summaryrefslogtreecommitdiffstats
path: root/src/shared/udev-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-08-31 15:30:17 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-08-31 16:12:46 +0200
commitf81b3e90e46a4a5fc0be57fe67934f23f3bb959b (patch)
tree8129c53716351e91b271c6e5e61fe538574fa2f3 /src/shared/udev-util.c
parenthashmap: add comment explaining that set_fnmatch() handles fnmatch() errors a... (diff)
downloadsystemd-f81b3e90e46a4a5fc0be57fe67934f23f3bb959b.tar.xz
systemd-f81b3e90e46a4a5fc0be57fe67934f23f3bb959b.zip
udev-util: replace device_new_from_dev_path() with sd_device_new_from_devname()
Diffstat (limited to 'src/shared/udev-util.c')
-rw-r--r--src/shared/udev-util.c35
1 files changed, 6 insertions, 29 deletions
diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c
index 3c1a674f57..e47c44f7a8 100644
--- a/src/shared/udev-util.c
+++ b/src/shared/udev-util.c
@@ -123,29 +123,6 @@ int udev_parse_config_full(
return 0;
}
-/* Note that if -ENOENT is returned, it will be logged at debug level rather than error,
- * because it's an expected, common occurrence that the caller will handle with a fallback */
-static int device_new_from_dev_path(const char *devlink, sd_device **ret_device) {
- struct stat st;
- int r;
-
- assert(devlink);
-
- if (stat(devlink, &st) < 0)
- return log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR, errno,
- "Failed to stat() %s: %m", devlink);
-
- if (!S_ISBLK(st.st_mode))
- return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK),
- "%s does not point to a block device: %m", devlink);
-
- r = sd_device_new_from_stat_rdev(ret_device, &st);
- if (r < 0)
- return log_error_errno(r, "Failed to initialize device from %s: %m", devlink);
-
- return 0;
-}
-
struct DeviceMonitorData {
const char *sysname;
const char *devlink;
@@ -225,9 +202,9 @@ static int device_wait_for_initialization_internal(
/* Devlink might already exist, if it does get the device to use the sysname filtering */
if (!device && devlink) {
- r = device_new_from_dev_path(devlink, &device);
- if (r < 0 && r != -ENOENT)
- return r;
+ r = sd_device_new_from_devname(&device, devlink);
+ if (r < 0 && !ERRNO_IS_DEVICE_ABSENT(r))
+ return log_error_errno(r, "Failed to create sd-device object from %s: %m", devlink);
}
if (device) {
@@ -282,9 +259,9 @@ static int device_wait_for_initialization_internal(
/* Check again, maybe things changed. Udev will re-read the db if the device wasn't initialized
* yet. */
if (!device && devlink) {
- r = device_new_from_dev_path(devlink, &device);
- if (r < 0 && r != -ENOENT)
- return r;
+ r = sd_device_new_from_devname(&device, devlink);
+ if (r < 0 && !ERRNO_IS_DEVICE_ABSENT(r))
+ return log_error_errno(r, "Failed to create sd-device object from %s: %m", devlink);
}
if (device && sd_device_get_is_initialized(device) > 0) {
if (ret)