]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Move utility function to query unit state from systemctl to shared/
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 10 Apr 2018 10:35:36 +0000 (12:35 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 10 Apr 2018 19:31:59 +0000 (21:31 +0200)
src/shared/bus-unit-util.c
src/shared/bus-unit-util.h
src/systemctl/systemctl.c

index a9c17d29e2a0a25813539f179f661107a674b254..24efd48ce7c724b4707e354fb1892dbceb793667 100644 (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;
+}
index 514e6edb766de8385af20f6f124fe19219559f2b..704c526f3f479f3e34591281cc62a2fb428a456d 100644 (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);
index 16a28edaa22e19f61dbd8460a6db519c1a6b29f2..9f63bbc77e6e1a6073038dd3546fb0e8edafb527 100644 (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");
 }