From: Yu Watanabe Date: Wed, 15 Sep 2021 06:21:44 +0000 (+0900) Subject: sd-device: make device_get_cached_sysattr_value() distinguish if we have looked up... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b94179add24abd5425a8d17fe2d24179e61f415a;p=thirdparty%2Fsystemd.git sd-device: make device_get_cached_sysattr_value() distinguish if we have looked up the attribute --- diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index b9268dfcd19..e06b6276dc6 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -1968,18 +1968,19 @@ static int device_cache_sysattr_value(sd_device *device, const char *key, char * return 0; } -static int device_get_cached_sysattr_value(sd_device *device, const char *_key, const char **_value) { - const char *key = NULL, *value; +static int device_get_cached_sysattr_value(sd_device *device, const char *key, const char **ret_value) { + const char *k = NULL, *value; assert(device); - assert(_key); - - value = hashmap_get2(device->sysattr_values, _key, (void **) &key); - if (!key) - return -ENOENT; + assert(key); - if (_value) - *_value = value; + value = hashmap_get2(device->sysattr_values, key, (void **) &k); + if (!k) + return -ENODATA; /* We have not read the attribute. */ + if (!value) + return -ENOENT; /* We have looked up the attribute before and it did not exist. */ + if (ret_value) + *ret_value = value; return 0; } @@ -1987,7 +1988,7 @@ static int device_get_cached_sysattr_value(sd_device *device, const char *_key, * with a NULL value in the cache, otherwise the returned string is stored */ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **ret_value) { _cleanup_free_ char *value = NULL; - const char *path, *syspath, *cached_value = NULL; + const char *path, *syspath; struct stat statbuf; int r; @@ -1995,20 +1996,9 @@ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, assert_return(sysattr, -EINVAL); /* look for possibly already cached result */ - r = device_get_cached_sysattr_value(device, sysattr, &cached_value); - if (r != -ENOENT) { - if (r < 0) - return r; - - if (!cached_value) - /* we looked up the sysattr before and it did not exist */ - return -ENOENT; - - if (ret_value) - *ret_value = cached_value; - - return 0; - } + r = device_get_cached_sysattr_value(device, sysattr, ret_value); + if (r != -ENODATA) + return r; r = sd_device_get_syspath(device, &syspath); if (r < 0)