chiark / gitweb /
systemctl: Add DropIn paths to status message
[elogind.git] / src / systemctl / systemctl.c
index fe71085d423d6660a8276551f3b87529461c2d55..a7b541dc3f0bf9da029001d04b14c499e4e2496c 100644 (file)
@@ -2225,6 +2225,8 @@ typedef struct UnitStatusInfo {
         const char *source_path;
         const char *default_control_group;
 
+        char **dropin_paths;
+
         const char *load_error;
         const char *result;
 
@@ -2331,6 +2333,34 @@ static void print_status_info(UnitStatusInfo *i) {
                 printf(" %*s: %s%s%s\n",
                        maxlen, "Loaded", on, strna(i->load_state), off);
 
+        if (!strv_isempty(i->dropin_paths)) {
+                char ** dropin;
+                char * dir = NULL;
+                bool last = false;
+
+                STRV_FOREACH(dropin, i->dropin_paths) {
+                        if (! dir || last) {
+                                printf("  %*s ", maxlen, dir ? "" : "Drop-In:");
+
+                                free(dir);
+
+                                if (path_get_parent(*dropin, &dir) < 0) {
+                                        log_oom();
+                                        return;
+                                }
+
+                                printf("%s\n %*s  %s ", dir, maxlen, "",
+                                       draw_special_char(DRAW_TREE_RIGHT));
+                        }
+
+                        last = ! (*(dropin + 1) && startswith(*(dropin + 1), dir));
+
+                        printf("%s%s", path_get_file_name(*dropin), last ? "\n" : ", ");
+                }
+
+                free(dir);
+        }
+
         ss = streq_ptr(i->active_state, i->sub_state) ? NULL : i->sub_state;
 
         if (streq_ptr(i->active_state, "failed")) {
@@ -2387,7 +2417,7 @@ static void print_status_info(UnitStatusInfo *i) {
                 printf(" %*s: %s\n", maxlen, "What", i->what);
 
         STRV_FOREACH(t, i->documentation)
-                printf(" %*s: %s\n", maxlen, t == i->documentation ? "Docs" : "", *t);
+                printf(" %*s %s\n", maxlen+1, t == i->documentation ? "Docs:" : "", *t);
 
         STRV_FOREACH_PAIR(t, t2, i->listen)
                 printf(" %*s%s: %s\n", maxlen - (int)strlen(*t), "Listen", *t, *t2);
@@ -2494,10 +2524,13 @@ static void print_status_info(UnitStatusInfo *i) {
                 if (arg_transport != TRANSPORT_SSH) {
                         unsigned k = 0;
                         pid_t extra[2];
+                        char prefix[maxlen + 4];
+                        memset(prefix, ' ', sizeof(prefix) - 1);
+                        prefix[sizeof(prefix) - 1] = '\0';
 
                         c = columns();
-                        if (c > 18)
-                                c -= 18;
+                        if (c > sizeof(prefix) - 1)
+                                c -= sizeof(prefix) - 1;
                         else
                                 c = 0;
 
@@ -2507,7 +2540,8 @@ static void print_status_info(UnitStatusInfo *i) {
                         if (i->control_pid > 0)
                                 extra[k++] = i->control_pid;
 
-                        show_cgroup_and_extra_by_spec(i->default_control_group, "\t\t  ", c, false, extra, k, flags);
+                        show_cgroup_and_extra_by_spec(i->default_control_group, prefix,
+                                                      c, false, extra, k, flags);
                 }
         }
 
@@ -2767,6 +2801,11 @@ static int status_property(const char *name, DBusMessageIter *iter, UnitStatusIn
 
                         return 0;
 
+                } else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRING && streq(name, "DropInPaths")) {
+                        int r = bus_parse_strv_iter(iter, &i->dropin_paths);
+                        if (r < 0)
+                                return r;
+
                 } else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRING &&
                            streq(name, "Documentation")) {
 
@@ -3102,6 +3141,7 @@ static int show_one(const char *verb, DBusConnection *bus, const char *path, boo
         }
 
         strv_free(info.documentation);
+        strv_free(info.dropin_paths);
         strv_free(info.listen);
 
         if (!streq_ptr(info.active_state, "active") &&