tree-wide: use strv_extend_strv_consume() where appropriate

This commit is contained in:
Mike Yuan
2024-09-21 00:53:50 +02:00
parent 8a7ade7427
commit a2c8652a2a
20 changed files with 54 additions and 113 deletions
+2 -2
View File
@@ -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;
+3 -7
View File
@@ -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) {
+16 -26
View File
@@ -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;
}