]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: split out core/manager-dump.[ch]
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 1 Jun 2021 13:25:44 +0000 (15:25 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 2 Jun 2021 07:22:08 +0000 (09:22 +0200)
This is a fairly specialized topic, let's create a separate file for it.

src/core/dbus-manager.c
src/core/execute.c
src/core/fuzz-unit-file.c
src/core/main.c
src/core/manager-dump.c [new file with mode: 0644]
src/core/manager-dump.h [new file with mode: 0644]
src/core/manager.c
src/core/manager.h
src/core/meson.build
src/test/test-engine.c

index 128d7778f55e8249aa915dc859483f064a9f2475..68a108742a3d58145651d9a63ef6f6cd2b954a84 100644 (file)
@@ -26,6 +26,7 @@
 #include "fs-util.h"
 #include "install.h"
 #include "log.h"
+#include "manager-dump.h"
 #include "os-util.h"
 #include "parse-util.h"
 #include "path-util.h"
index 3d750ee06ea537c58ca0b2836c0f7f5524fceedf..5c30d0bcbe64453ecdc837b308b60366cd3f49f0 100644 (file)
@@ -64,6 +64,7 @@
 #include "log.h"
 #include "macro.h"
 #include "manager.h"
+#include "manager-dump.h"
 #include "memory-util.h"
 #include "missing_fs.h"
 #include "mkdir.h"
index 311ffcecc1c1694b5cfdc9245bb5b10b4ff1311a..aef29f4cf71c6becea7f1e2c902bddfdc460dae9 100644 (file)
@@ -6,6 +6,7 @@
 #include "fuzz.h"
 #include "install.h"
 #include "load-fragment.h"
+#include "manager-dump.h"
 #include "string-util.h"
 #include "unit-serialize.h"
 #include "utf8.h"
index 1336be494aa0fe531e4d0f7e59084e378492d6fa..906c1482d738701ad594c22a55044a55846cacfe 100644 (file)
@@ -54,6 +54,7 @@
 #include "loopback-setup.h"
 #include "machine-id-setup.h"
 #include "manager.h"
+#include "manager-dump.h"
 #include "mkdir.h"
 #include "mount-setup.h"
 #include "os-util.h"
@@ -2500,16 +2501,6 @@ static int initialize_security(
         return 0;
 }
 
-static void test_summary(Manager *m) {
-        assert(m);
-
-        printf("-> By units:\n");
-        manager_dump_units(m, stdout, "\t");
-
-        printf("-> By jobs:\n");
-        manager_dump_jobs(m, stdout, "\t");
-}
-
 static int collect_fds(FDSet **ret_fds, const char **ret_error_message) {
         int r;
 
@@ -2882,7 +2873,7 @@ int main(int argc, char *argv[]) {
                  format_timespan(timespan, sizeof(timespan), after_startup - before_startup, 100 * USEC_PER_MSEC));
 
         if (arg_action == ACTION_TEST) {
-                test_summary(m);
+                manager_test_summary(m);
                 retval = EXIT_SUCCESS;
                 goto finish;
         }
diff --git a/src/core/manager-dump.c b/src/core/manager-dump.c
new file mode 100644 (file)
index 0000000..850ee36
--- /dev/null
@@ -0,0 +1,85 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "fd-util.h"
+#include "fileio.h"
+#include "hashmap.h"
+#include "manager-dump.h"
+#include "unit-serialize.h"
+
+void manager_dump_jobs(Manager *s, FILE *f, const char *prefix) {
+        Job *j;
+
+        assert(s);
+        assert(f);
+
+        HASHMAP_FOREACH(j, s->jobs)
+                job_dump(j, f, prefix);
+}
+
+void manager_dump_units(Manager *s, FILE *f, const char *prefix) {
+        Unit *u;
+        const char *t;
+
+        assert(s);
+        assert(f);
+
+        HASHMAP_FOREACH_KEY(u, t, s->units)
+                if (u->id == t)
+                        unit_dump(u, f, prefix);
+}
+
+void manager_dump(Manager *m, FILE *f, const char *prefix) {
+        assert(m);
+        assert(f);
+
+        for (ManagerTimestamp q = 0; q < _MANAGER_TIMESTAMP_MAX; q++) {
+                const dual_timestamp *t = m->timestamps + q;
+                char buf[CONST_MAX(FORMAT_TIMESPAN_MAX, FORMAT_TIMESTAMP_MAX)];
+
+                if (dual_timestamp_is_set(t))
+                        fprintf(f, "%sTimestamp %s: %s\n",
+                                strempty(prefix),
+                                manager_timestamp_to_string(q),
+                                timestamp_is_set(t->realtime) ? format_timestamp(buf, sizeof buf, t->realtime) :
+                                                                format_timespan(buf, sizeof buf, t->monotonic, 1));
+        }
+
+        manager_dump_units(m, f, prefix);
+        manager_dump_jobs(m, f, prefix);
+}
+
+int manager_get_dump_string(Manager *m, char **ret) {
+        _cleanup_free_ char *dump = NULL;
+        _cleanup_fclose_ FILE *f = NULL;
+        size_t size;
+        int r;
+
+        assert(m);
+        assert(ret);
+
+        f = open_memstream_unlocked(&dump, &size);
+        if (!f)
+                return -errno;
+
+        manager_dump(m, f, NULL);
+
+        r = fflush_and_check(f);
+        if (r < 0)
+                return r;
+
+        f = safe_fclose(f);
+
+        *ret = TAKE_PTR(dump);
+
+        return 0;
+}
+
+void manager_test_summary(Manager *m) {
+        assert(m);
+
+        printf("-> By units:\n");
+        manager_dump_units(m, stdout, "\t");
+
+        printf("-> By jobs:\n");
+        manager_dump_jobs(m, stdout, "\t");
+}
diff --git a/src/core/manager-dump.h b/src/core/manager-dump.h
new file mode 100644 (file)
index 0000000..317a4b6
--- /dev/null
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <stdio.h>
+
+#include "manager.h"
+
+void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
+void manager_dump_units(Manager *s, FILE *f, const char *prefix);
+void manager_dump(Manager *s, FILE *f, const char *prefix);
+int manager_get_dump_string(Manager *m, char **ret);
+void manager_test_summary(Manager *m);
index d96280667a67bd202331fdc278fbc7ee62623b36..dd6e7693d099181444cc9bd4e93e4965531b8180 100644 (file)
@@ -55,6 +55,7 @@
 #include "log.h"
 #include "macro.h"
 #include "manager.h"
+#include "manager-dump.h"
 #include "memory-util.h"
 #include "mkdir.h"
 #include "parse-util.h"
@@ -2154,74 +2155,6 @@ int manager_load_startable_unit_or_warn(
         return 0;
 }
 
-void manager_dump_jobs(Manager *s, FILE *f, const char *prefix) {
-        Job *j;
-
-        assert(s);
-        assert(f);
-
-        HASHMAP_FOREACH(j, s->jobs)
-                job_dump(j, f, prefix);
-}
-
-void manager_dump_units(Manager *s, FILE *f, const char *prefix) {
-        Unit *u;
-        const char *t;
-
-        assert(s);
-        assert(f);
-
-        HASHMAP_FOREACH_KEY(u, t, s->units)
-                if (u->id == t)
-                        unit_dump(u, f, prefix);
-}
-
-void manager_dump(Manager *m, FILE *f, const char *prefix) {
-        assert(m);
-        assert(f);
-
-        for (ManagerTimestamp q = 0; q < _MANAGER_TIMESTAMP_MAX; q++) {
-                const dual_timestamp *t = m->timestamps + q;
-                char buf[CONST_MAX(FORMAT_TIMESPAN_MAX, FORMAT_TIMESTAMP_MAX)];
-
-                if (dual_timestamp_is_set(t))
-                        fprintf(f, "%sTimestamp %s: %s\n",
-                                strempty(prefix),
-                                manager_timestamp_to_string(q),
-                                timestamp_is_set(t->realtime) ? format_timestamp(buf, sizeof buf, t->realtime) :
-                                                                format_timespan(buf, sizeof buf, t->monotonic, 1));
-        }
-
-        manager_dump_units(m, f, prefix);
-        manager_dump_jobs(m, f, prefix);
-}
-
-int manager_get_dump_string(Manager *m, char **ret) {
-        _cleanup_free_ char *dump = NULL;
-        _cleanup_fclose_ FILE *f = NULL;
-        size_t size;
-        int r;
-
-        assert(m);
-        assert(ret);
-
-        f = open_memstream_unlocked(&dump, &size);
-        if (!f)
-                return -errno;
-
-        manager_dump(m, f, NULL);
-
-        r = fflush_and_check(f);
-        if (r < 0)
-                return r;
-
-        f = safe_fclose(f);
-
-        *ret = TAKE_PTR(dump);
-
-        return 0;
-}
-
 void manager_clear_jobs(Manager *m) {
         Job *j;
 
index c4d4b2c375bd7261c2b46e860bea601c051ffa7a..b3e7c68e6ddd0bff0021baee7dd8b111a15f59cf 100644 (file)
@@ -485,11 +485,6 @@ int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode
 int manager_add_job_by_name_and_warn(Manager *m, JobType type, const char *name, JobMode mode, Set *affected_jobs,  Job **ret);
 int manager_propagate_reload(Manager *m, Unit *unit, JobMode mode, sd_bus_error *e);
 
-void manager_dump_units(Manager *s, FILE *f, const char *prefix);
-void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
-void manager_dump(Manager *s, FILE *f, const char *prefix);
-int manager_get_dump_string(Manager *m, char **ret);
-
 void manager_clear_jobs(Manager *m);
 
 void manager_unwatch_pid(Manager *m, pid_t pid);
index 06f0e8b5db3d0befe98c48d285ea3d38c4c6987d..e696d2772716d522310ddee1b8f68ea3a534fb12 100644 (file)
@@ -85,6 +85,8 @@ libcore_sources = '''
         locale-setup.h
         manager.c
         manager.h
+        manager-dump.c
+        manager-dump.h
         mount.c
         mount.h
         namespace.c
index 1039709b892ea8570ce284f823d345c895d716b3..6dc16193d3768fb79ab0cb5b9721f9bf94c54dcb 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "bus-util.h"
 #include "manager.h"
+#include "manager-dump.h"
 #include "rm-rf.h"
 #include "service.h"
 #include "special.h"