diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-06-04 22:52:02 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-06-07 13:36:19 +0200 |
commit | e5ca27b772267bd18109eb460fb6653a920e551e (patch) | |
tree | e0a23f07c1ae580171d27e82a5e7763d52ea4bdf /src/core/device.c | |
parent | core: split out device validation from device_found_node() (diff) | |
download | systemd-e5ca27b772267bd18109eb460fb6653a920e551e.tar.xz systemd-e5ca27b772267bd18109eb460fb6653a920e551e.zip |
udev: add helper udev_device_new_from_stat_rdev()
This is a simple wrapper around udev_device_new_from_devnum(), and uses
the data from a struct stat's .st_rdev field to derive the udev_device
object.
Diffstat (limited to 'src/core/device.c')
-rw-r--r-- | src/core/device.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/core/device.c b/src/core/device.c index e296ffa418..e92b982439 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -943,6 +943,7 @@ static bool device_supported(void) { static int validate_node(Manager *m, const char *node, struct udev_device **ret) { struct stat st; + int r; assert(m); assert(node); @@ -966,19 +967,15 @@ static int validate_node(Manager *m, const char *node, struct udev_device **ret) } else { _cleanup_(udev_device_unrefp) struct udev_device *dev = NULL; - if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode)) { - *ret = NULL; - return 0; /* bad! */ - } - - dev = udev_device_new_from_devnum(m->udev, S_ISBLK(st.st_mode) ? 'b' : 'c', st.st_rdev); - if (!dev) { - if (errno != ENOENT) - return log_error_errno(errno, "Failed to get udev device from devnum %u:%u: %m", major(st.st_rdev), minor(st.st_rdev)); - + r = udev_device_new_from_stat_rdev(m->udev, &st, &dev); + if (r == -ENOENT) { *ret = NULL; return 1; /* good! (though missing) */ - } + } else if (r == -ENOTTY) { + *ret = NULL; + return 0; /* bad! (not a device node but some other kind of file system node) */ + } else if (r < 0) + return log_error_errno(r, "Failed to get udev device from devnum %u:%u: %m", major(st.st_rdev), minor(st.st_rdev)); *ret = TAKE_PTR(dev); return 1; /* good! */ |