<refsect2><title>udevadm test
<arg choice="opt"><replaceable>options</replaceable></arg>
- <arg><replaceable>devpath</replaceable></arg>
+ <arg choice="opt"><replaceable>devpath</replaceable>|<replaceable>file</replaceable>|<replaceable>unit</replaceable></arg>
</title>
<para>Simulate a udev event run for the given device, and print debug output.</para>
<variablelist>
<refsect2><title>udevadm test-builtin
<arg choice="opt"><replaceable>options</replaceable></arg>
<arg><replaceable>command</replaceable></arg>
- <arg><replaceable>devpath</replaceable></arg>
+ <arg choice="opt"><replaceable>devpath</replaceable>|<replaceable>file</replaceable>|<replaceable>unit</replaceable></arg>
</title>
<para>Run a built-in command <replaceable>COMMAND</replaceable>
for device <replaceable>DEVPATH</replaceable>, and print debug
}
int find_device(const char *id, const char *prefix, sd_device **ret) {
- _cleanup_free_ char *path = NULL;
- int r;
-
assert(id);
assert(ret);
- if (prefix) {
- if (!path_startswith(id, prefix)) {
- id = path = path_join(prefix, id);
- if (!path)
- return -ENOMEM;
- }
- } else {
- /* In cases where the argument is generic (no prefix specified),
- * check if the argument looks like a device unit name. */
- r = find_device_from_unit(id, ret);
- if (r >= 0)
- return r;
+ if (find_device_from_path(id, ret) >= 0)
+ return 0;
+
+ if (prefix && !path_startswith(id, prefix)) {
+ _cleanup_free_ char *path = NULL;
+
+ path = path_join(prefix, id);
+ if (!path)
+ return -ENOMEM;
+
+ if (find_device_from_path(path, ret) >= 0)
+ return 0;
}
- return find_device_from_path(id, ret);
+ /* Check if the argument looks like a device unit name. */
+ return find_device_from_unit(id, ret);
}
int find_device_with_action(const char *id, sd_device_action_t action, sd_device **ret) {
- _cleanup_free_ char *path = NULL;
+ _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
+ int r;
assert(id);
assert(ret);
assert(action >= 0 && action < _SD_DEVICE_ACTION_MAX);
- if (!path_startswith(id, "/sys")) {
- path = path_join("/sys", id);
- if (!path)
- return -ENOMEM;
- id = path;
- }
+ r = find_device(id, "/sys", &dev);
+ if (r < 0)
+ return r;
+
+ r = device_read_uevent_file(dev);
+ if (r < 0)
+ return r;
+
+ r = device_set_action(dev, action);
+ if (r < 0)
+ return r;
- return device_new_from_synthetic_event(ret, id, device_action_to_string(action));
+ *ret = TAKE_PTR(dev);
+ return 0;
}
int parse_device_action(const char *str, sd_device_action_t *action) {