diff options
author | Mike Yuan <me@yhndnzj.com> | 2023-01-13 09:52:29 +0100 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2023-01-16 12:46:52 +0100 |
commit | 372997694446f26ffdedc95a14278cd5b3d2b73d (patch) | |
tree | 769def8a2edd08531aa7c8aa78b94732b27dc4cf /src/systemctl/systemctl-util.c | |
parent | systemctl: list-dependencies: pass bool where appropriate (diff) | |
download | systemd-372997694446f26ffdedc95a14278cd5b3d2b73d.tar.xz systemd-372997694446f26ffdedc95a14278cd5b3d2b73d.zip |
systemctl: list-dependencies: support --type= and --state=
Closes #25975
Diffstat (limited to 'src/systemctl/systemctl-util.c')
-rw-r--r-- | src/systemctl/systemctl-util.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/systemctl/systemctl-util.c b/src/systemctl/systemctl-util.c index b333850bec..bcad65f8dc 100644 --- a/src/systemctl/systemctl-util.c +++ b/src/systemctl/systemctl-util.c @@ -122,6 +122,7 @@ int get_state_one_unit(sd_bus *bus, const char *unit, UnitActiveState *ret_activ UnitActiveState state; int r; + assert(bus); assert(unit); assert(ret_active_state); @@ -148,6 +149,34 @@ int get_state_one_unit(sd_bus *bus, const char *unit, UnitActiveState *ret_activ return 0; } +int get_sub_state_one_unit(sd_bus *bus, const char *unit, char **ret_sub_state) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_free_ char *sub_state = NULL, *dbus_path = NULL; + int r; + + assert(bus); + assert(unit); + assert(ret_sub_state); + + dbus_path = unit_dbus_path_from_name(unit); + if (!dbus_path) + return log_oom(); + + r = sd_bus_get_property_string( + bus, + "org.freedesktop.systemd1", + dbus_path, + "org.freedesktop.systemd1.Unit", + "SubState", + &error, + &sub_state); + if (r < 0) + return log_error_errno(r, "Failed to retrieve unit sub state: %s", bus_error_message(&error, r)); + + *ret_sub_state = TAKE_PTR(sub_state); + return 0; +} + int get_unit_list( sd_bus *bus, const char *machine, |