From 9f39404c86ea20d164b08b9639ca800c1d88724b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 31 Jul 2011 18:13:03 +0200 Subject: [PATCH] dbus: export load error on unit objects --- src/dbus-unit.c | 24 ++++++++++++++++++++++++ src/dbus-unit.h | 5 ++++- src/systemctl.c | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/dbus-unit.c b/src/dbus-unit.c index 266fb39b..bf240f97 100644 --- a/src/dbus-unit.c +++ b/src/dbus-unit.c @@ -330,6 +330,30 @@ int bus_unit_append_need_daemon_reload(DBusMessageIter *i, const char *property, return 0; } +int bus_unit_append_load_error(DBusMessageIter *i, const char *property, void *data) { + Unit *u = data; + const char *name, *message; + DBusMessageIter sub; + + assert(i); + assert(property); + assert(u); + + if (u->meta.load_error != 0) { + name = bus_errno_to_dbus(u->meta.load_error); + message = strempty(strerror(-u->meta.load_error)); + } else + name = message = ""; + + if (!dbus_message_iter_open_container(i, DBUS_TYPE_STRUCT, NULL, &sub) || + !dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &name) || + !dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &message) || + !dbus_message_iter_close_container(i, &sub)) + return -ENOMEM; + + return 0; +} + static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *connection, DBusMessage *message) { DBusMessage *reply = NULL; Manager *m = u->meta.manager; diff --git a/src/dbus-unit.h b/src/dbus-unit.h index df8f6ae2..fc9b4f57 100644 --- a/src/dbus-unit.h +++ b/src/dbus-unit.h @@ -113,6 +113,7 @@ " \n" \ " \n" \ " \n" \ + " \n" \ " \n" #define BUS_UNIT_INTERFACES_LIST \ @@ -170,7 +171,8 @@ { "org.freedesktop.systemd1.Unit", "JobTimeoutUSec", bus_property_append_usec, "t", &u->meta.job_timeout }, \ { "org.freedesktop.systemd1.Unit", "ConditionTimestamp", bus_property_append_usec, "t", &u->meta.condition_timestamp.realtime }, \ { "org.freedesktop.systemd1.Unit", "ConditionTimestampMonotonic", bus_property_append_usec,"t", &u->meta.condition_timestamp.monotonic }, \ - { "org.freedesktop.systemd1.Unit", "ConditionResult", bus_property_append_bool, "b", &u->meta.condition_result } + { "org.freedesktop.systemd1.Unit", "ConditionResult", bus_property_append_bool, "b", &u->meta.condition_result }, \ + { "org.freedesktop.systemd1.Unit", "LoadError", bus_unit_append_load_error, "(ss)", u } int bus_unit_append_names(DBusMessageIter *i, const char *property, void *data); int bus_unit_append_following(DBusMessageIter *i, const char *property, void *data); @@ -187,6 +189,7 @@ int bus_unit_append_job(DBusMessageIter *i, const char *property, void *data); int bus_unit_append_default_cgroup(DBusMessageIter *i, const char *property, void *data); int bus_unit_append_cgroups(DBusMessageIter *i, const char *property, void *data); int bus_unit_append_need_daemon_reload(DBusMessageIter *i, const char *property, void *data); +int bus_unit_append_load_error(DBusMessageIter *i, const char *property, void *data); void bus_unit_send_change_signal(Unit *u); void bus_unit_send_removed_signal(Unit *u); diff --git a/src/systemctl.c b/src/systemctl.c index bf905caa..3eb8ab5b 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -1969,6 +1969,8 @@ typedef struct UnitStatusInfo { const char *path; const char *default_control_group; + const char *load_error; + usec_t inactive_exit_timestamp; usec_t active_enter_timestamp; usec_t active_exit_timestamp; @@ -2039,7 +2041,9 @@ static void print_status_info(UnitStatusInfo *i) { } else on = off = ""; - if (i->path) + if (i->load_error) + printf("\t Loaded: %s%s%s (Reason: %s)\n", on, strna(i->load_state), off, i->load_error); + else if (i->path) printf("\t Loaded: %s%s%s (%s)\n", on, strna(i->load_state), off, i->path); else printf("\t Loaded: %s%s%s\n", on, strna(i->load_state), off); @@ -2392,6 +2396,30 @@ static int status_property(const char *name, DBusMessageIter *iter, UnitStatusIn break; } + + case DBUS_TYPE_STRUCT: { + + if (streq(name, "LoadError")) { + DBusMessageIter sub; + const char *n, *message; + int r; + + dbus_message_iter_recurse(iter, &sub); + + r = bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &n, true); + if (r < 0) + return r; + + r = bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &message, false); + if (r < 0) + return r; + + if (!isempty(message)) + i->load_error = message; + } + + break; + } } return 0; @@ -2433,6 +2461,14 @@ static int print_property(const char *name, DBusMessageIter *iter) { printf("%s=%s\n", name, s); return 0; + } else if (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING && streq(name, "LoadError")) { + const char *a = NULL, *b = NULL; + + if (bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &a, true) > 0) + bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &b, false); + + if (arg_all || !isempty(a) || !isempty(b)) + printf("%s=%s \"%s\"\n", name, strempty(a), strempty(b)); } break; -- 2.39.5