sd-device: use extract_first_word()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-07-29 12:09:08 +02:00
parent ae7ef63f21
commit 87a4d416e5
1 changed files with 20 additions and 21 deletions

View File

@ -316,34 +316,33 @@ static int device_amend(sd_device *device, const char *key, const char *value) {
if (r < 0)
return log_device_debug_errno(device, r, "sd-device: Failed to set SEQNUM to '%s': %m", value);
} else if (streq(key, "DEVLINKS")) {
const char *word, *state;
size_t l;
for (const char *p = value;;) {
_cleanup_free_ char *word = NULL;
FOREACH_WORD(word, l, value, state) {
char devlink[l + 1];
strncpy(devlink, word, l);
devlink[l] = '\0';
r = device_add_devlink(device, devlink);
r = extract_first_word(&p, &word, NULL, 0);
if (r < 0)
return log_device_debug_errno(device, r, "sd-device: Failed to add devlink '%s': %m", devlink);
return r;
if (r == 0)
break;
r = device_add_devlink(device, word);
if (r < 0)
return log_device_debug_errno(device, r, "sd-device: Failed to add devlink '%s': %m", word);
}
} else if (STR_IN_SET(key, "TAGS", "CURRENT_TAGS")) {
const char *word, *state;
size_t l;
for (const char *p = value;;) {
_cleanup_free_ char *word = NULL;
FOREACH_WORD_SEPARATOR(word, l, value, ":", state) {
char tag[l + 1];
(void) strncpy(tag, word, l);
tag[l] = '\0';
r = device_add_tag(device, tag, streq(key, "CURRENT_TAGS"));
r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
if (r < 0)
return log_device_debug_errno(device, r, "sd-device: Failed to add tag '%s': %m", tag);
}
return r;
if (r == 0)
break;
r = device_add_tag(device, word, streq(key, "CURRENT_TAGS"));
if (r < 0)
return log_device_debug_errno(device, r, "sd-device: Failed to add tag '%s': %m", word);
}
} else {
r = device_add_property_internal(device, key, value);
if (r < 0)