summaryrefslogtreecommitdiffstats
path: root/src/udev/udevadm-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-08-29 10:28:05 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-10-16 20:31:20 +0200
commit13aca847695f49afeb93367ecdad76035fa6c139 (patch)
tree872ea8199baa1d230c1a9a3bdf93d3d291ae2b97 /src/udev/udevadm-util.c
parentudevadm-monitor: replace udev_monitor by sd_device_monitor (diff)
downloadsystemd-13aca847695f49afeb93367ecdad76035fa6c139.tar.xz
systemd-13aca847695f49afeb93367ecdad76035fa6c139.zip
udevadm-info,trigger: replace udev_device by sd_device
Diffstat (limited to 'src/udev/udevadm-util.c')
-rw-r--r--src/udev/udevadm-util.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/udev/udevadm-util.c b/src/udev/udevadm-util.c
index 867a6d94c2..6cff5ef84c 100644
--- a/src/udev/udevadm-util.c
+++ b/src/udev/udevadm-util.c
@@ -1,34 +1,30 @@
/* SPDX-License-Identifier: GPL-2.0+ */
+#include <errno.h>
+
+#include "device-private.h"
#include "path-util.h"
#include "string-util.h"
#include "udevadm-util.h"
-struct udev_device *find_device(const char *id,
- const char *prefix) {
-
+int find_device(const char *id, const char *prefix, sd_device **ret) {
assert(id);
+ assert(ret);
if (prefix && !startswith(id, prefix))
id = strjoina(prefix, id);
+ if (path_startswith(id, "/sys/"))
+ return sd_device_new_from_syspath(ret, id);
+
if (path_startswith(id, "/dev/")) {
- struct stat statbuf;
- char type;
-
- if (stat(id, &statbuf) < 0)
- return NULL;
-
- if (S_ISBLK(statbuf.st_mode))
- type = 'b';
- else if (S_ISCHR(statbuf.st_mode))
- type = 'c';
- else
- return NULL;
-
- return udev_device_new_from_devnum(NULL, type, statbuf.st_rdev);
- } else if (path_startswith(id, "/sys/"))
- return udev_device_new_from_syspath(NULL, id);
- else
- return NULL;
+ struct stat st;
+
+ if (stat(id, &st) < 0)
+ return -errno;
+
+ return device_new_from_stat_rdev(ret, &st);
+ }
+
+ return -EINVAL;
}