X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=dbus-manager.c;h=a8661bace3332def5359bc410182e93afe07aa74;hp=754916482936fc48277fda7728cd1191f1f01211;hb=8c43883a682b2edd902b170ab2e0f3d50d7e92e0;hpb=4ca5640b272d17726ca7c4ace789d884922a3bc7 diff --git a/dbus-manager.c b/dbus-manager.c index 754916482..a8661bace 100644 --- a/dbus-manager.c +++ b/dbus-manager.c @@ -49,6 +49,7 @@ " " \ " " \ " " \ + " " \ " " \ " " \ " " \ @@ -65,6 +66,11 @@ " " \ " " \ " " \ + " " \ + " " \ + " " \ + " " \ + " " \ " " \ BUS_PROPERTIES_INTERFACE \ BUS_INTROSPECTABLE_INTERFACE @@ -72,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; @@ -330,6 +378,35 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection if (!(reply = dbus_message_new_method_return(message))) goto oom; + } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "Dump")) { + FILE *f; + char *dump = NULL; + size_t size; + + if (!(reply = dbus_message_new_method_return(message))) + goto oom; + + if (!(f = open_memstream(&dump, &size))) + goto oom; + + manager_dump_units(m, f, NULL); + manager_dump_jobs(m, f, NULL); + + if (ferror(f)) { + fclose(f); + free(dump); + goto oom; + } + + fclose(f); + + if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &dump, DBUS_TYPE_INVALID)) { + free(dump); + goto oom; + } + + free(dump); + } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) { char *introspection = NULL; FILE *f; @@ -392,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);