summaryrefslogtreecommitdiffstats
path: root/src/udev/udevadm-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-08-17 15:46:32 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-08-17 16:22:26 +0200
commitd1429d8f788c9028cff65d8c552872fd59ecc34a (patch)
treee9b889e526a1a7f2a10f6310dc6f5f850f23382e /src/udev/udevadm-util.c
parentMerge pull request #20281 from bluca/ext_release_naming (diff)
downloadsystemd-d1429d8f788c9028cff65d8c552872fd59ecc34a.tar.xz
systemd-d1429d8f788c9028cff65d8c552872fd59ecc34a.zip
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));
+}