chiark / gitweb /
systemctl: show sub state along active state
[elogind.git] / dbus-manager.c
index 754916482936fc48277fda7728cd1191f1f01211..5f3d9647776e6a10050eac95bf384084f1bb0e3a 100644 (file)
         "  </method>"                                                   \
         "  <method name=\"ClearJobs\"/>"                                \
         "  <method name=\"ListUnits\">"                                 \
-        "   <arg name=\"units\" type=\"a(ssssouso)\" direction=\"out\"/>" \
+        "   <arg name=\"units\" type=\"a(sssssouso)\" direction=\"out\"/>" \
         "  </method>"                                                   \
         "  <method name=\"ListJobs\">"                                  \
         "   <arg name=\"jobs\" type=\"a(usssoo)\" direction=\"out\"/>"  \
         "  </method>"                                                   \
         "  <method name=\"Subscribe\"/>"                                \
         "  <method name=\"Unsubscribe\"/>"                              \
+        "  <method name=\"Dump\"/>"                                     \
         "  <signal name=\"UnitNew\">"                                   \
         "   <arg name=\"id\" type=\"s\"/>"                              \
         "   <arg name=\"unit\" type=\"o\"/>"                            \
         "   <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;
@@ -186,12 +234,12 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
 
                 dbus_message_iter_init_append(reply, &iter);
 
-                if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ssssouso)", &sub))
+                if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(sssssouso)", &sub))
                         goto oom;
 
                 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
                         char *u_path, *j_path;
-                        const char *id, *description, *load_state, *active_state, *job_type;
+                        const char *id, *description, *load_state, *active_state, *sub_state, *job_type;
                         DBusMessageIter sub2;
                         uint32_t job_id;
 
@@ -205,6 +253,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                         description = unit_description(u);
                         load_state = unit_load_state_to_string(u->meta.load_state);
                         active_state = unit_active_state_to_string(unit_active_state(u));
+                        sub_state = unit_sub_state_to_string(u);
 
                         if (!(u_path = unit_dbus_path(u)))
                                 goto oom;
@@ -228,6 +277,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &description) ||
                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &load_state) ||
                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &active_state) ||
+                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sub_state) ||
                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path) ||
                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &job_id) ||
                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &job_type) ||
@@ -330,6 +380,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 +471,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);