summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-04-10 12:35:36 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-04-10 21:31:59 +0200
commitbd062910c844a3aa823e1651436d694266c248b1 (patch)
tree037928c0ce7fefa2c071e3a1b41bc41ec97cbdc1
parentc863dc05881fd5afbc3c7ce700980354530cee8e (diff)
downloadsystemd-bd062910c844a3aa823e1651436d694266c248b1.tar.gz
systemd-bd062910c844a3aa823e1651436d694266c248b1.tar.bz2
systemd-bd062910c844a3aa823e1651436d694266c248b1.zip
Move utility function to query unit state from systemctl to shared/
-rw-r--r--src/shared/bus-unit-util.c26
-rw-r--r--src/shared/bus-unit-util.h2
-rw-r--r--src/systemctl/systemctl.c18
3 files changed, 31 insertions, 15 deletions
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
index a9c17d29e2..24efd48ce7 100644
--- a/src/shared/bus-unit-util.c
+++ b/src/shared/bus-unit-util.c
@@ -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;
+}
diff --git a/src/shared/bus-unit-util.h b/src/shared/bus-unit-util.h
index 514e6edb76..704c526f3f 100644
--- a/src/shared/bus-unit-util.h
+++ b/src/shared/bus-unit-util.h
@@ -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);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 16a28edaa2..9f63bbc77e 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -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");
}