]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm: replace find_device_from_path() with sd_device_new_from_path()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 27 Aug 2022 20:52:12 +0000 (05:52 +0900)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Sun, 28 Aug 2022 08:10:22 +0000 (08:10 +0000)
src/udev/udevadm-util.c

index 52a726709af1176fef14e5f27f559f8f26a49ead..4081976ca314b2033fc9c002e3991e5fc85168a0 100644 (file)
 #include "udevadm-util.h"
 #include "unit-name.h"
 
-static int find_device_from_path(const char *path, sd_device **ret) {
-        if (path_startswith(path, "/sys/"))
-                return sd_device_new_from_syspath(ret, path);
-
-        if (path_startswith(path, "/dev/")) {
-                struct stat st;
-
-                if (stat(path, &st) < 0)
-                        return -errno;
-
-                return sd_device_new_from_stat_rdev(ret, &st);
-        }
-
-        return -EINVAL;
-}
-
 static int find_device_from_unit(const char *unit_name, sd_device **ret) {
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
@@ -48,7 +32,7 @@ static int find_device_from_unit(const char *unit_name, sd_device **ret) {
                 if (r < 0)
                         return log_debug_errno(r, "Failed to convert \"%s\" to a device path: %m", unit_name);
 
-                return find_device_from_path(path, ret);
+                return sd_device_new_from_path(ret, path);
         }
 
         unit_path = unit_dbus_path_from_name(unit_name);
@@ -74,7 +58,7 @@ int find_device(const char *id, const char *prefix, sd_device **ret) {
         assert(id);
         assert(ret);
 
-        if (find_device_from_path(id, ret) >= 0)
+        if (sd_device_new_from_path(ret, id) >= 0)
                 return 0;
 
         if (prefix && !path_startswith(id, prefix)) {
@@ -84,7 +68,7 @@ int find_device(const char *id, const char *prefix, sd_device **ret) {
                 if (!path)
                         return -ENOMEM;
 
-                if (find_device_from_path(path, ret) >= 0)
+                if (sd_device_new_from_path(ret, path) >= 0)
                         return 0;
         }