diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-08-17 15:46:32 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-08-17 16:22:26 +0200 |
commit | d1429d8f788c9028cff65d8c552872fd59ecc34a (patch) | |
tree | e9b889e526a1a7f2a10f6310dc6f5f850f23382e /src/udev/udevadm-util.c | |
parent | Merge pull request #20281 from bluca/ext_release_naming (diff) | |
download | systemd-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.c | 17 |
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)); +} |