chiark / gitweb /
main: implement manager configuration file
[elogind.git] / src / systemctl.c
index 73b0fc48cc1d0fc93cd652b0cd13c0c1e36ea110..02c8e30418b6e49b312b6e5b8baa6d6be705d163 100644 (file)
@@ -856,6 +856,7 @@ static int check_unit(DBusConnection *bus, char **args, unsigned n) {
                         if (!arg_quiet)
                                 puts("unknown");
 
+                        dbus_error_free(&error);
                         continue;
                 }
 
@@ -935,9 +936,9 @@ finish:
 }
 
 static void show_cgroup(const char *name) {
-        char *fn, *pids;
-        int r;
-        char *p;
+        char *fn;
+        FILE *f;
+        pid_t last = 0;
 
         if (!startswith(name, "name=systemd:"))
                 return;
@@ -945,30 +946,41 @@ static void show_cgroup(const char *name) {
         if (asprintf(&fn, "/cgroup/systemd/%s/tasks", name + 13) < 0)
                 return;
 
-        r = read_one_line_file(fn, &pids);
+        f = fopen(fn, "r");
         free(fn);
 
-        if (r < 0)
+        if (!f)
                 return;
 
-        p = pids;
-        while (p[0]) {
-                unsigned long ul;
-                char *t = NULL;
+        printf("\t\t  \342\224\202\n");
 
-                p += strspn(p, WHITESPACE);
+        while (!feof(f)) {
+                unsigned long ul;
 
-                errno = 0;
-                ul = strtoul(p, &p, 0);
-                if (errno != 0 || ul <= 0)
+                if (fscanf(f, "%lu", &ul) != 1)
                         break;
 
-                get_process_cmdline((pid_t) ul, 60, &t);
-                printf("\t\t%lu %s\n", ul, strna(t));
+                if (ul <= 0)
+                        continue;
+
+                if (last > 0) {
+                        char *t = NULL;
+                        get_process_cmdline(last, 60, &t);
+                        printf("\t\t  \342\224\234 %lu %s\n", (unsigned long) last, strna(t));
+                        free(t);
+                }
+
+                last = (pid_t) ul;
+        }
+
+        if (last > 0) {
+                char *t = NULL;
+                get_process_cmdline(last, 60, &t);
+                printf("\t\t  \342\224\224 %lu %s\n", (unsigned long) last, strna(t));
                 free(t);
         }
 
-        free(pids);
+        fclose(f);
 }
 
 typedef struct UnitStatusInfo {
@@ -1607,6 +1619,42 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
                                 goto finish;
                         }
 
+                        if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) {
+
+                                if (!dbus_error_has_name(&error, DBUS_ERROR_ACCESS_DENIED)) {
+                                        log_error("Failed to issue method call: %s", error.message);
+                                        r = -EIO;
+                                        goto finish;
+                                }
+
+                                dbus_error_free(&error);
+
+                                dbus_message_unref(m);
+                                if (!(m = dbus_message_new_method_call(
+                                                      "org.freedesktop.systemd1",
+                                                      "/org/freedesktop/systemd1",
+                                                      "org.freedesktop.systemd1.Manager",
+                                                      "GetUnit"))) {
+                                        log_error("Could not allocate message.");
+                                        r = -ENOMEM;
+                                        goto finish;
+                                }
+
+                                if (!dbus_message_append_args(m,
+                                                              DBUS_TYPE_STRING, &args[i],
+                                                              DBUS_TYPE_INVALID)) {
+                                        log_error("Could not append arguments to message.");
+                                        r = -ENOMEM;
+                                        goto finish;
+                                }
+
+                                if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) {
+                                        log_error("Failed to issue method call: %s", error.message);
+                                        r = -EIO;
+                                        goto finish;
+                                }
+                        }
+
                 } else {
 
                         if (!(m = dbus_message_new_method_call(
@@ -1626,12 +1674,12 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
                                 r = -ENOMEM;
                                 goto finish;
                         }
-                }
 
-                if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) {
-                        log_error("Failed to issue method call: %s", error.message);
-                        r = -EIO;
-                        goto finish;
+                        if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) {
+                                log_error("Failed to issue method call: %s", error.message);
+                                r = -EIO;
+                                goto finish;
+                        }
                 }
 
                 if (!dbus_message_get_args(reply, &error,