summaryrefslogtreecommitdiff
path: root/src/udev
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-04-07 03:31:01 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-04-08 03:38:19 +0900
commit733b7bfd79a9bf7c46e8930ca5f235507aeed6fc (patch)
tree150c8c7d109f1dcaca99fc20b1310b2f4d2a5645 /src/udev
parentf17af9c927636fdd4275eabf129d6bfa3367e1e9 (diff)
downloadsystemd-733b7bfd79a9bf7c46e8930ca5f235507aeed6fc.tar.gz
udev-rules: replace ingrowing word extractor with extract_first_word()
No functional change, just refactoring.
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/udev-rules.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index b410216396..58c5c81574 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;
}