chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
46e65dc
)
bus: log message parsing errors everywhere with a generalized bus_log_parse_error()
author
Lennart Poettering
<lennart@poettering.net>
Thu, 7 Nov 2013 20:26:31 +0000
(21:26 +0100)
committer
Lennart Poettering
<lennart@poettering.net>
Thu, 7 Nov 2013 20:26:31 +0000
(21:26 +0100)
src/analyze/analyze.c
patch
|
blob
|
history
src/hostname/hostnamectl.c
patch
|
blob
|
history
src/libsystemd-bus/bus-util.c
patch
|
blob
|
history
src/libsystemd-bus/bus-util.h
patch
|
blob
|
history
src/login/inhibit.c
patch
|
blob
|
history
src/login/loginctl.c
patch
|
blob
|
history
src/machine/machinectl.c
patch
|
blob
|
history
src/nspawn/nspawn.c
patch
|
blob
|
history
src/update-utmp/update-utmp.c
patch
|
blob
|
history
diff --git
a/src/analyze/analyze.c
b/src/analyze/analyze.c
index 22bf07670ecab41992d741438387bc1ba74156fc..715ad73ff9e53ef6866e59aa18f63ef38b0e9467 100644
(file)
--- 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);
&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;
}
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;
}
return r;
}
@@
-839,15
+840,13
@@
static int list_dependencies(sd_bus *bus, const char *name) {
&reply,
"s");
if (r < 0) {
&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);
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);
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);
}
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;
fputs(text, stdout);
return 0;
diff --git
a/src/hostname/hostnamectl.c
b/src/hostname/hostnamectl.c
index 523177b27d4d412d54d7734c25130956a1aea4a4..959ec6d3b227ba4aab7fd44b1de87abbc551af0b 100644
(file)
--- 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)
r = sd_bus_message_read(reply, "s", &s);
if (r < 0)
- return
r
;
+ return
bus_log_parse_error(r)
;
printf("%s\n", s);
printf("%s\n", s);
diff --git
a/src/libsystemd-bus/bus-util.c
b/src/libsystemd-bus/bus-util.c
index 2b1cd0bc8375efdc91052a426098a5a8c0cd37ff..ae9733d01f7eb461edc954a4a9db5c2b59d33185 100644
(file)
--- 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);
}
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 f982e08ecd6bfc99a509df783225a2f4a9dee5c5..5f0a0b3ffa117cfaee319608a43ae4bc97803f09 100644
(file)
--- 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
#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);
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 8c0056e503d84c8b2209f7837204c3fc4aa2eae9..e20af74ef0949d873b9f44b93ec6e4aa0021d61a 100644
(file)
--- 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)
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)
r = dup(fd);
if (r < 0)
diff --git
a/src/login/loginctl.c
b/src/login/loginctl.c
index c9899ecba528eaea30255de342873e2f7631abe1..2aedbcf9225c6cc14458ac7319592b3500f0109a 100644
(file)
--- 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();
}
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;
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)
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");
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)
k++;
}
if (r < 0)
- return log_parse_error(r);
+ return
bus_
log_parse_error(r);
printf("\n%u sessions listed.\n", k);
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)
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");
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)
k++;
}
if (r < 0)
- return log_parse_error(r);
+ return
bus_
log_parse_error(r);
printf("\n%u users listed.\n", k);
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)
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");
printf("%-16s\n", "SEAT");
@@
-192,7
+187,7
@@
static int list_seats(sd_bus *bus, char **args, unsigned n) {
k++;
}
if (r < 0)
k++;
}
if (r < 0)
- return log_parse_error(r);
+ return
bus_
log_parse_error(r);
printf("\n%u seats listed.\n", k);
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)
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);
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)
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);
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)
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);
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 f60c66055dd7258e5d823302f30e90d920cb4147..7feb7be3da69fb7f5f27052dd479901acd3eb996 100644
(file)
--- 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)
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);
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)
k++;
}
if (r < 0)
-
goto fail
;
+
return bus_log_parse_error(r)
;
r = sd_bus_message_exit_container(reply);
if (r < 0)
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;
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) {
}
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);
}
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;
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);
}
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);
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);
}
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,
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);
}
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) {
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 34a0dafa645803024956b62d016debfc17fe95e0..06d627c0a9ce1840c938af070385073a292c7080 100644
(file)
--- 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);
}
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,
r = sd_bus_call_method(
bus,
diff --git
a/src/update-utmp/update-utmp.c
b/src/update-utmp/update-utmp.c
index 61db1e96d34a47b3fd77cd4d580277775c211ef9..42554fe2dcead4284727a4e0787ca13f7bee7b1b 100644
(file)
--- 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);
}
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;
}
return t;
}
@@
-123,10
+122,8
@@
static int get_current_runlevel(Context *c) {
}
r = sd_bus_message_read(reply1, "o", &path);
}
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,
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);
}
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;
if (streq(state, "active") || streq(state, "reloading"))
return table[i].runlevel;