]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
various: handle the positive condition after strv_skip() first
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 19 Nov 2024 15:51:27 +0000 (16:51 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 27 Mar 2025 11:04:37 +0000 (12:04 +0100)
src/id128/id128.c
src/systemctl/systemctl-list-dependencies.c
src/udev/udev-builtin-kmod.c

index ed444c8022e4f1069075239c579a2418b8409f4c..d3e2f28c1e0f5e76c617b842c0b0f4822816b165 100644 (file)
@@ -133,17 +133,7 @@ static int verb_show(int argc, char **argv, void *userdata) {
         int r;
 
         argv = strv_skip(argv, 1);
-        if (strv_isempty(argv)) {
-                if (!sd_id128_is_null(arg_app))
-                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                               "'show --app-specific=' can only be used with explicit UUID input.");
-
-                for (const GptPartitionType *e = gpt_partition_type_table; e->name; e++) {
-                        r = show_one(&table, e->name, e->uuid, e == gpt_partition_type_table);
-                        if (r < 0)
-                                return r;
-                }
-        } else
+        if (argv)
                 STRV_FOREACH(p, argv) {
                         sd_id128_t uuid;
                         const char *id = NULL;
@@ -171,6 +161,17 @@ static int verb_show(int argc, char **argv, void *userdata) {
                         if (r < 0)
                                 return r;
                 }
+        else {
+                if (!sd_id128_is_null(arg_app))
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "'show --app-specific=' can only be used with explicit UUID input.");
+
+                for (const GptPartitionType *e = gpt_partition_type_table; e->name; e++) {
+                        r = show_one(&table, e->name, e->uuid, e == gpt_partition_type_table);
+                        if (r < 0)
+                                return r;
+                }
+        }
 
         if (table) {
                 r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
index 335e32f71c441a1d5bd569696d8c3a1c0f7c922e..8cd9fc83a1a09a38f53599ba5ea6588ba50a5cc4 100644 (file)
@@ -171,14 +171,14 @@ int verb_list_dependencies(int argc, char *argv[], void *userdata) {
                 return r;
 
         patterns = strv_skip(argv, 1);
-        if (strv_isempty(patterns)) {
-                units = strv_new(SPECIAL_DEFAULT_TARGET);
-                if (!units)
-                        return log_oom();
-        } else {
+        if (patterns) {
                 r = expand_unit_names(bus, patterns, NULL, &units, NULL);
                 if (r < 0)
                         return log_error_errno(r, "Failed to expand names: %m");
+        } else {
+                units = strv_new(SPECIAL_DEFAULT_TARGET);
+                if (!units)
+                        return log_oom();
         }
 
         pager_open(arg_pager_flags);
index e0553ce3e4b801ddfb24d547b1bdee7d751d7ea4..33031f7f40221a32bbcdfffea19a56ee79fbf2b3 100644 (file)
@@ -35,7 +35,10 @@ static int builtin_kmod(UdevEvent *event, int argc, char *argv[]) {
                                                 "%s: expected: load [module…]", argv[0]);
 
         char **modules = strv_skip(argv, 2);
-        if (strv_isempty(modules)) {
+        if (modules)
+                STRV_FOREACH(module, modules)
+                        (void) module_load_and_warn(ctx, *module, /* verbose = */ false);
+        else {
                 const char *modalias;
 
                 r = sd_device_get_property_value(dev, "MODALIAS", &modalias);
@@ -43,9 +46,7 @@ static int builtin_kmod(UdevEvent *event, int argc, char *argv[]) {
                         return log_device_warning_errno(dev, r, "Failed to read property \"MODALIAS\": %m");
 
                 (void) module_load_and_warn(ctx, modalias, /* verbose = */ false);
-        } else
-                STRV_FOREACH(module, modules)
-                        (void) module_load_and_warn(ctx, *module, /* verbose = */ false);
+        }
 
         return 0;
 }