From: Yu Watanabe Date: Thu, 6 Apr 2023 18:31:01 +0000 (+0900) Subject: udev-rules: replace ingrowing word extractor with extract_first_word() X-Git-Tag: v254-rc1~761^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=733b7bfd79a9bf7c46e8930ca5f235507aeed6fc;p=thirdparty%2Fsystemd.git udev-rules: replace ingrowing word extractor with extract_first_word() No functional change, just refactoring. --- diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index b410216396e..58c5c815741 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -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; }