]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: let's tweak how we synthesize a cell for activating unit
authorLennart Poettering <lennart@poettering.net>
Wed, 6 May 2020 12:48:54 +0000 (14:48 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 6 May 2020 13:40:15 +0000 (15:40 +0200)
Let's create a string cell for the unit if possible (since there can
only be one unit right now, and the JSON alternative output then
generates a string instead of an array for us), an empty cell if empty.

src/systemctl/systemctl.c

index 673f29bcaa3c2f2e7ce380e08b16ecb697078a68..07b0fdd2c5b3c2471736a48fd1b06e42a03a7a42 100644 (file)
@@ -1027,7 +1027,7 @@ static int output_sockets_list(struct socket_info *socket_infos, unsigned cs) {
 
         if (cs) {
                 for (s = socket_infos; s < socket_infos + cs; s++) {
-                        _cleanup_free_ char *j = NULL, *activates = NULL;
+                        _cleanup_free_ char *j = NULL;
                         const char *path;
 
                         if (s->machine) {
@@ -1038,17 +1038,25 @@ static int output_sockets_list(struct socket_info *socket_infos, unsigned cs) {
                         } else
                                 path = s->path;
 
-                        activates = strv_join(s->triggered, ", ");
-                        if (!activates)
-                                return log_oom();
-
                         r = table_add_many(table,
                                            TABLE_STRING, path,
                                            TABLE_STRING, s->type,
-                                           TABLE_STRING, s->id,
-                                           TABLE_STRING, activates);
+                                           TABLE_STRING, s->id);
                         if (r < 0)
                                 return table_log_add_error(r);
+
+                        if (strv_isempty(s->triggered))
+                                r = table_add_cell(table, NULL, TABLE_EMPTY, NULL);
+                        else if (strv_length(s->triggered) == 1)
+                                r = table_add_cell(table, NULL, TABLE_STRING, s->triggered[0]);
+                        else
+                                /* This should never happen, currently our socket units can only trigger a
+                                 * single unit. But let's handle this anyway, who knows what the future
+                                 * brings? */
+                                r = table_add_cell(table, NULL, TABLE_STRV, s->triggered);
+                        if (r < 0)
+                                return table_log_add_error(r);
+
                 }
 
                 on = ansi_highlight();