tree-wide: port over various pieces of code to strv_extend_many()

This commit is contained in:
Lennart Poettering
2024-01-17 11:32:11 +01:00
parent 80f1e209a5
commit 69f3c61990
12 changed files with 72 additions and 101 deletions
+13 -23
View File
@@ -167,19 +167,13 @@ static char** user_dirs(
return NULL;
/* Now merge everything we found. */
if (strv_extend(&res, persistent_control) < 0)
return NULL;
if (strv_extend(&res, runtime_control) < 0)
return NULL;
if (strv_extend(&res, transient) < 0)
return NULL;
if (strv_extend(&res, generator_early) < 0)
return NULL;
if (strv_extend(&res, persistent_config) < 0)
if (strv_extend_many(
&res,
persistent_control,
runtime_control,
transient,
generator_early,
persistent_config) < 0)
return NULL;
if (strv_extend_strv_concat(&res, config_dirs, "/systemd/user") < 0)
@@ -192,16 +186,12 @@ static char** user_dirs(
if (strv_extend_strv(&res, (char**) user_config_unit_paths, false) < 0)
return NULL;
if (strv_extend(&res, runtime_config) < 0)
return NULL;
if (strv_extend(&res, global_runtime_config) < 0)
return NULL;
if (strv_extend(&res, generator) < 0)
return NULL;
if (strv_extend(&res, data_home) < 0)
if (strv_extend_many(
&res,
runtime_config,
global_runtime_config,
generator,
data_home) < 0)
return NULL;
if (strv_extend_strv_concat(&res, data_dirs, "/systemd/user") < 0)
+5 -6
View File
@@ -300,12 +300,11 @@ static int parse_argv(int argc, char *argv[]) {
if (strv_isempty(arg_phase)) {
/* If no phases are specifically selected, pick everything from the beginning of the initrd
* to the beginning of shutdown. */
if (strv_extend_strv(&arg_phase,
STRV_MAKE("enter-initrd",
"enter-initrd:leave-initrd",
"enter-initrd:leave-initrd:sysinit",
"enter-initrd:leave-initrd:sysinit:ready"),
/* filter_duplicates= */ false) < 0)
if (strv_extend_many(&arg_phase,
"enter-initrd",
"enter-initrd:leave-initrd",
"enter-initrd:leave-initrd:sysinit",
"enter-initrd:leave-initrd:sysinit:ready") < 0)
return log_oom();
} else {
strv_sort(arg_phase);
+4 -5
View File
@@ -2811,11 +2811,10 @@ static int compile_symlinks(
* absolute, when they are processed in namespace.c they will be made relative automatically, i.e.:
* 'os-release -> .os-release-stage/os-release' is what will be created. */
if (setup_os_release_symlink) {
r = strv_extend(&symlinks, "/run/host/.os-release-stage/os-release");
if (r < 0)
return r;
r = strv_extend(&symlinks, "/run/host/os-release");
r = strv_extend_many(
&symlinks,
"/run/host/.os-release-stage/os-release",
"/run/host/os-release");
if (r < 0)
return r;
}
+1 -5
View File
@@ -994,11 +994,7 @@ static int activation_details_path_append_pair(ActivationDetails *details, char
if (isempty(p->trigger_path_filename))
return 0;
r = strv_extend(strv, "trigger_path");
if (r < 0)
return r;
r = strv_extend(strv, p->trigger_path_filename);
r = strv_extend_many(strv, "trigger_path", p->trigger_path_filename);
if (r < 0)
return r;
+1 -5
View File
@@ -6530,11 +6530,7 @@ int activation_details_append_pair(ActivationDetails *details, char ***strv) {
return 0;
if (!isempty(details->trigger_unit_name)) {
r = strv_extend(strv, "trigger_unit");
if (r < 0)
return r;
r = strv_extend(strv, details->trigger_unit_name);
r = strv_extend_many(strv, "trigger_unit", details->trigger_unit_name);
if (r < 0)
return r;
}
+3 -3
View File
@@ -1242,7 +1242,7 @@ static int run_debug(int argc, char **argv, void *userdata) {
if (r < 0)
return r;
r = strv_extend_strv(&debugger_call, STRV_MAKE(exe, "-c", path), false);
r = strv_extend_many(&debugger_call, exe, "-c", path);
if (r < 0)
return log_oom();
@@ -1251,14 +1251,14 @@ static int run_debug(int argc, char **argv, void *userdata) {
const char *sysroot_cmd;
sysroot_cmd = strjoina("set sysroot ", arg_root);
r = strv_extend_strv(&debugger_call, STRV_MAKE("-iex", sysroot_cmd), false);
r = strv_extend_many(&debugger_call, "-iex", sysroot_cmd);
if (r < 0)
return log_oom();
} else if (streq(arg_debugger, "lldb")) {
const char *sysroot_cmd;
sysroot_cmd = strjoina("platform select --sysroot ", arg_root, " host");
r = strv_extend_strv(&debugger_call, STRV_MAKE("-O", sysroot_cmd), false);
r = strv_extend_many(&debugger_call, "-O", sysroot_cmd);
if (r < 0)
return log_oom();
}
+4 -5
View File
@@ -978,11 +978,10 @@ static int context_build_arguments(Context *c) {
return log_oom();
} else if (c->action == ACTION_INSPECT) {
r = strv_extend(&a, c->kernel ?: "[KERNEL_IMAGE]");
if (r < 0)
return log_oom();
r = strv_extend(&a, "[INITRD...]");
r = strv_extend_many(
&a,
c->kernel ?: "[KERNEL_IMAGE]",
"[INITRD...]");
if (r < 0)
return log_oom();
}
+1 -1
View File
@@ -1588,7 +1588,7 @@ static int oci_sysctl(const char *name, JsonVariant *v, JsonDispatchFlags flags,
return json_log(v, flags, SYNTHETIC_ERRNO(EINVAL),
"sysctl key invalid, refusing: %s", k);
r = strv_extend_strv(&s->sysctl, STRV_MAKE(k, m), false);
r = strv_extend_many(&s->sysctl, k, m);
if (r < 0)
return log_oom();
}
+3 -3
View File
@@ -425,7 +425,7 @@ int make_filesystem(
"-T", "default",
node);
if (root && strv_extend_strv(&argv, STRV_MAKE("-d", root), false) < 0)
if (root && strv_extend_many(&argv, "-d", root) < 0)
return log_oom();
if (quiet && strv_extend(&argv, "-q") < 0)
@@ -450,7 +450,7 @@ int make_filesystem(
if (!discard && strv_extend(&argv, "--nodiscard") < 0)
return log_oom();
if (root && strv_extend_strv(&argv, STRV_MAKE("-r", root), false) < 0)
if (root && strv_extend_many(&argv, "-r", root) < 0)
return log_oom();
if (quiet && strv_extend(&argv, "-q") < 0)
@@ -514,7 +514,7 @@ int make_filesystem(
if (!protofile_with_opt)
return -ENOMEM;
if (strv_extend_strv(&argv, STRV_MAKE("-p", protofile_with_opt), false) < 0)
if (strv_extend_many(&argv, "-p", protofile_with_opt) < 0)
return log_oom();
}
+1 -5
View File
@@ -932,11 +932,7 @@ static int map_listen(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus
while ((r = sd_bus_message_read(m, "(ss)", &type, &path)) > 0) {
r = strv_extend(p, type);
if (r < 0)
return r;
r = strv_extend(p, path);
r = strv_extend_many(p, type, path);
if (r < 0)
return r;
}
+11 -15
View File
@@ -355,15 +355,11 @@ static int user_config_paths(char*** ret) {
if (r < 0)
return r;
r = strv_extend(&res, persistent_config);
if (r < 0)
return r;
r = strv_extend(&res, runtime_config);
if (r < 0)
return r;
r = strv_extend(&res, data_home);
r = strv_extend_many(
&res,
persistent_config,
runtime_config,
data_home);
if (r < 0)
return r;
@@ -3983,16 +3979,16 @@ static int exclude_default_prefixes(void) {
* likely over-mounted if the root directory is actually used, and it wouldbe less than ideal to have
* all kinds of files created/adjusted underneath these mount points. */
r = strv_extend_strv(
r = strv_extend_many(
&arg_exclude_prefixes,
STRV_MAKE("/dev",
"/proc",
"/run",
"/sys"),
true);
"/dev",
"/proc",
"/run",
"/sys");
if (r < 0)
return log_oom();
strv_uniq(arg_exclude_prefixes);
return 0;
}
+25 -25
View File
@@ -516,25 +516,25 @@ static int run_virtual_machine(void) {
return log_oom();
}
r = strv_extend_strv(&cmdline, STRV_MAKE("-cpu", "max"), /* filter_duplicates= */ false);
r = strv_extend_many(&cmdline, "-cpu", "max");
if (r < 0)
return log_oom();
if (arg_qemu_gui) {
r = strv_extend_strv(&cmdline, STRV_MAKE("-vga", "virtio"), /* filter_duplicates= */ false);
if (r < 0)
return log_oom();
} else {
r = strv_extend_strv(&cmdline, STRV_MAKE(
"-nographic",
"-nodefaults",
"-chardev", "stdio,mux=on,id=console,signal=off",
"-serial", "chardev:console",
"-mon", "console"
), /* filter_duplicates= */ false);
if (r < 0)
return log_oom();
}
if (arg_qemu_gui)
r = strv_extend_many(
&cmdline,
"-vga",
"virtio");
else
r = strv_extend_many(
&cmdline,
"-nographic",
"-nodefaults",
"-chardev", "stdio,mux=on,id=console,signal=off",
"-serial", "chardev:console",
"-mon", "console");
if (r < 0)
return log_oom();
if (ARCHITECTURE_SUPPORTS_SMBIOS)
FOREACH_ARRAY(cred, arg_credentials.credentials, arg_credentials.n_credentials) {
@@ -588,11 +588,11 @@ static int run_virtual_machine(void) {
(void) copy_access(source_fd, target_fd);
(void) copy_times(source_fd, target_fd, 0);
r = strv_extend_strv(&cmdline, STRV_MAKE(
"-global", "ICH9-LPC.disable_s3=1",
"-global", "driver=cfi.pflash01,property=secure,value=on",
"-drive"
), /* filter_duplicates= */ false);
r = strv_extend_many(
&cmdline,
"-global", "ICH9-LPC.disable_s3=1",
"-global", "driver=cfi.pflash01,property=secure,value=on",
"-drive");
if (r < 0)
return log_oom();
@@ -609,10 +609,10 @@ static int run_virtual_machine(void) {
if (r < 0)
return log_oom();
r = strv_extend_strv(&cmdline, STRV_MAKE(
"-device", "virtio-scsi-pci,id=scsi",
"-device", "scsi-hd,drive=mkosi,bootindex=1"
), /* filter_duplicates= */ false);
r = strv_extend_many(
&cmdline,
"-device", "virtio-scsi-pci,id=scsi",
"-device", "scsi-hd,drive=mkosi,bootindex=1");
if (r < 0)
return log_oom();