sd-device: make device_get_cached_sysattr_value() distinguish if we have looked up the attribute
This commit is contained in:
@@ -1969,18 +1969,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);
|
||||
assert(key);
|
||||
|
||||
value = hashmap_get2(device->sysattr_values, _key, (void **) &key);
|
||||
if (!key)
|
||||
return -ENOENT;
|
||||
|
||||
if (_value)
|
||||
*_value = value;
|
||||
value = hashmap_get2(device->sysattr_values, key, (void **) &k);
|
||||
if (!k)
|
||||
return -ESTALE; /* 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;
|
||||
}
|
||||
|
||||
@@ -1988,7 +1989,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;
|
||||
|
||||
@@ -1996,20 +1997,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 != -ESTALE)
|
||||
return r;
|
||||
|
||||
r = sd_device_get_syspath(device, &syspath);
|
||||
if (r < 0)
|
||||
|
||||
Reference in New Issue
Block a user