systemctl: list-dependencies: support --type= and --state=

Closes #25975
This commit is contained in:
Mike Yuan
2023-01-16 19:46:52 +08:00
parent 8e481bd292
commit 3729976944
5 changed files with 69 additions and 9 deletions
+29
View File
@@ -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,