summaryrefslogtreecommitdiff
path: root/src/udev/udevadm-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-08-17 22:46:32 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-08-17 23:22:26 +0900
commitd1429d8f788c9028cff65d8c552872fd59ecc34a (patch)
treee9b889e526a1a7f2a10f6310dc6f5f850f23382e /src/udev/udevadm-util.c
parent29278aa41d93bfadd1559c66f569c81ba5187244 (diff)
downloadsystemd-d1429d8f788c9028cff65d8c552872fd59ecc34a.tar.gz
udevadm: introduce find_device_with_action() helper function
Diffstat (limited to 'src/udev/udevadm-util.c')
-rw-r--r--src/udev/udevadm-util.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/udev/udevadm-util.c b/src/udev/udevadm-util.c
index 10191d88ba..6be0e73560 100644
--- a/src/udev/udevadm-util.c
+++ b/src/udev/udevadm-util.c
@@ -93,3 +93,20 @@ int find_device(const char *id, const char *prefix, sd_device **ret) {
return find_device_from_path(id, ret);
}
+
+int find_device_with_action(const char *id, sd_device_action_t action, sd_device **ret) {
+ _cleanup_free_ char *path = NULL;
+
+ 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;
+ }
+
+ return device_new_from_synthetic_event(ret, id, device_action_to_string(action));
+}