]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: drop unneeded condition
authorDavid Tardon <dtardon@redhat.com>
Mon, 25 Jul 2022 07:28:31 +0000 (09:28 +0200)
committerDavid Tardon <dtardon@redhat.com>
Mon, 25 Jul 2022 11:12:31 +0000 (13:12 +0200)
src/systemctl/systemctl-list-units.c

index a6596ddd0eaa56f48fccad69ae0867492ee5f2a6..96bc4d47eabdfdac4b5315da57ab6fbdbd0536dd 100644 (file)
@@ -352,6 +352,8 @@ static int output_sockets_list(struct socket_info *socket_infos, size_t cs) {
         _cleanup_(table_unrefp) Table *table = NULL;
         int r;
 
+        assert(socket_infos || cs == 0);
+
         table = table_new("listen", "type", "unit", "activates");
         if (!table)
                 return log_oom();
@@ -369,38 +371,36 @@ static int output_sockets_list(struct socket_info *socket_infos, size_t cs) {
 
         (void) table_set_empty_string(table, "-");
 
-        if (cs > 0) {
-                for (struct socket_info *s = socket_infos; s < socket_infos + cs; s++) {
-                        _cleanup_free_ char *j = NULL;
-                        const char *path;
-
-                        if (s->machine) {
-                                j = strjoin(s->machine, ":", s->path);
-                                if (!j)
-                                        return log_oom();
-                                path = j;
-                        } else
-                                path = s->path;
-
-                        r = table_add_many(table,
-                                           TABLE_STRING, path,
-                                           TABLE_STRING, s->type,
-                                           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);
-                }
+        for (struct socket_info *s = socket_infos; s < socket_infos + cs; s++) {
+                _cleanup_free_ char *j = NULL;
+                const char *path;
+
+                if (s->machine) {
+                        j = strjoin(s->machine, ":", s->path);
+                        if (!j)
+                                return log_oom();
+                        path = j;
+                } else
+                        path = s->path;
+
+                r = table_add_many(table,
+                                        TABLE_STRING, path,
+                                        TABLE_STRING, s->type,
+                                        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);
         }
 
         r = output_table(table);