1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-25 23:21:33 +03:00

bus: use new property retrieval calls everywhere

This commit is contained in:
Lennart Poettering 2013-11-07 22:17:19 +01:00
parent 40be0704eb
commit 47c649b5de
2 changed files with 24 additions and 51 deletions

View File

@ -742,9 +742,7 @@ static int request_handler_file(
}
static int get_virtualization(char **v) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_unref_ sd_bus *bus = NULL;
const char *t;
char *b;
int r;
@ -752,33 +750,23 @@ static int get_virtualization(char **v) {
if (r < 0)
return r;
r = sd_bus_call_method(
r = sd_bus_get_property_string(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.DBus.Properties",
"Get",
NULL,
&reply,
"ss",
"org.freedesktop.systemd1.Manager",
"Virtualization");
"Virtualization",
NULL,
&b);
if (r < 0)
return r;
r = sd_bus_message_read(reply, "v", "s", &t);
if (r < 0)
return r;
if (isempty(t)) {
if (isempty(b)) {
free(b);
*v = NULL;
return 0;
}
b = strdup(t);
if (!b)
return -ENOMEM;
*v = b;
return 1;
}

View File

@ -47,33 +47,25 @@ typedef struct Context {
} Context;
static usec_t get_startup_time(Context *c) {
usec_t t = 0;
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
usec_t t = 0;
int r;
assert(c);
r = sd_bus_call_method(
r = sd_bus_get_property_trivial(
c->bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.DBus.Properties",
"Get",
&error,
&reply,
"ss",
"org.freedesktop.systemd1.Manager",
"UserspaceTimestamp");
"UserspaceTimestamp",
&error,
't', &t);
if (r < 0) {
log_error("Failed to get timestamp: %s", bus_error_message(&error, -r));
return t;
return 0;
}
r = sd_bus_message_read(reply, "v", "t", &t);
if (r < 0)
return bus_log_parse_error(r);
return t;
}
@ -101,8 +93,9 @@ static int get_current_runlevel(Context *c) {
assert(c);
for (i = 0; i < ELEMENTSOF(table); i++) {
_cleanup_bus_message_unref_ sd_bus_message *reply1 = NULL, *reply2 = NULL;
const char *path = NULL, *state;
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_free_ char *state = NULL;
const char *path = NULL;
r = sd_bus_call_method(
c->bus,
@ -111,38 +104,30 @@ static int get_current_runlevel(Context *c) {
"org.freedesktop.systemd1.Manager",
"LoadUnit",
&error,
&reply1,
&reply,
"s", table[i].special);
if (r < 0) {
log_error("Failed to get runlevel: %s", bus_error_message(&error, -r));
if (r == -ENOMEM)
return r;
else
continue;
log_warning("Failed to get runlevel: %s", bus_error_message(&error, -r));
continue;
}
r = sd_bus_message_read(reply1, "o", &path);
r = sd_bus_message_read(reply, "o", &path);
if (r < 0)
return bus_log_parse_error(r);
r = sd_bus_call_method(
r = sd_bus_get_property_string(
c->bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.DBus.Properties",
"Get",
"org.freedesktop.systemd1.Unit",
"ActiveState",
&error,
&reply2,
"ss", "org.freedesktop.systemd1.Unit", "ActiveState");
&state);
if (r < 0) {
log_error("Failed to get state: %s", bus_error_message(&error, -r));
log_warning("Failed to get state: %s", bus_error_message(&error, -r));
return r;
}
r = sd_bus_message_read(reply2, "v", "s", &state);
if (r < 0)
return bus_log_parse_error(r);
if (streq(state, "active") || streq(state, "reloading"))
return table[i].runlevel;
}