1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-06 16:59:03 +03:00

Move utility function to query unit state from systemctl to shared/

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-04-10 12:35:36 +02:00
parent c863dc0588
commit bd062910c8
3 changed files with 31 additions and 15 deletions

View File

@ -2462,3 +2462,29 @@ finish:
return r;
}
int unit_load_state(sd_bus *bus, const char *name, char **load_state) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_free_ char *path = NULL;
int r;
path = unit_dbus_path_from_name(name);
if (!path)
return log_oom();
/* This function warns on it's own, because otherwise it'd be awkward to pass
* the dbus error message around. */
r = sd_bus_get_property_string(
bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Unit",
"LoadState",
&error,
load_state);
if (r < 0)
return log_error_errno(r, "Failed to get load state of %s: %s", name, bus_error_message(&error, r));
return 0;
}

View File

@ -57,3 +57,5 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(BusWaitForJobs*, bus_wait_for_jobs_free);
int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, unsigned *n_changes);
int unit_show_processes(sd_bus *bus, const char *unit, const char *cgroup_path, const char *prefix, unsigned n_columns, OutputFlags flags, sd_bus_error *error);
int unit_load_state(sd_bus *bus, const char *name, char **load_state);

View File

@ -2649,24 +2649,12 @@ static int get_state_one_unit(sd_bus *bus, const char *name, UnitActiveState *ac
}
static int unit_is_masked(sd_bus *bus, const char *name) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_free_ char *path = NULL, *load_state = NULL;
_cleanup_free_ char *load_state = NULL;
int r;
path = unit_dbus_path_from_name(name);
if (!path)
return log_oom();
r = sd_bus_get_property_string(
bus,
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Unit",
"LoadState",
&error,
&load_state);
r = unit_load_state(bus, name, &load_state);
if (r < 0)
return log_error_errno(r, "Failed to get load state of %s: %s", name, bus_error_message(&error, r));
return r;
return streq(load_state, "masked");
}