udevadm: do not try to find device unit when a path like string is provided

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
---
This commit is contained in:
Yu Watanabe
2022-09-30 02:05:09 +09:00
parent 957dfcc96d
commit 4273a041f1
+4
View 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);
}