X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibelogind%2Fsd-device%2Fdevice-private.c;h=9788df769cfbf249e730da89838a26092974523b;hb=ead0b80f56cd4d4f0a9e654b271a8957251c0c35;hp=81b0b6dde68cfc3e0abd45ab3f2727f3e856fe6f;hpb=f48dd74a8d39b6074f820f904953f5cece03b9b0;p=elogind.git diff --git a/src/libelogind/sd-device/device-private.c b/src/libelogind/sd-device/device-private.c index 81b0b6dde..9788df769 100644 --- a/src/libelogind/sd-device/device-private.c +++ b/src/libelogind/sd-device/device-private.c @@ -366,7 +366,7 @@ static int device_set_devgid(sd_device *device, const char *gid) { return 0; } -static int device_ammend(sd_device *device, const char *key, const char *value) { +static int device_amend(sd_device *device, const char *key, const char *value) { int r; assert(device); @@ -419,32 +419,32 @@ static int device_ammend(sd_device *device, const char *key, const char *value) if (r < 0) return log_debug_errno(r, "sd-device: could not set devgid to '%s': %m", value); } else if (streq(key, "DEVLINKS")) { - char *devlinks, *next; + const char *word, *state; + size_t l; - devlinks = strdupa(value); + FOREACH_WORD(word, l, value, state) { + char devlink[l + 1]; - while ((next = strchr(devlinks, ' '))) { - next[0] = '\0'; + strncpy(devlink, word, l); + devlink[l] = '\0'; - r = device_add_devlink(device, devlinks); + r = device_add_devlink(device, devlink); if (r < 0) - return log_debug_errno(r, "sd-device: could not add devlink '%s': %m", devlinks); - - devlinks = next + 1; + return log_debug_errno(r, "sd-device: could not add devlink '%s': %m", devlink); } } else if (streq(key, "TAGS")) { - char *tags, *next; + const char *word, *state; + size_t l; - tags = strdupa(value); + FOREACH_WORD_SEPARATOR(word, l, value, ":", state) { + char tag[l + 1]; - while ((next = strchr(tags, ':'))) { - next[0] = '\0'; + (void)strncpy(tag, word, l); + tag[l] = '\0'; - r = device_add_tag(device, tags); + r = device_add_tag(device, tag); if (r < 0) - return log_debug_errno(r, "sd-device: could not add tag '%s': %m", tags); - - tags = next + 1; + return log_debug_errno(r, "sd-device: could not add tag '%s': %m", tag); } } else { r = device_add_property_internal(device, key, value); @@ -509,7 +509,7 @@ static int device_append(sd_device *device, char *key, const char **_major, cons return -EINVAL; } - r = device_ammend(device, key, value); + r = device_amend(device, key, value); if (r < 0) return r; } @@ -643,6 +643,9 @@ static int device_update_properties_bufs(sd_device *device) { assert(device); + if (!device->properties_buf_outdated) + return 0; + FOREACH_DEVICE_PROPERTY(device, prop, val) { size_t len = 0; @@ -679,11 +682,9 @@ int device_get_properties_nulstr(sd_device *device, const uint8_t **nulstr, size assert(nulstr); assert(len); - if (device->properties_buf_outdated) { - r = device_update_properties_bufs(device); - if (r < 0) - return r; - } + r = device_update_properties_bufs(device); + if (r < 0) + return r; *nulstr = device->properties_nulstr; *len = device->properties_nulstr_len;