chiark / gitweb /
dbus: add Dump() D-Bus call
[elogind.git] / dbus-manager.c
index 732e586e9292c01dec4be5a61dcad975e149cebd..2323260dbb65d11bbd9be505cae197d118e48059 100644 (file)
@@ -38,7 +38,7 @@
         "  </method>"                                                   \
         "  <method name=\"GetJob\">"                                    \
         "   <arg name=\"id\" type=\"u\" direction=\"in\"/>"             \
-        "   <arg name=\"unit\" type=\"o\" direction=\"out\"/>"          \
+        "   <arg name=\"job\" type=\"o\" direction=\"out\"/>"           \
         "  </method>"                                                   \
         "  <method name=\"ClearJobs\"/>"                                \
         "  <method name=\"ListUnits\">"                                 \
@@ -49,6 +49,7 @@
         "  </method>"                                                   \
         "  <method name=\"Subscribe\"/>"                                \
         "  <method name=\"Unsubscribe\"/>"                              \
+        "  <method name=\"Dump\"/>"                                     \
         "  <signal name=\"UnitNew\">"                                   \
         "   <arg name=\"id\" type=\"s\"/>"                              \
         "   <arg name=\"unit\" type=\"o\"/>"                            \
@@ -142,7 +143,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                                     DBUS_TYPE_INVALID))
                         goto oom;
 
-        } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1",  "GetJob")) {
+        } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "GetJob")) {
                 uint32_t id;
                 Job *j;
 
@@ -168,14 +169,14 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                                     DBUS_TYPE_INVALID))
                         goto oom;
 
-        } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1",  "ClearJobs")) {
+        } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "ClearJobs")) {
 
                 manager_clear_jobs(m);
 
                 if (!(reply = dbus_message_new_method_return(message)))
                         goto oom;
 
-        } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1",  "ListUnits")) {
+        } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "ListUnits")) {
                 DBusMessageIter iter, sub;
                 Iterator i;
                 Unit *u;
@@ -249,7 +250,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                 if (!dbus_message_iter_close_container(&iter, &sub))
                         goto oom;
 
-        } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1",  "ListJobs")) {
+        } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "ListJobs")) {
                 DBusMessageIter iter, sub;
                 Iterator i;
                 Job *j;
@@ -305,7 +306,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                 if (!dbus_message_iter_close_container(&iter, &sub))
                         goto oom;
 
-        } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1",  "Subscribe")) {
+        } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "Subscribe")) {
                 char *client;
 
                 if (!(client = strdup(dbus_message_get_sender(message))))
@@ -319,7 +320,7 @@ 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",  "Unsubscribe")) {
+        } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "Unsubscribe")) {
                 char *client;
 
                 if (!(client = set_remove(m->subscribed, (char*) dbus_message_get_sender(message))))
@@ -330,6 +331,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;