From: Lennart Poettering Date: Wed, 6 May 2020 12:48:54 +0000 (+0200) Subject: systemctl: let's tweak how we synthesize a cell for activating unit X-Git-Tag: v246-rc1~429^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=50098d87fbe677bd43cb7329b2e32b039401f35c;p=thirdparty%2Fsystemd.git systemctl: let's tweak how we synthesize a cell for activating unit 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. --- diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 673f29bcaa3..07b0fdd2c5b 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -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();