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.
This commit is contained in:
Lennart Poettering
2020-05-06 15:40:15 +02:00
parent bc04bb0d29
commit 50098d87fb
+15 -7
View 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();