sd-device: use extract_first_word()
This commit is contained in:
parent
ae7ef63f21
commit
87a4d416e5
|
@ -316,34 +316,33 @@ static int device_amend(sd_device *device, const char *key, const char *value) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_device_debug_errno(device, r, "sd-device: Failed to set SEQNUM to '%s': %m", value);
|
return log_device_debug_errno(device, r, "sd-device: Failed to set SEQNUM to '%s': %m", value);
|
||||||
} else if (streq(key, "DEVLINKS")) {
|
} else if (streq(key, "DEVLINKS")) {
|
||||||
const char *word, *state;
|
for (const char *p = value;;) {
|
||||||
size_t l;
|
_cleanup_free_ char *word = NULL;
|
||||||
|
|
||||||
FOREACH_WORD(word, l, value, state) {
|
r = extract_first_word(&p, &word, NULL, 0);
|
||||||
char devlink[l + 1];
|
|
||||||
|
|
||||||
strncpy(devlink, word, l);
|
|
||||||
devlink[l] = '\0';
|
|
||||||
|
|
||||||
r = device_add_devlink(device, devlink);
|
|
||||||
if (r < 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")) {
|
} else if (STR_IN_SET(key, "TAGS", "CURRENT_TAGS")) {
|
||||||
const char *word, *state;
|
for (const char *p = value;;) {
|
||||||
size_t l;
|
_cleanup_free_ char *word = NULL;
|
||||||
|
|
||||||
FOREACH_WORD_SEPARATOR(word, l, value, ":", state) {
|
r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||||
char tag[l + 1];
|
|
||||||
|
|
||||||
(void) strncpy(tag, word, l);
|
|
||||||
tag[l] = '\0';
|
|
||||||
|
|
||||||
r = device_add_tag(device, tag, streq(key, "CURRENT_TAGS"));
|
|
||||||
if (r < 0)
|
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 {
|
} else {
|
||||||
r = device_add_property_internal(device, key, value);
|
r = device_add_property_internal(device, key, value);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
|
Loading…
Reference in New Issue