From: Lennart Poettering Date: Sat, 10 Apr 2010 15:40:18 +0000 (+0200) Subject: dbus: add a couple of properties to the dbus manager interface X-Git-Tag: 0.git+20100605+dfd8ee-1~172 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1adf1049dc9def8d8df405bab7f5ae08e1e9573d;p=systemd dbus: add a couple of properties to the dbus manager interface --- diff --git a/dbus-manager.c b/dbus-manager.c index 2323260d..a8661bac 100644 --- a/dbus-manager.c +++ b/dbus-manager.c @@ -66,6 +66,11 @@ " " \ " " \ " " \ + " " \ + " " \ + " " \ + " " \ + " " \ " " \ BUS_PROPERTIES_INTERFACE \ BUS_INTROSPECTABLE_INTERFACE @@ -73,9 +78,51 @@ #define INTROSPECTION_END \ "" +DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_running_as, manager_running_as, ManagerRunningAs); + +static int bus_manager_append_log_target(Manager *m, DBusMessageIter *i, const char *property, void *data) { + const char *t; + + assert(m); + assert(i); + assert(property); + + t = log_target_to_string(log_get_target()); + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t)) + return -ENOMEM; + + return 0; +} + +static int bus_manager_append_log_level(Manager *m, DBusMessageIter *i, const char *property, void *data) { + const char *t; + + assert(m); + assert(i); + assert(property); + + t = log_level_to_string(log_get_max_level()); + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t)) + return -ENOMEM; + + return 0; +} + static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) { - int r; Manager *m = data; + + const BusProperty properties[] = { + { "org.freedesktop.systemd1", "Version", bus_property_append_string, "s", PACKAGE_VERSION }, + { "org.freedesktop.systemd1", "RunningAs", bus_manager_append_running_as, "s", &m->running_as }, + { "org.freedesktop.systemd1", "BootTimestamp", bus_property_append_uint64, "t", &m->boot_timestamp }, + { "org.freedesktop.systemd1", "LogLevel", bus_manager_append_log_level, "s", NULL }, + { "org.freedesktop.systemd1", "LogTarget", bus_manager_append_log_target, "s", NULL }, + { NULL, NULL, NULL, NULL, NULL } + }; + + int r; DBusError error; DBusMessage *reply = NULL; char * path = NULL; @@ -422,7 +469,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection free(introspection); } else - return bus_default_message_handler(m, message, NULL, NULL); + return bus_default_message_handler(m, message, NULL, properties); free(path); diff --git a/log.c b/log.c index 497433a8..b82018f2 100644 --- a/log.c +++ b/log.c @@ -313,6 +313,14 @@ void log_parse_environment(void) { log_warning("Failed to parse log level %s. Ignoring.", e); } +LogTarget log_get_target(void) { + return log_target; +} + +int log_get_max_level(void) { + return log_max_level; +} + static const char *const log_target_table[] = { [LOG_TARGET_CONSOLE] = "console", [LOG_TARGET_SYSLOG] = "syslog", diff --git a/log.h b/log.h index abea126b..f424c191 100644 --- a/log.h +++ b/log.h @@ -40,6 +40,9 @@ void log_set_max_level(int level); int log_set_target_from_string(const char *e); int log_set_max_level_from_string(const char *e); +LogTarget log_get_target(void); +int log_get_max_level(void); + void log_close_kmsg(void); int log_open_kmsg(void); void log_close_syslog(void);