summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-07 21:26:31 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-07 21:26:31 +0100
commit5b30bef856e89a571df57b7b953e9a1409d9aced (patch)
tree815d8648bf7b59a35c1cda35174b8b1e08cac323
parent46e65dcc3a522b5e992e165b5e61d14254026859 (diff)
bus: log message parsing errors everywhere with a generalized bus_log_parse_error()
-rw-r--r--src/analyze/analyze.c23
-rw-r--r--src/hostname/hostnamectl.c2
-rw-r--r--src/libsystemd-bus/bus-util.c5
-rw-r--r--src/libsystemd-bus/bus-util.h2
-rw-r--r--src/login/inhibit.c2
-rw-r--r--src/login/loginctl.c23
-rw-r--r--src/machine/machinectl.c34
-rw-r--r--src/nspawn/nspawn.c6
-rw-r--r--src/update-utmp/update-utmp.c17
9 files changed, 47 insertions, 67 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 22bf07670e..715ad73ff9 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -190,10 +190,8 @@ static int bus_parse_unit_info(sd_bus_message *message, struct unit_info *u) {
&u->job_id,
&u->job_type,
&u->job_path);
- if (r < 0) {
- log_error("Failed to parse message as unit_info.");
- return -EIO;
- }
+ if (r < 0)
+ return bus_log_parse_error(r);
return r;
}
@@ -230,6 +228,9 @@ static int bus_get_unit_property_strv(sd_bus *bus, const char *unit_path, const
}
}
+ if (r < 0)
+ return bus_log_parse_error(r);
+
return r;
}
@@ -839,15 +840,13 @@ static int list_dependencies(sd_bus *bus, const char *name) {
&reply,
"s");
if (r < 0) {
- log_error("Failed to parse reply: %s", bus_error_message(&error, -r));
+ log_error("Failed to get ID: %s", bus_error_message(&error, -r));
return r;
}
r = sd_bus_message_read(reply, "s", &id);
- if (r < 0) {
- log_error("Failed to parse reply.");
- return r;
- }
+ if (r < 0)
+ return bus_log_parse_error(r);
times = hashmap_get(unit_times_hashmap, id);
@@ -1114,10 +1113,8 @@ static int dump(sd_bus *bus, char **args) {
}
r = sd_bus_message_read(reply, "s", &text);
- if (r < 0) {
- log_error("Failed to parse reply");
- return r;
- }
+ if (r < 0)
+ return bus_log_parse_error(r);
fputs(text, stdout);
return 0;
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index 523177b27d..959ec6d3b2 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -145,7 +145,7 @@ static int show_one_name(sd_bus *bus, const char* attr) {
r = sd_bus_message_read(reply, "s", &s);
if (r < 0)
- return r;
+ return bus_log_parse_error(r);
printf("%s\n", s);
diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c
index 2b1cd0bc83..ae9733d01f 100644
--- a/src/libsystemd-bus/bus-util.c
+++ b/src/libsystemd-bus/bus-util.c
@@ -953,3 +953,8 @@ int bus_property_get_uid(
return sd_bus_message_append_basic(reply, 'u', userdata);
}
+
+int bus_log_parse_error(int r) {
+ log_error("Failed to parse message: %s", strerror(-r));
+ return r;
+}
diff --git a/src/libsystemd-bus/bus-util.h b/src/libsystemd-bus/bus-util.h
index f982e08ecd..5f0a0b3ffa 100644
--- a/src/libsystemd-bus/bus-util.h
+++ b/src/libsystemd-bus/bus-util.h
@@ -75,6 +75,8 @@ int bus_property_get_uid(sd_bus *bus, const char *path, const char *interface, c
#define bus_property_get_gid bus_property_get_uid
#define bus_property_get_pid bus_property_get_uid
+int bus_log_parse_error(int r);
+
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus*, sd_bus_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_message*, sd_bus_message_unref);
diff --git a/src/login/inhibit.c b/src/login/inhibit.c
index 8c0056e503..e20af74ef0 100644
--- a/src/login/inhibit.c
+++ b/src/login/inhibit.c
@@ -62,7 +62,7 @@ static int inhibit(sd_bus *bus, sd_bus_error *error) {
r = sd_bus_message_read_basic(reply, SD_BUS_TYPE_UNIX_FD, &fd);
if (r < 0)
- return -EIO;
+ return r;
r = dup(fd);
if (r < 0)
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index c9899ecba5..2aedbcf922 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -72,11 +72,6 @@ static void polkit_agent_open_if_enabled(void) {
polkit_agent_open();
}
-static int log_parse_error(int r) {
- log_error("Failed to parse message: %s", strerror(-r));
- return r;
-}
-
static int list_sessions(sd_bus *bus, char **args, unsigned n) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
@@ -102,7 +97,7 @@ static int list_sessions(sd_bus *bus, char **args, unsigned n) {
r = sd_bus_message_enter_container(reply, 'a', "(susso)");
if (r < 0)
- return log_parse_error(r);
+ return bus_log_parse_error(r);
printf("%10s %10s %-16s %-16s\n", "SESSION", "UID", "USER", "SEAT");
@@ -111,7 +106,7 @@ static int list_sessions(sd_bus *bus, char **args, unsigned n) {
k++;
}
if (r < 0)
- return log_parse_error(r);
+ return bus_log_parse_error(r);
printf("\n%u sessions listed.\n", k);
@@ -143,7 +138,7 @@ static int list_users(sd_bus *bus, char **args, unsigned n) {
r = sd_bus_message_enter_container(reply, 'a', "(uso)");
if (r < 0)
- return log_parse_error(r);
+ return bus_log_parse_error(r);
printf("%10s %-16s\n", "UID", "USER");
@@ -152,7 +147,7 @@ static int list_users(sd_bus *bus, char **args, unsigned n) {
k++;
}
if (r < 0)
- return log_parse_error(r);
+ return bus_log_parse_error(r);
printf("\n%u users listed.\n", k);
@@ -183,7 +178,7 @@ static int list_seats(sd_bus *bus, char **args, unsigned n) {
r = sd_bus_message_enter_container(reply, 'a', "(so)");
if (r < 0)
- return log_parse_error(r);
+ return bus_log_parse_error(r);
printf("%-16s\n", "SEAT");
@@ -192,7 +187,7 @@ static int list_seats(sd_bus *bus, char **args, unsigned n) {
k++;
}
if (r < 0)
- return log_parse_error(r);
+ return bus_log_parse_error(r);
printf("\n%u seats listed.\n", k);
@@ -622,7 +617,7 @@ static int show_session(sd_bus *bus, char **args, unsigned n) {
r = sd_bus_message_read(reply, "o", &path);
if (r < 0)
- return log_parse_error(r);
+ return bus_log_parse_error(r);
if (show_properties)
r = bus_print_all_properties(bus, "org.freedesktop.login1", path, NULL, arg_all);
@@ -689,7 +684,7 @@ static int show_user(sd_bus *bus, char **args, unsigned n) {
r = sd_bus_message_read(reply, "o", &path);
if (r < 0)
- return log_parse_error(r);
+ return bus_log_parse_error(r);
if (show_properties)
r = bus_print_all_properties(bus, "org.freedesktop.login1", path, NULL, arg_all);
@@ -749,7 +744,7 @@ static int show_seat(sd_bus *bus, char **args, unsigned n) {
r = sd_bus_message_read(reply, "o", &path);
if (r < 0)
- return log_parse_error(r);
+ return bus_log_parse_error(r);
if (show_properties)
r = bus_print_all_properties(bus, "org.freedesktop.login1", path, NULL, arg_all);
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index f60c66055d..7feb7be3da 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -89,7 +89,7 @@ static int list_machines(sd_bus *bus, char **args, unsigned n) {
r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssso)");
if (r < 0)
- goto fail;
+ return bus_log_parse_error(r);
while ((r = sd_bus_message_read(reply, "(ssso)", &name, &class, &service, &object)) > 0) {
printf("%-32s %-9s %-16s\n", name, class, service);
@@ -97,20 +97,16 @@ static int list_machines(sd_bus *bus, char **args, unsigned n) {
k++;
}
if (r < 0)
- goto fail;
+ return bus_log_parse_error(r);
r = sd_bus_message_exit_container(reply);
if (r < 0)
- goto fail;
+ return bus_log_parse_error(r);
if (on_tty())
printf("\n%u machines listed.\n", k);
return 0;
-
-fail:
- log_error("Failed to parse reply: %s", strerror(-r));
- return r;
}
static int show_scope_cgroup(sd_bus *bus, const char *unit, pid_t leader) {
@@ -146,10 +142,8 @@ static int show_scope_cgroup(sd_bus *bus, const char *unit, pid_t leader) {
}
r = sd_bus_message_read(reply, "s", &cgroup);
- if (r < 0) {
- log_error("Failed to parse reply: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return bus_log_parse_error(r);
if (isempty(cgroup))
return 0;
@@ -334,10 +328,8 @@ static int show(sd_bus *bus, char **args, unsigned n) {
}
r = sd_bus_message_read(reply, "o", &path);
- if (r < 0) {
- log_error("Failed to parse reply: %s", strerror(-r));
- break;
- }
+ if (r < 0)
+ return bus_log_parse_error(r);
if (properties)
r = show_properties(bus, path, &new_line);
@@ -547,10 +539,8 @@ static int login_machine(sd_bus *bus, char **args, unsigned n) {
}
r = sd_bus_message_read(reply, "o", &path);
- if (r < 0) {
- log_error("Failed to parse reply: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return bus_log_parse_error(r);
r = sd_bus_get_property(
bus,
@@ -567,10 +557,8 @@ static int login_machine(sd_bus *bus, char **args, unsigned n) {
}
r = sd_bus_message_read(reply2, "u", &leader);
- if (r < 0) {
- log_error("Failed to parse reply: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return bus_log_parse_error(r);
master = openpt_in_namespace(leader, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NDELAY);
if (master < 0) {
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 34a0dafa64..06d627c0a9 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -990,10 +990,8 @@ static int terminate_machine(pid_t pid) {
}
r = sd_bus_message_read(reply, "o", &path);
- if (r < 0) {
- log_error("Failed to parse GetMachineByPID() reply: %s", bus_error_message(&error, r));
- return r;
- }
+ if (r < 0)
+ return bus_log_parse_error(r);
r = sd_bus_call_method(
bus,
diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c
index 61db1e96d3..42554fe2dc 100644
--- a/src/update-utmp/update-utmp.c
+++ b/src/update-utmp/update-utmp.c
@@ -71,9 +71,8 @@ static usec_t get_startup_time(Context *c) {
}
r = sd_bus_message_read(reply, "v", "t", &t);
- if (r < 0) {
- log_error("Failed to parse reply: %s", strerror(-r));
- }
+ if (r < 0)
+ return bus_log_parse_error(r);
return t;
}
@@ -123,10 +122,8 @@ static int get_current_runlevel(Context *c) {
}
r = sd_bus_message_read(reply1, "o", &path);
- if (r < 0) {
- log_error("Failed to parse reply: %s", strerror(-r));
- return -EIO;
- }
+ if (r < 0)
+ return bus_log_parse_error(r);
r = sd_bus_call_method(
c->bus,
@@ -143,10 +140,8 @@ static int get_current_runlevel(Context *c) {
}
r = sd_bus_message_read(reply2, "v", "s", &state);
- if (r < 0) {
- log_error("Failed to parse reply: %s", strerror(-r));
- return -EIO;
- }
+ if (r < 0)
+ return bus_log_parse_error(r);
if (streq(state, "active") || streq(state, "reloading"))
return table[i].runlevel;