diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-11-11 12:58:41 -0500 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-11-11 18:58:41 +0100 |
commit | c58bd76a6af673196ad283131cbe3edcf2bf6291 (patch) | |
tree | f6e10c3e79cd25b9eca6be7b2fa024ef009a29b5 /src | |
parent | 5f36e3d30375cf04292bbc1bf3f4d7512cf80139 (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/extract-word.c | 2 | ||||
-rw-r--r-- | src/libsystemd/sd-network/sd-network.c | 14 | ||||
-rw-r--r-- | src/resolve/resolved-link.c | 61 | ||||
-rw-r--r-- | src/shared/bus-unit-util.c | 12 | ||||
-rw-r--r-- | src/shared/condition.c | 3 | ||||
-rw-r--r-- | src/shared/nsflags.c | 5 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 15 |
7 files changed, 40 insertions, 72 deletions
diff --git a/src/basic/extract-word.c b/src/basic/extract-word.c index d6c1228463..dbe64a9a58 100644 --- a/src/basic/extract-word.c +++ b/src/basic/extract-word.c @@ -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) diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index f8e18f23fd..0d8d99c56d 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -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; diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c index 13e1f91192..e7e5c5f5a7 100644 --- a/src/resolve/resolved-link.c +++ b/src/resolve/resolved-link.c @@ -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; } } diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 35e2c8f18e..4f66497f3a 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -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); diff --git a/src/shared/condition.c b/src/shared/condition.c index 8bd6a51a99..525e65aedf 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -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; diff --git a/src/shared/nsflags.c b/src/shared/nsflags.c index 8fcbe97ba7..911779a28f 100644 --- a/src/shared/nsflags.c +++ b/src/shared/nsflags.c @@ -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; diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index af5b18c0ed..8a9a47a88e 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -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; |