]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm: do not try to find device unit when a path like string is provided
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 29 Sep 2022 17:03:32 +0000 (02:03 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 29 Sep 2022 17:05:09 +0000 (02:05 +0900)
Otherwise, we provide misleading error message.
Before:
---
$ udevadm info /sys/class/foo
Bad argument "/sys/class/foo", expected an absolute path in /dev/ or /sys/ or a unit name: Invalid argument
---
After:
---
$ udevadm info /sys/class/foo
Unknown device "/sys/class/foo": No such device
---

src/udev/udevadm-util.c

index 4081976ca314b2033fc9c002e3991e5fc85168a0..2447edad1929b68949a86b8d5a05eab397290150 100644 (file)
@@ -72,6 +72,10 @@ int find_device(const char *id, const char *prefix, sd_device **ret) {
                         return 0;
         }
 
+        /* if a path is provided, then it cannot be a unit name. Let's return earlier. */
+        if (is_path(id))
+                return -ENODEV;
+
         /* Check if the argument looks like a device unit name. */
         return find_device_from_unit(id, ret);
 }