]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-rules: replace ingrowing word extractor with extract_first_word()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 6 Apr 2023 18:31:01 +0000 (03:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 7 Apr 2023 18:38:19 +0000 (03:38 +0900)
No functional change, just refactoring.

src/udev/udev-rules.c

index b410216396e95ede6675220b7122d2a048b34565..58c5c81574115db037fabd6eb0894e9d757ad84b 100644 (file)
@@ -2541,7 +2541,7 @@ static int udev_rule_apply_token_to_event(
                 break;
         }
         case TK_A_DEVLINK: {
-                char buf[UDEV_PATH_SIZE], *p;
+                char buf[UDEV_PATH_SIZE];
                 bool truncated;
                 size_t count;
 
@@ -2573,19 +2573,22 @@ static int udev_rule_apply_token_to_event(
                                         "Replaced %zu character(s) from result of SYMLINK=\"%s\"",
                                         count, token->value);
 
-                p = skip_leading_chars(buf, NULL);
-                while (!isempty(p)) {
-                        char path[UDEV_PATH_SIZE], *next;
+                for (const char *p = buf;;) {
+                        _cleanup_free_ char *word = NULL, *path = NULL;
 
-                        next = strchr(p, ' ');
-                        if (next) {
-                                *next++ = '\0';
-                                next = skip_leading_chars(next, NULL);
+                        r = extract_first_word(&p, &word, NULL, EXTRACT_RETAIN_ESCAPE);
+                        if (r == -ENOMEM)
+                                return log_oom();
+                        if (r < 0) {
+                                log_warning_errno(r, "Failed to extract first path in SYMLINK=, ignoring: %m");
+                                break;
                         }
+                        if (r == 0)
+                                break;
 
-                        strscpyl_full(path, sizeof(path), &truncated, "/dev/", p, NULL);
-                        if (truncated)
-                                continue;
+                        path = path_join("/dev/", word);
+                        if (!path)
+                                return log_oom();
 
                         if (token->op == OP_REMOVE) {
                                 device_remove_devlink(dev, path);
@@ -2597,8 +2600,6 @@ static int udev_rule_apply_token_to_event(
 
                                 log_event_debug(dev, token, "Added SYMLINK '%s'", path);
                         }
-
-                        p = next;
                 }
                 break;
         }