summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-11-12 13:57:02 +0100
committerTom Gundersen <teg@jklm.no>2014-12-11 13:54:18 +0100
commitb67fca29af5f93066dc8bfb82bed71dfeea73639 (patch)
treeaf9f1090fbf6057fc52cf247911f48b6076d2e51
parent57be5a343314930451cf47578e51c792ee81c197 (diff)
sd-device: add sd_device_get_parent_with_susbystem_devtype
-rw-r--r--src/libsystemd/sd-device/sd-device.c32
-rw-r--r--src/systemd/sd-device.h1
2 files changed, 33 insertions, 0 deletions
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index 5964d46d3..51a75b302 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -701,3 +701,35 @@ _public_ int sd_device_get_devtype(sd_device *device, const char **devtype) {
return 0;
}
+
+_public_ int sd_device_get_parent_with_subsystem_devtype(sd_device *child, const char *subsystem, const char *devtype, sd_device **ret) {
+ sd_device *parent = NULL;
+ int r;
+
+ assert_return(child, -EINVAL);
+ assert_return(subsystem, -EINVAL);
+
+ r = sd_device_get_parent(child, &parent);
+ while (r >= 0) {
+ const char *parent_subsystem;
+ const char *parent_devtype;
+
+ (void)sd_device_get_subsystem(parent, &parent_subsystem);
+ if (streq_ptr(parent_subsystem, subsystem)) {
+ if (!devtype)
+ break;
+
+ (void)sd_device_get_devtype(parent, &parent_devtype);
+ if (streq_ptr(parent_devtype, devtype))
+ break;
+ }
+ r = sd_device_get_parent(parent, &parent);
+ }
+
+ if (r < 0)
+ return r;
+
+ *ret = parent;
+
+ return 0;
+}
diff --git a/src/systemd/sd-device.h b/src/systemd/sd-device.h
index 52146dfaa..9735fa38f 100644
--- a/src/systemd/sd-device.h
+++ b/src/systemd/sd-device.h
@@ -44,6 +44,7 @@ int sd_device_get_syspath(sd_device *device, const char **ret);
int sd_device_get_parent(sd_device *child, sd_device **ret);
int sd_device_get_subsystem(sd_device *device, const char **ret);
int sd_device_get_devtype(sd_device *device, const char **ret);
+int sd_device_get_parent_with_subsystem_devtype(sd_device *child, const char *subsystem, const char *devtype, sd_device **ret);
_SD_END_DECLARATIONS;