]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: make invocations of extract_first_word more uniform (#4627)
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 11 Nov 2016 17:58:41 +0000 (12:58 -0500)
committerLennart Poettering <lennart@poettering.net>
Fri, 11 Nov 2016 17:58:41 +0000 (18:58 +0100)
extract_first_words deals fine with the string being NULL, so drop the upfront
check for that.

src/basic/extract-word.c
src/libsystemd/sd-network/sd-network.c
src/resolve/resolved-link.c
src/shared/bus-unit-util.c
src/shared/condition.c
src/shared/nsflags.c
src/systemctl/systemctl.c

index d6c12284637604a4a052d68d3f9933a63ec88988..dbe64a9a58eff1765dd5285bba72806b04c2f9d5 100644 (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)
index f8e18f23fdd49e84e142e2f99b272d209edc1292..0d8d99c56d5c85281d6ee6a3507742060e57db83 100644 (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;
index 13e1f91192ecdf2797ea69ee6e9bceba3b333160..e7e5c5f5a7b36391617efa3f640e154aec55335d 100644 (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;
                 }
         }
 
index 35e2c8f18e619b7eabe426325321e1fb7ec97266..4f66497f3a9f60894eaf9c483227acf5b0adda40 100644 (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);
index 8bd6a51a99b6aaece77953a13829eb7732f8e936..525e65aedfef6c610f761bc04185b0c34c738def 100644 (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;
 
index 8fcbe97ba78b36eb49454f953c7f6a8703e57ccb..911779a28f263880b09d07c7670d46cbe7981080 100644 (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;
index af5b18c0ed15fafbeb9b47b7b3c3578a8189a023..8a9a47a88e5ef2d20899f969e272a0f76f93229f 100644 (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;