udev-rules: replace ingrowing word extractor with extract_first_word()
No functional change, just refactoring.
This commit is contained in:
+14
-13
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user