1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-31 14:50:15 +03:00

tree-wide: make invocations of extract_first_word more uniform (#4627)

extract_first_words deals fine with the string being NULL, so drop the upfront
check for that.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2016-11-11 12:58:41 -05:00 committed by Lennart Poettering
parent 5f36e3d303
commit c58bd76a6a
7 changed files with 40 additions and 72 deletions

View File

@ -48,7 +48,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
/* Bail early if called after last value or with no input */
if (!*p)
goto finish_force_terminate;
goto finish;
c = **p;
if (!separators)

View File

@ -224,13 +224,8 @@ static int network_link_get_ifindexes(int ifindex, const char *key, int **ret) {
return -ENODATA;
if (r < 0)
return r;
if (isempty(s)) {
*ret = NULL;
return 0;
}
x = s;
for (;;) {
for (x = s;;) {
_cleanup_free_ char *word = NULL;
r = extract_first_word(&x, &word, NULL, 0);
@ -243,15 +238,14 @@ static int network_link_get_ifindexes(int ifindex, const char *key, int **ret) {
if (r < 0)
return r;
if (!GREEDY_REALLOC(ifis, allocated, c + 1))
if (!GREEDY_REALLOC(ifis, allocated, c + 2))
return -ENOMEM;
ifis[c++] = ifindex;
}
if (!GREEDY_REALLOC(ifis, allocated, c + 1))
return -ENOMEM;
ifis[c] = 0; /* Let's add a 0 ifindex to the end, to be nice*/
if (ifis)
ifis[c] = 0; /* Let's add a 0 ifindex to the end, to be nice*/
*ret = ifis;
ifis = NULL;

View File

@ -997,6 +997,7 @@ int link_load_user(Link *l) {
*ntas = NULL;
ResolveSupport s;
const char *p;
int r;
assert(l);
@ -1037,48 +1038,40 @@ int link_load_user(Link *l) {
/* If we can't recognize the DNSSEC setting, then set it to invalid, so that the daemon default is used. */
l->dnssec_mode = dnssec_mode_from_string(dnssec);
if (servers) {
const char *p = servers;
for (p = servers;;) {
_cleanup_free_ char *word = NULL;
for (;;) {
_cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, NULL, 0);
if (r < 0)
goto fail;
if (r == 0)
break;
r = extract_first_word(&p, &word, NULL, 0);
if (r < 0)
goto fail;
if (r == 0)
break;
r = link_update_dns_server_one(l, word);
if (r < 0) {
log_debug_errno(r, "Failed to load DNS server '%s', ignoring: %m", word);
continue;
}
r = link_update_dns_server_one(l, word);
if (r < 0) {
log_debug_errno(r, "Failed to load DNS server '%s', ignoring: %m", word);
continue;
}
}
if (domains) {
const char *p = domains;
for (p = domains;;) {
_cleanup_free_ char *word = NULL;
const char *n;
bool is_route;
for (;;) {
_cleanup_free_ char *word = NULL;
const char *n;
bool is_route;
r = extract_first_word(&p, &word, NULL, 0);
if (r < 0)
goto fail;
if (r == 0)
break;
r = extract_first_word(&p, &word, NULL, 0);
if (r < 0)
goto fail;
if (r == 0)
break;
is_route = word[0] == '~';
n = is_route ? word + 1 : word;
is_route = word[0] == '~';
n = is_route ? word + 1 : word;
r = link_update_search_domain_one(l, n, is_route);
if (r < 0) {
log_debug_errno(r, "Failed to load search domain '%s', ignoring: %m", word);
continue;
}
r = link_update_search_domain_one(l, n, is_route);
if (r < 0) {
log_debug_errno(r, "Failed to load search domain '%s', ignoring: %m", word);
continue;
}
}

View File

@ -398,9 +398,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
if (r < 0)
return bus_log_create_error(r);
p = eq;
for (;;) {
for (p = eq;;) {
_cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_CUNESCAPE);
@ -482,9 +480,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
if (r < 0)
return bus_log_create_error(r);
p = eq;
for (;;) {
for (p = eq;;) {
_cleanup_free_ char *word = NULL;
int offset;
@ -531,9 +527,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
if (r < 0)
return bus_log_create_error(r);
p = eq;
for (;;) {
for (p = eq;;) {
_cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES);

View File

@ -111,9 +111,8 @@ static int condition_test_kernel_command_line(Condition *c) {
return r;
equal = !!strchr(c->parameter, '=');
p = line;
for (;;) {
for (p = line;;) {
_cleanup_free_ char *word = NULL;
bool found;

View File

@ -69,11 +69,6 @@ int namespace_flag_from_string_many(const char *name, unsigned long *ret) {
assert_se(ret);
if (!name) {
*ret = 0;
return 0;
}
for (;;) {
_cleanup_free_ char *word = NULL;
unsigned long f;

View File

@ -7214,14 +7214,12 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
return -EINVAL;
}
p = optarg;
for (;;) {
for (p = optarg;;) {
_cleanup_free_ char *type = NULL;
r = extract_first_word(&p, &type, ",", 0);
if (r < 0)
return log_error_errno(r, "Failed to parse type: %s", optarg);
if (r == 0)
break;
@ -7263,15 +7261,13 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
arg_properties = new0(char*, 1);
if (!arg_properties)
return log_oom();
} else {
p = optarg;
for (;;) {
} else
for (p = optarg;;) {
_cleanup_free_ char *prop = NULL;
r = extract_first_word(&p, &prop, ",", 0);
if (r < 0)
return log_error_errno(r, "Failed to parse property: %s", optarg);
if (r == 0)
break;
@ -7280,7 +7276,6 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
prop = NULL;
}
}
/* If the user asked for a particular
* property, show it to him, even if it is
@ -7457,14 +7452,12 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
return -EINVAL;
}
p = optarg;
for (;;) {
for (p = optarg;;) {
_cleanup_free_ char *s = NULL;
r = extract_first_word(&p, &s, ",", 0);
if (r < 0)
return log_error_errno(r, "Failed to parse signal: %s", optarg);
if (r == 0)
break;