From 57b7a260c20f58a5c5d9c1e1aacde50646863919 Mon Sep 17 00:00:00 2001 From: Felipe Sateler Date: Tue, 15 May 2018 14:17:34 -0400 Subject: [PATCH] core: undo the dependency inversion between unit.h and all unit types --- src/analyze/analyze-verify.c | 1 + src/core/all-units.h | 14 +++++++++ src/core/automount.h | 2 ++ src/core/dbus-scope.h | 2 +- src/core/dbus.c | 1 + src/core/device.h | 4 +++ src/core/dynamic-user.c | 1 + src/core/execute.c | 1 + src/core/load-fragment-gperf.gperf.m4 | 2 ++ src/core/load-fragment.c | 2 +- src/core/main.c | 1 + src/core/manager.c | 2 ++ src/core/manager.h | 1 + src/core/mount.c | 1 + src/core/mount.h | 3 ++ src/core/path.h | 2 ++ src/core/scope.h | 2 ++ src/core/service.h | 4 +++ src/core/slice.h | 4 +++ src/core/socket.h | 3 ++ src/core/swap.c | 1 + src/core/swap.h | 3 ++ src/core/target.h | 4 +++ src/core/timer.h | 3 ++ src/core/unit.c | 1 + src/core/unit.h | 43 +++++++-------------------- src/test/test-execute.c | 1 + src/test/test-path.c | 1 + src/test/test-sched-prio.c | 1 + src/test/test-unit-file.c | 1 + src/test/test-unit-name.c | 1 + src/test/test-watch-pid.c | 1 + 32 files changed, 79 insertions(+), 35 deletions(-) create mode 100644 src/core/all-units.h diff --git a/src/analyze/analyze-verify.c b/src/analyze/analyze-verify.c index 90c10f575a4..694ecc72879 100644 --- a/src/analyze/analyze-verify.c +++ b/src/analyze/analyze-verify.c @@ -8,6 +8,7 @@ #include #include "alloc-util.h" +#include "all-units.h" #include "analyze-verify.h" #include "bus-error.h" #include "bus-util.h" diff --git a/src/core/all-units.h b/src/core/all-units.h new file mode 100644 index 00000000000..ed8350ebe0d --- /dev/null +++ b/src/core/all-units.h @@ -0,0 +1,14 @@ +#pragma once + +#include "unit.h" + +#include "automount.h" +#include "device.h" +#include "path.h" +#include "scope.h" +#include "service.h" +#include "slice.h" +#include "socket.h" +#include "swap.h" +#include "target.h" +#include "timer.h" diff --git a/src/core/automount.h b/src/core/automount.h index f017b8c7ee7..bdadb554786 100644 --- a/src/core/automount.h +++ b/src/core/automount.h @@ -45,3 +45,5 @@ extern const UnitVTable automount_vtable; const char* automount_result_to_string(AutomountResult i) _const_; AutomountResult automount_result_from_string(const char *s) _pure_; + +DEFINE_CAST(AUTOMOUNT, Automount); diff --git a/src/core/dbus-scope.h b/src/core/dbus-scope.h index f055b70aac8..115886b134a 100644 --- a/src/core/dbus-scope.h +++ b/src/core/dbus-scope.h @@ -9,7 +9,7 @@ #include "sd-bus.h" -#include "unit.h" +#include "scope.h" extern const sd_bus_vtable bus_scope_vtable[]; diff --git a/src/core/dbus.c b/src/core/dbus.c index 47492835ee8..9e39d8ab7f1 100644 --- a/src/core/dbus.c +++ b/src/core/dbus.c @@ -30,6 +30,7 @@ #include "mkdir.h" #include "process-util.h" #include "selinux-access.h" +#include "service.h" #include "special.h" #include "string-util.h" #include "strv.h" diff --git a/src/core/device.h b/src/core/device.h index d52700b66f6..f188640c59b 100644 --- a/src/core/device.h +++ b/src/core/device.h @@ -7,6 +7,8 @@ Copyright 2010 Lennart Poettering ***/ +#include "unit.h" + typedef struct Device Device; typedef enum DeviceFound { @@ -37,3 +39,5 @@ extern const UnitVTable device_vtable; int device_found_node(Manager *m, const char *node, bool add, DeviceFound found, bool now); bool device_shall_be_bound_by(Unit *device, Unit *u); + +DEFINE_CAST(DEVICE, Device); diff --git a/src/core/dynamic-user.c b/src/core/dynamic-user.c index 1f4ed576d98..05ccc8c854e 100644 --- a/src/core/dynamic-user.c +++ b/src/core/dynamic-user.c @@ -17,6 +17,7 @@ #include "io-util.h" #include "parse-util.h" #include "random-util.h" +#include "socket-util.h" #include "stdio-util.h" #include "string-util.h" #include "user-util.h" diff --git a/src/core/execute.c b/src/core/execute.c index ecc7e8821a2..fca20c55678 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -86,6 +86,7 @@ #include "selinux-util.h" #include "signal-util.h" #include "smack-util.h" +#include "socket-util.h" #include "special.h" #include "stat-util.h" #include "string-table.h" diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4 index 5d90a7c0549..001837463b2 100644 --- a/src/core/load-fragment-gperf.gperf.m4 +++ b/src/core/load-fragment-gperf.gperf.m4 @@ -6,6 +6,8 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"") #include "conf-parser.h" #include "load-fragment.h" #include "missing.h" + +#include "all-units.h" %} struct ConfigPerfItem; %null_strings diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index a78039bb4fa..e17987bf070 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -20,6 +20,7 @@ #include "af-list.h" #include "alloc-util.h" +#include "all-units.h" #include "bus-error.h" #include "bus-internal.h" #include "bus-util.h" @@ -57,7 +58,6 @@ #include "strv.h" #include "unit-name.h" #include "unit-printf.h" -#include "unit.h" #include "user-util.h" #include "utf8.h" #include "web-util.h" diff --git a/src/core/main.c b/src/core/main.c index 201882ca95c..978434038e3 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -40,6 +40,7 @@ #include "def.h" #include "emergency-action.h" #include "env-util.h" +#include "exit-status.h" #include "fd-util.h" #include "fdset.h" #include "fileio.h" diff --git a/src/core/manager.c b/src/core/manager.c index 6412fee4764..a4cea85136f 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -28,6 +28,7 @@ #include "sd-path.h" #include "alloc-util.h" +#include "all-units.h" #include "audit-fd.h" #include "boot-timestamps.h" #include "bus-common-errors.h" @@ -65,6 +66,7 @@ #include "ratelimit.h" #include "rm-rf.h" #include "signal-util.h" +#include "socket-util.h" #include "special.h" #include "stat-util.h" #include "string-table.h" diff --git a/src/core/manager.h b/src/core/manager.h index 35a3a1eb400..f41cce1c09e 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -21,6 +21,7 @@ #include "ratelimit.h" struct libmnt_monitor; +typedef struct Unit Unit; /* Enforce upper limit how many names we allow */ #define MANAGER_MAX_NAMES 131072 /* 128K */ diff --git a/src/core/mount.c b/src/core/mount.c index 968ed104dac..d5463b76213 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -16,6 +16,7 @@ #include "alloc-util.h" #include "dbus-mount.h" +#include "device.h" #include "escape.h" #include "exit-status.h" #include "format-util.h" diff --git a/src/core/mount.h b/src/core/mount.h index 08a4cfe61f1..71dac128c22 100644 --- a/src/core/mount.h +++ b/src/core/mount.h @@ -11,6 +11,7 @@ typedef struct Mount Mount; #include "kill.h" #include "dynamic-user.h" +#include "unit.h" typedef enum MountExecCommand { MOUNT_EXEC_MOUNT, @@ -97,3 +98,5 @@ MountExecCommand mount_exec_command_from_string(const char *s) _pure_; const char* mount_result_to_string(MountResult i) _const_; MountResult mount_result_from_string(const char *s) _pure_; + +DEFINE_CAST(MOUNT, Mount); diff --git a/src/core/path.h b/src/core/path.h index ca7dac227d9..2aa2ca111f0 100644 --- a/src/core/path.h +++ b/src/core/path.h @@ -79,3 +79,5 @@ PathType path_type_from_string(const char *s) _pure_; const char* path_result_to_string(PathResult i) _const_; PathResult path_result_from_string(const char *s) _pure_; + +DEFINE_CAST(PATH, Path); diff --git a/src/core/scope.h b/src/core/scope.h index 6e314eeda3a..e74014119d7 100644 --- a/src/core/scope.h +++ b/src/core/scope.h @@ -46,3 +46,5 @@ int scope_abandon(Scope *s); const char* scope_result_to_string(ScopeResult i) _const_; ScopeResult scope_result_from_string(const char *s) _pure_; + +DEFINE_CAST(SCOPE, Scope); diff --git a/src/core/service.h b/src/core/service.h index 116d5d119fa..6d64f8e9e6f 100644 --- a/src/core/service.h +++ b/src/core/service.h @@ -14,6 +14,8 @@ typedef struct ServiceFDStore ServiceFDStore; #include "kill.h" #include "path.h" #include "ratelimit.h" +#include "socket.h" +#include "unit.h" typedef enum ServiceRestart { SERVICE_RESTART_NO, @@ -204,3 +206,5 @@ NotifyState notify_state_from_string(const char *s) _pure_; const char* service_result_to_string(ServiceResult i) _const_; ServiceResult service_result_from_string(const char *s) _pure_; + +DEFINE_CAST(SERVICE, Service); diff --git a/src/core/slice.h b/src/core/slice.h index 7d48fafa3ac..0ab479467ce 100644 --- a/src/core/slice.h +++ b/src/core/slice.h @@ -7,6 +7,8 @@ Copyright 2013 Lennart Poettering ***/ +#include "unit.h" + typedef struct Slice Slice; struct Slice { @@ -18,3 +20,5 @@ struct Slice { }; extern const UnitVTable slice_vtable; + +DEFINE_CAST(SLICE, Slice); diff --git a/src/core/socket.h b/src/core/socket.h index ce9452dbd69..8a9559d5c6d 100644 --- a/src/core/socket.h +++ b/src/core/socket.h @@ -13,6 +13,7 @@ typedef struct SocketPeer SocketPeer; #include "mount.h" #include "service.h" #include "socket-util.h" +#include "unit.h" typedef enum SocketExecCommand { SOCKET_EXEC_START_PRE, @@ -182,3 +183,5 @@ SocketResult socket_result_from_string(const char *s) _pure_; const char* socket_port_type_to_string(SocketPort *p) _pure_; SocketType socket_port_type_from_string(const char *p) _pure_; + +DEFINE_CAST(SOCKET, Socket); diff --git a/src/core/swap.c b/src/core/swap.c index 618a8d553dc..e75c9f2464f 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -14,6 +14,7 @@ #include "alloc-util.h" #include "dbus-swap.h" +#include "device.h" #include "escape.h" #include "exit-status.h" #include "fd-util.h" diff --git a/src/core/swap.h b/src/core/swap.h index ec29ccfa6e2..fdb14e667a3 100644 --- a/src/core/swap.h +++ b/src/core/swap.h @@ -9,6 +9,7 @@ ***/ #include "libudev.h" +#include "unit.h" typedef struct Swap Swap; @@ -95,3 +96,5 @@ SwapExecCommand swap_exec_command_from_string(const char *s) _pure_; const char* swap_result_to_string(SwapResult i) _const_; SwapResult swap_result_from_string(const char *s) _pure_; + +DEFINE_CAST(SWAP, Swap); diff --git a/src/core/target.h b/src/core/target.h index 2b099c2513a..4a2dea17ed6 100644 --- a/src/core/target.h +++ b/src/core/target.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once +#include "unit.h" + /*** This file is part of systemd. @@ -16,3 +18,5 @@ struct Target { }; extern const UnitVTable target_vtable; + +DEFINE_CAST(TARGET, Target); diff --git a/src/core/timer.h b/src/core/timer.h index 728afba9bda..0588a96ca24 100644 --- a/src/core/timer.h +++ b/src/core/timer.h @@ -10,6 +10,7 @@ typedef struct Timer Timer; #include "calendarspec.h" +#include "unit.h" typedef enum TimerBase { TIMER_ACTIVE, @@ -77,3 +78,5 @@ TimerBase timer_base_from_string(const char *s) _pure_; const char* timer_result_to_string(TimerResult i) _const_; TimerResult timer_result_from_string(const char *s) _pure_; + +DEFINE_CAST(TIMER, Timer); diff --git a/src/core/unit.c b/src/core/unit.c index 13e00a25c82..c7320240f7b 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -16,6 +16,7 @@ #include "sd-messages.h" #include "alloc-util.h" +#include "all-units.h" #include "bus-common-errors.h" #include "bus-util.h" #include "cgroup-util.h" diff --git a/src/core/unit.h b/src/core/unit.h index 26194ef35a0..767cd96aeb6 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -11,11 +11,6 @@ #include #include -typedef struct Unit Unit; -typedef struct UnitVTable UnitVTable; -typedef struct UnitRef UnitRef; -typedef struct UnitStatusMessageFormats UnitStatusMessageFormats; - #include "bpf-program.h" #include "condition.h" #include "emergency-action.h" @@ -24,6 +19,8 @@ typedef struct UnitStatusMessageFormats UnitStatusMessageFormats; #include "unit-name.h" #include "cgroup.h" +typedef struct UnitRef UnitRef; + typedef enum KillOperation { KILL_TERMINATE, KILL_TERMINATE_AND_LOG, @@ -120,7 +117,7 @@ typedef enum UnitCGroupBPFState { UNIT_CGROUP_BPF_INVALIDATED = -1, } UnitCGroupBPFState; -struct Unit { +typedef struct Unit { Manager *manager; UnitType type; @@ -358,13 +355,13 @@ struct Unit { /* When writing transient unit files, stores which section we stored last. If < 0, we didn't write any yet. If * == 0 we are in the [Unit] section, if > 0 we are in the unit type-specific section. */ int last_section_private:2; -}; +} Unit; -struct UnitStatusMessageFormats { +typedef struct UnitStatusMessageFormats { const char *starting_stopping[2]; const char *finished_start_job[_JOB_RESULT_MAX]; const char *finished_stop_job[_JOB_RESULT_MAX]; -}; +} UnitStatusMessageFormats; /* Flags used when writing drop-in files or transient unit files */ typedef enum UnitWriteFlags { @@ -387,17 +384,9 @@ typedef enum UnitWriteFlags { /* Returns true if neither persistent, nor runtime storage is requested, i.e. this is a check invocation only */ #define UNIT_WRITE_FLAGS_NOOP(flags) (((flags) & (UNIT_RUNTIME|UNIT_PERSISTENT)) == 0) -#include "automount.h" -#include "device.h" -#include "path.h" -#include "scope.h" -#include "slice.h" -#include "socket.h" -#include "swap.h" -#include "target.h" -#include "timer.h" - -struct UnitVTable { +#include "kill.h" + +typedef struct UnitVTable { /* How much memory does an object of this unit type need */ size_t object_size; @@ -566,7 +555,7 @@ struct UnitVTable { /* True if queued jobs of this type should be GC'ed if no other job needs them anymore */ bool gc_jobs:1; -}; +} UnitVTable; extern const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX]; @@ -590,18 +579,6 @@ extern const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX]; #define UNIT_TRIGGER(u) ((Unit*) hashmap_first_key((u)->dependencies[UNIT_TRIGGERS])) -DEFINE_CAST(SERVICE, Service); -DEFINE_CAST(SOCKET, Socket); -DEFINE_CAST(TARGET, Target); -DEFINE_CAST(DEVICE, Device); -DEFINE_CAST(MOUNT, Mount); -DEFINE_CAST(AUTOMOUNT, Automount); -DEFINE_CAST(SWAP, Swap); -DEFINE_CAST(TIMER, Timer); -DEFINE_CAST(PATH, Path); -DEFINE_CAST(SLICE, Slice); -DEFINE_CAST(SCOPE, Scope); - Unit *unit_new(Manager *m, size_t size); void unit_free(Unit *u); DEFINE_TRIVIAL_CLEANUP_FUNC(Unit *, unit_free); diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 730dfd1e0b8..20202c9421c 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -24,6 +24,7 @@ #if HAVE_SECCOMP #include "seccomp-util.h" #endif +#include "service.h" #include "stat-util.h" #include "test-helper.h" #include "tests.h" diff --git a/src/test/test-path.c b/src/test/test-path.c index ed53177dcc8..cdc2375d563 100644 --- a/src/test/test-path.c +++ b/src/test/test-path.c @@ -11,6 +11,7 @@ #include #include "alloc-util.h" +#include "all-units.h" #include "fd-util.h" #include "fs-util.h" #include "macro.h" diff --git a/src/test/test-sched-prio.c b/src/test/test-sched-prio.c index 7d8fc445ec0..da0f8581423 100644 --- a/src/test/test-sched-prio.c +++ b/src/test/test-sched-prio.c @@ -7,6 +7,7 @@ #include +#include "all-units.h" #include "macro.h" #include "manager.h" #include "rm-rf.h" diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index 3fd4ac9e5da..45849ef87ed 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -14,6 +14,7 @@ #include #include "alloc-util.h" +#include "all-units.h" #include "capability-util.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c index bb44bc25458..692c3f41cff 100644 --- a/src/test/test-unit-name.c +++ b/src/test/test-unit-name.c @@ -13,6 +13,7 @@ #include #include "alloc-util.h" +#include "all-units.h" #include "glob-util.h" #include "hostname-util.h" #include "macro.h" diff --git a/src/test/test-watch-pid.c b/src/test/test-watch-pid.c index c280374582c..cb43b35bc5d 100644 --- a/src/test/test-watch-pid.c +++ b/src/test/test-watch-pid.c @@ -3,6 +3,7 @@ #include "log.h" #include "manager.h" #include "rm-rf.h" +#include "service.h" #include "test-helper.h" #include "tests.h" -- 2.39.2