From: Yu Watanabe Date: Wed, 31 Aug 2022 13:30:17 +0000 (+0900) Subject: udev-util: replace device_new_from_dev_path() with sd_device_new_from_devname() X-Git-Tag: v252-rc1~285^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f81b3e90e46a4a5fc0be57fe67934f23f3bb959b;p=thirdparty%2Fsystemd.git udev-util: replace device_new_from_dev_path() with sd_device_new_from_devname() --- diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 3c1a674f579..e47c44f7a8f 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)