]> err.no Git - systemd/commitdiff
dbus: add a couple of properties to the dbus manager interface
authorLennart Poettering <lennart@poettering.net>
Sat, 10 Apr 2010 15:40:18 +0000 (17:40 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 10 Apr 2010 16:00:28 +0000 (18:00 +0200)
dbus-manager.c
log.c
log.h

index 2323260dbb65d11bbd9be505cae197d118e48059..a8661bace3332def5359bc410182e93afe07aa74 100644 (file)
         "   <arg name=\"id\" type=\"u\"/>"                              \
         "   <arg name=\"job\" type=\"o\"/>"                             \
         "  </signal>"                                                   \
+        "  <property name=\"Version\" type=\"s\" access=\"read\"/>"     \
+        "  <property name=\"RunningAs\" type=\"s\" access=\"read\"/>"   \
+        "  <property name=\"BootTimestamp\" type=\"t\" access=\"read\"/>" \
+        "  <property name=\"LogLevel\" type=\"s\" access=\"readwrite\"/>" \
+        "  <property name=\"LogTarget\" type=\"s\" access=\"readwrite\"/>" \
         " </interface>"                                                 \
         BUS_PROPERTIES_INTERFACE                                        \
         BUS_INTROSPECTABLE_INTERFACE
 #define INTROSPECTION_END                                               \
         "</node>"
 
+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 497433a8b01751929dcbc06f42cf63aa152df9ef..b82018f28b509c15091642665aad038879ea1f05 100644 (file)
--- 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 abea126b916e3a81b5c8c20e69bd799b2cdb25b9..f424c191fa30c99708fb7ab4efb1d9eadbdf9391 100644 (file)
--- 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);