various: handle the positive condition after strv_skip() first

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2024-11-19 16:51:27 +01:00
parent 129446ddec
commit fdfa9fd8ab
3 changed files with 22 additions and 20 deletions

View 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);

View 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);

View 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;
}