path = prefix_roota(syspath, sysattr);
r = lstat(path, &statbuf);
if (r < 0) {
+ int k;
+
/* remember that we could not access the sysattr */
- r = device_cache_sysattr_value(device, sysattr, NULL);
- if (r < 0)
- return r;
+ k = device_cache_sysattr_value(device, sysattr, NULL);
+ if (k < 0)
+ log_device_debug_errno(device, k,
+ "sd-device: failed to cache attribute '%s' with NULL, ignoring: %m",
+ sysattr);
- return -ENOENT;
+ return r;
} else if (S_ISLNK(statbuf.st_mode)) {
/* Some core links return only the last element of the target path,
* these are just values, the paths should not be exposed. */
delete_trailing_chars(value, "\n");
}
+ /* Unfortunately, we need to return 'const char*' instead of 'char*'. Hence, failure in caching
+ * sysattr value is critical unlike the other places. */
r = device_cache_sysattr_value(device, sysattr, value);
- if (r < 0)
- return r;
-
- if (ret_value)
+ if (r < 0) {
+ log_device_debug_errno(device, r,
+ "sd-device: failed to cache attribute '%s' with '%s'%s: %m",
+ sysattr, value, ret_value ? "" : ", ignoring");
+ if (ret_value)
+ return r;
+ } else if (ret_value)
*ret_value = TAKE_PTR(value);
return 0;
r = device_cache_sysattr_value(device, sysattr, value);
if (r < 0)
- return r;
- TAKE_PTR(value);
+ log_device_debug_errno(device, r,
+ "sd-device: failed to cache attribute '%s' with '%s', ignoring: %m",
+ sysattr, value);
+ else
+ TAKE_PTR(value);
return 0;
}
#include "device-internal.h"
#include "device-private.h"
#include "device-util.h"
+#include "errno-util.h"
#include "hashmap.h"
#include "nulstr-util.h"
#include "string-util.h"
}
r = sd_device_get_sysattr_value(d, "name_assign_type", &val);
- assert_se(r >= 0 || IN_SET(r, -ENOENT, -EINVAL));
+ assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || IN_SET(r, -ENOENT, -EINVAL));
r = sd_device_get_property_value(d, "ID_NET_DRIVER", &val);
assert_se(r >= 0 || r == -ENOENT);
#include "device-private.h"
#include "device-util.h"
#include "env-file.h"
+#include "errno-util.h"
#include "escape.h"
#include "fd-util.h"
#include "log.h"
if (read_value) {
r = sd_device_get_sysattr_value(dev, attr, &val);
- if (r < 0 && r != -ENOENT)
+ if (r < 0 && !ERRNO_IS_PRIVILEGE(r) && r != -ENOENT)
return r;
- if (r == -ENOENT)
- result[0] = '\0';
- else
+ if (r >= 0)
strscpy(result, maxsize, val);
+ else
+ result[0] = '\0';
log_debug("value '[%s/%s]%s' is '%s'", subsys, sysname, attr, result);
} else {
r = sd_device_get_syspath(dev, &val);