diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-09-09 17:43:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-09 17:43:38 +0200 |
commit | 12ce0f41735e3d179c41deee99d9abe8aae52527 (patch) | |
tree | 13ba019fd7e4232da90de24f9ee36f6a669b4833 /src/libsystemd/sd-device | |
parent | Merge pull request #16972 from wusto/ambient-and-keep-caps-corrections (diff) | |
parent | Rename strv_split_extract() to strv_split_full() (diff) | |
download | systemd-12ce0f41735e3d179c41deee99d9abe8aae52527.tar.xz systemd-12ce0f41735e3d179c41deee99d9abe8aae52527.zip |
Merge pull request #16635 from keszybz/do-not-for-each-word
Drop FOREACH_WORD
Diffstat (limited to 'src/libsystemd/sd-device')
-rw-r--r-- | src/libsystemd/sd-device/device-private.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 44d1fd9839..dc16d555a1 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -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 = extract_first_word(&p, &word, NULL, 0); + if (r < 0) + return r; + if (r == 0) + break; - r = device_add_devlink(device, devlink); + r = device_add_devlink(device, word); if (r < 0) - return log_device_debug_errno(device, r, "sd-device: Failed to add devlink '%s': %m", devlink); + 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; - - FOREACH_WORD_SEPARATOR(word, l, value, ":", state) { - char tag[l + 1]; + for (const char *p = value;;) { + _cleanup_free_ char *word = NULL; - (void) strncpy(tag, word, l); - tag[l] = '\0'; + r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS); + if (r < 0) + return r; + if (r == 0) + break; - r = device_add_tag(device, tag, streq(key, "CURRENT_TAGS")); + 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", tag); + 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) |