mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 17:06:39 +09:00
tree-wide: use strv_extend_strv_consume() where appropriate
This commit is contained in:
@@ -796,10 +796,10 @@ int replace_env_full(
|
||||
t = v;
|
||||
}
|
||||
|
||||
r = strv_extend_strv(&unset_variables, u, /* filter_duplicates= */ true);
|
||||
r = strv_extend_strv_consume(&unset_variables, TAKE_PTR(u), /* filter_duplicates= */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
r = strv_extend_strv(&bad_variables, b, /* filter_duplicates= */ true);
|
||||
r = strv_extend_strv_consume(&bad_variables, TAKE_PTR(b), /* filter_duplicates= */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -931,11 +931,11 @@ int replace_env_argv(
|
||||
return r;
|
||||
n[++k] = NULL;
|
||||
|
||||
r = strv_extend_strv(&unset_variables, u, /* filter_duplicates= */ true);
|
||||
r = strv_extend_strv_consume(&unset_variables, TAKE_PTR(u), /* filter_duplicates= */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = strv_extend_strv(&bad_variables, b, /*filter_duplicates= */ true);
|
||||
r = strv_extend_strv_consume(&bad_variables, TAKE_PTR(b), /* filter_duplicates= */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ int strv_split_full(char ***t, const char *s, const char *separators, ExtractFla
|
||||
}
|
||||
|
||||
int strv_split_and_extend_full(char ***t, const char *s, const char *separators, bool filter_duplicates, ExtractFlags flags) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
char **l;
|
||||
int r;
|
||||
|
||||
assert(t);
|
||||
@@ -415,7 +415,7 @@ int strv_split_and_extend_full(char ***t, const char *s, const char *separators,
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = strv_extend_strv(t, l, filter_duplicates);
|
||||
r = strv_extend_strv_consume(t, l, filter_duplicates);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -2046,7 +2046,7 @@ int exec_command_set(ExecCommand *c, const char *path, ...) {
|
||||
}
|
||||
|
||||
int exec_command_append(ExecCommand *c, const char *path, ...) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
char **l;
|
||||
va_list ap;
|
||||
int r;
|
||||
|
||||
@@ -2060,7 +2060,7 @@ int exec_command_append(ExecCommand *c, const char *path, ...) {
|
||||
if (!l)
|
||||
return -ENOMEM;
|
||||
|
||||
r = strv_extend_strv(&c->argv, l, false);
|
||||
r = strv_extend_strv_consume(&c->argv, l, /* filter_duplicates = */ false);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -106,13 +106,9 @@ int unit_load_dropin(Unit *u) {
|
||||
if (r <= 0)
|
||||
return 0;
|
||||
|
||||
if (!u->dropin_paths)
|
||||
u->dropin_paths = TAKE_PTR(l);
|
||||
else {
|
||||
r = strv_extend_strv(&u->dropin_paths, l, true);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
r = strv_extend_strv_consume(&u->dropin_paths, TAKE_PTR(l), /* filter_duplicates = */ true);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
u->dropin_mtime = 0;
|
||||
STRV_FOREACH(f, u->dropin_paths) {
|
||||
|
||||
@@ -2779,10 +2779,8 @@ int config_parse_pass_environ(
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_strv_free_ char **n = NULL;
|
||||
char ***passenv = ASSERT_PTR(data);
|
||||
const Unit *u = userdata;
|
||||
char*** passenv = ASSERT_PTR(data);
|
||||
size_t nlen = 0;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
@@ -2795,6 +2793,8 @@ int config_parse_pass_environ(
|
||||
return 0;
|
||||
}
|
||||
|
||||
_cleanup_strv_free_ char **n = NULL;
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *word = NULL, *k = NULL;
|
||||
|
||||
@@ -2825,19 +2825,14 @@ int config_parse_pass_environ(
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!GREEDY_REALLOC(n, nlen + 2))
|
||||
return log_oom();
|
||||
|
||||
n[nlen++] = TAKE_PTR(k);
|
||||
n[nlen] = NULL;
|
||||
}
|
||||
|
||||
if (n) {
|
||||
r = strv_extend_strv(passenv, n, true);
|
||||
if (r < 0)
|
||||
if (strv_consume(&n, TAKE_PTR(k)) < 0)
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
r = strv_extend_strv_consume(passenv, TAKE_PTR(n), /* filter_duplicates = */ true);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2853,10 +2848,8 @@ int config_parse_unset_environ(
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_strv_free_ char **n = NULL;
|
||||
char*** unsetenv = ASSERT_PTR(data);
|
||||
char ***unsetenv = ASSERT_PTR(data);
|
||||
const Unit *u = userdata;
|
||||
size_t nlen = 0;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
@@ -2869,6 +2862,8 @@ int config_parse_unset_environ(
|
||||
return 0;
|
||||
}
|
||||
|
||||
_cleanup_strv_free_ char **n = NULL;
|
||||
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *word = NULL, *k = NULL;
|
||||
|
||||
@@ -2899,19 +2894,14 @@ int config_parse_unset_environ(
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!GREEDY_REALLOC(n, nlen + 2))
|
||||
return log_oom();
|
||||
|
||||
n[nlen++] = TAKE_PTR(k);
|
||||
n[nlen] = NULL;
|
||||
}
|
||||
|
||||
if (n) {
|
||||
r = strv_extend_strv(unsetenv, n, true);
|
||||
if (r < 0)
|
||||
if (strv_consume(&n, TAKE_PTR(k)) < 0)
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
r = strv_extend_strv_consume(unsetenv, TAKE_PTR(n), /* filter_duplicates = */ true);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -3652,7 +3652,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
return log_error_errno(r, "Failed to parse SSH authorized keys list: %m");
|
||||
}
|
||||
|
||||
r = strv_extend_strv(&l, add, true);
|
||||
r = strv_extend_strv_consume(&l, TAKE_PTR(add), /* filter_duplicates = */ true);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
|
||||
@@ -424,7 +424,7 @@ int dhcp6_lease_add_domains(sd_dhcp6_lease *lease, const uint8_t *optval, size_t
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return strv_extend_strv(&lease->domains, domains, true);
|
||||
return strv_extend_strv_consume(&lease->domains, TAKE_PTR(domains), /* filter_duplicates = */ true);
|
||||
}
|
||||
|
||||
int sd_dhcp6_lease_get_domains(sd_dhcp6_lease *lease, char ***ret) {
|
||||
|
||||
@@ -410,7 +410,7 @@ static int varlink_connect_ssh_exec(sd_varlink **ret, const char *where) {
|
||||
full_cmdline = strv_new("ssh", "-e", "none", "-T", h, "env", "SYSTEMD_VARLINK_LISTEN=-");
|
||||
if (!full_cmdline)
|
||||
return log_oom_debug();
|
||||
r = strv_extend_strv(&full_cmdline, cmdline, /* filter_duplicates= */ false);
|
||||
r = strv_extend_strv_consume(&full_cmdline, TAKE_PTR(cmdline), /* filter_duplicates= */ false);
|
||||
if (r < 0)
|
||||
return log_oom_debug();
|
||||
|
||||
|
||||
@@ -23,19 +23,6 @@ static const char conf_file_dirs[] = CONF_PATHS_NULSTR("modules-load.d");
|
||||
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_proc_cmdline_modules, strv_freep);
|
||||
|
||||
static int add_modules(const char *p) {
|
||||
_cleanup_strv_free_ char **k = NULL;
|
||||
|
||||
k = strv_split(p, ",");
|
||||
if (!k)
|
||||
return log_oom();
|
||||
|
||||
if (strv_extend_strv(&arg_proc_cmdline_modules, k, true) < 0)
|
||||
return log_oom();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
|
||||
int r;
|
||||
|
||||
@@ -44,9 +31,9 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
|
||||
if (proc_cmdline_value_missing(key, value))
|
||||
return 0;
|
||||
|
||||
r = add_modules(value);
|
||||
r = strv_split_and_extend(&arg_proc_cmdline_modules, value, ",", /* filter_duplicates = */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_error_errno(r, "Failed to parse modules_load= kernel command line option: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -5361,13 +5361,13 @@ static int make_subvolumes_strv(const Partition *p, char ***ret) {
|
||||
return log_oom();
|
||||
|
||||
if (p->suppressing) {
|
||||
_cleanup_strv_free_ char **suppressing = NULL;
|
||||
char **suppressing;
|
||||
|
||||
r = make_subvolumes_strv(p->suppressing, &suppressing);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = strv_extend_strv(&subvolumes, suppressing, /* filter_duplicates= */ true);
|
||||
r = strv_extend_strv_consume(&subvolumes, suppressing, /* filter_duplicates= */ true);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
@@ -721,13 +721,7 @@ static int extract_image_and_extensions(
|
||||
|
||||
e = strv_env_pairs_get(extension_release, "PORTABLE_PREFIXES");
|
||||
if (e) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
|
||||
l = strv_split(e, WHITESPACE);
|
||||
if (!l)
|
||||
return -ENOMEM;
|
||||
|
||||
r = strv_extend_strv(&valid_prefixes, l, true);
|
||||
r = strv_split_and_extend(&valid_prefixes, e, WHITESPACE, /* filter_duplicates = */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ static int parse_path_many(
|
||||
return r;
|
||||
}
|
||||
|
||||
return strv_extend_strv(s, f, /* filter_duplicates= */ false);
|
||||
return strv_extend_strv_consume(s, TAKE_PTR(f), /* filter_duplicates= */ false);
|
||||
}
|
||||
|
||||
static int parse_tries(const char *fname, const char **p, unsigned *ret) {
|
||||
|
||||
@@ -1343,7 +1343,7 @@ int config_parse_strv(
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
r = strv_extend_strv(sv, strv, /* filter_duplicates = */ ltype);
|
||||
r = strv_extend_strv_consume(sv, TAKE_PTR(strv), /* filter_duplicates = */ ltype);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
|
||||
@@ -49,25 +49,8 @@ int dlopen_libkmod(void) {
|
||||
DLSYM_ARG(kmod_validate_resources));
|
||||
}
|
||||
|
||||
static int denylist_modules(const char *p, char ***denylist) {
|
||||
_cleanup_strv_free_ char **k = NULL;
|
||||
int r;
|
||||
|
||||
assert(p);
|
||||
assert(denylist);
|
||||
|
||||
k = strv_split(p, ",");
|
||||
if (!k)
|
||||
return -ENOMEM;
|
||||
|
||||
r = strv_extend_strv(denylist, k, /* filter_duplicates= */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
|
||||
char ***denylist = ASSERT_PTR(data);
|
||||
int r;
|
||||
|
||||
if (proc_cmdline_key_streq(key, "module_blacklist")) {
|
||||
@@ -75,7 +58,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
|
||||
if (proc_cmdline_value_missing(key, value))
|
||||
return 0;
|
||||
|
||||
r = denylist_modules(value, data);
|
||||
r = strv_split_and_extend(denylist, value, ",", /* filter_duplicates = */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -626,16 +626,15 @@ static int json_dispatch_weight(const char *name, sd_json_variant *variant, sd_j
|
||||
}
|
||||
|
||||
int json_dispatch_user_group_list(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
|
||||
char ***list = ASSERT_PTR(userdata);
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
char ***list = userdata;
|
||||
sd_json_variant *e;
|
||||
int r;
|
||||
|
||||
if (!sd_json_variant_is_array(variant))
|
||||
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array of strings.", strna(name));
|
||||
|
||||
sd_json_variant *e;
|
||||
JSON_VARIANT_ARRAY_FOREACH(e, variant) {
|
||||
|
||||
if (!sd_json_variant_is_string(e))
|
||||
return json_log(e, flags, SYNTHETIC_ERRNO(EINVAL), "JSON array element is not a string.");
|
||||
|
||||
@@ -647,7 +646,7 @@ int json_dispatch_user_group_list(const char *name, sd_json_variant *variant, sd
|
||||
return json_log(e, flags, r, "Failed to append array element: %m");
|
||||
}
|
||||
|
||||
r = strv_extend_strv(list, l, true);
|
||||
r = strv_extend_strv_consume(list, TAKE_PTR(l), /* filter_duplicates = */ true);
|
||||
if (r < 0)
|
||||
return json_log(variant, flags, r, "Failed to merge user/group arrays: %m");
|
||||
|
||||
|
||||
@@ -739,14 +739,14 @@ int append_unit_dependencies(sd_bus *bus, char **names, char ***ret) {
|
||||
assert(ret);
|
||||
|
||||
STRV_FOREACH(name, names) {
|
||||
_cleanup_strv_free_ char **deps = NULL;
|
||||
char **deps;
|
||||
|
||||
if (strv_extend(&with_deps, *name) < 0)
|
||||
return log_oom();
|
||||
|
||||
(void) unit_get_dependencies(bus, *name, &deps);
|
||||
|
||||
if (strv_extend_strv(&with_deps, deps, true) < 0)
|
||||
if (strv_extend_strv_consume(&with_deps, deps, /* filter_duplicates = */ true) < 0)
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
|
||||
@@ -1771,12 +1771,13 @@ static int method_list_appstream(sd_bus_message *msg, void *userdata, sd_bus_err
|
||||
return r;
|
||||
|
||||
HASHMAP_FOREACH(t, m->targets) {
|
||||
_cleanup_strv_free_ char **target_appstream = NULL;
|
||||
char **target_appstream;
|
||||
|
||||
r = target_get_appstream(t, &target_appstream);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = strv_extend_strv(&urls, target_appstream, true);
|
||||
r = strv_extend_strv_consume(&urls, target_appstream, /* filter_duplicates = */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ static int emit_deprecation_warning(void) {
|
||||
NULL,
|
||||
&b);
|
||||
|
||||
r = strv_extend_strv(&a, b, true);
|
||||
r = strv_extend_strv_consume(&a, TAKE_PTR(b), /* filter_duplicates = */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -1220,15 +1220,9 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
if (isempty(optarg))
|
||||
arg_services = strv_free(arg_services);
|
||||
else {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
|
||||
l = strv_split(optarg, ":");
|
||||
if (!l)
|
||||
return log_oom();
|
||||
|
||||
r = strv_extend_strv(&arg_services, l, true);
|
||||
r = strv_split_and_extend(&arg_services, optarg, ":", /* filter_duplicates = */ true);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
return log_error_errno(r, "Failed to parse -s/--service= argument: %m");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -2088,14 +2088,11 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
|
||||
|
||||
const char *e = secure_getenv("SYSTEMD_VMSPAWN_QEMU_EXTRA");
|
||||
if (e) {
|
||||
_cleanup_strv_free_ char **extra = NULL;
|
||||
|
||||
r = strv_split_full(&extra, e, /* separator= */ NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
|
||||
r = strv_split_and_extend_full(&cmdline, e,
|
||||
/* separator = */ NULL, /* filter_duplicates = */ false,
|
||||
EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to split $SYSTEMD_VMSPAWN_QEMU_EXTRA environment variable: %m");
|
||||
|
||||
if (strv_extend_strv(&cmdline, extra, /* filter_duplicates= */ false) < 0)
|
||||
return log_oom();
|
||||
return log_error_errno(r, "Failed to parse $SYSTEMD_VMSPAWN_QEMU_EXTRA: %m");
|
||||
}
|
||||
|
||||
if (DEBUG_LOGGING) {
|
||||
|
||||
Reference in New Issue
Block a user