]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/unit-def.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / basic / unit-def.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2010 Lennart Poettering
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include <stdbool.h>
24
25 #include "macro.h"
26
27 typedef enum UnitType {
28 UNIT_SERVICE = 0,
29 UNIT_SOCKET,
30 UNIT_TARGET,
31 UNIT_DEVICE,
32 UNIT_MOUNT,
33 UNIT_AUTOMOUNT,
34 UNIT_SWAP,
35 UNIT_TIMER,
36 UNIT_PATH,
37 UNIT_SLICE,
38 UNIT_SCOPE,
39 _UNIT_TYPE_MAX,
40 _UNIT_TYPE_INVALID = -1
41 } UnitType;
42
43 typedef enum UnitLoadState {
44 UNIT_STUB = 0,
45 UNIT_LOADED,
46 UNIT_NOT_FOUND,
47 UNIT_ERROR,
48 UNIT_MERGED,
49 UNIT_MASKED,
50 _UNIT_LOAD_STATE_MAX,
51 _UNIT_LOAD_STATE_INVALID = -1
52 } UnitLoadState;
53
54 typedef enum UnitActiveState {
55 UNIT_ACTIVE,
56 UNIT_RELOADING,
57 UNIT_INACTIVE,
58 UNIT_FAILED,
59 UNIT_ACTIVATING,
60 UNIT_DEACTIVATING,
61 _UNIT_ACTIVE_STATE_MAX,
62 _UNIT_ACTIVE_STATE_INVALID = -1
63 } UnitActiveState;
64
65 typedef enum AutomountState {
66 AUTOMOUNT_DEAD,
67 AUTOMOUNT_WAITING,
68 AUTOMOUNT_RUNNING,
69 AUTOMOUNT_FAILED,
70 _AUTOMOUNT_STATE_MAX,
71 _AUTOMOUNT_STATE_INVALID = -1
72 } AutomountState;
73
74 /* We simply watch devices, we cannot plug/unplug them. That
75 * simplifies the state engine greatly */
76 typedef enum DeviceState {
77 DEVICE_DEAD,
78 DEVICE_TENTATIVE, /* mounted or swapped, but not (yet) announced by udev */
79 DEVICE_PLUGGED, /* announced by udev */
80 _DEVICE_STATE_MAX,
81 _DEVICE_STATE_INVALID = -1
82 } DeviceState;
83
84 typedef enum MountState {
85 MOUNT_DEAD,
86 MOUNT_MOUNTING, /* /usr/bin/mount is running, but the mount is not done yet. */
87 MOUNT_MOUNTING_DONE, /* /usr/bin/mount is running, and the mount is done. */
88 MOUNT_MOUNTED,
89 MOUNT_REMOUNTING,
90 MOUNT_UNMOUNTING,
91 MOUNT_REMOUNTING_SIGTERM,
92 MOUNT_REMOUNTING_SIGKILL,
93 MOUNT_UNMOUNTING_SIGTERM,
94 MOUNT_UNMOUNTING_SIGKILL,
95 MOUNT_FAILED,
96 _MOUNT_STATE_MAX,
97 _MOUNT_STATE_INVALID = -1
98 } MountState;
99
100 typedef enum PathState {
101 PATH_DEAD,
102 PATH_WAITING,
103 PATH_RUNNING,
104 PATH_FAILED,
105 _PATH_STATE_MAX,
106 _PATH_STATE_INVALID = -1
107 } PathState;
108
109 typedef enum ScopeState {
110 SCOPE_DEAD,
111 SCOPE_RUNNING,
112 SCOPE_ABANDONED,
113 SCOPE_STOP_SIGTERM,
114 SCOPE_STOP_SIGKILL,
115 SCOPE_FAILED,
116 _SCOPE_STATE_MAX,
117 _SCOPE_STATE_INVALID = -1
118 } ScopeState;
119
120 typedef enum ServiceState {
121 SERVICE_DEAD,
122 SERVICE_START_PRE,
123 SERVICE_START,
124 SERVICE_START_POST,
125 SERVICE_RUNNING,
126 SERVICE_EXITED, /* Nothing is running anymore, but RemainAfterExit is true hence this is OK */
127 SERVICE_RELOAD,
128 SERVICE_STOP, /* No STOP_PRE state, instead just register multiple STOP executables */
129 SERVICE_STOP_SIGABRT, /* Watchdog timeout */
130 SERVICE_STOP_SIGTERM,
131 SERVICE_STOP_SIGKILL,
132 SERVICE_STOP_POST,
133 SERVICE_FINAL_SIGTERM, /* In case the STOP_POST executable hangs, we shoot that down, too */
134 SERVICE_FINAL_SIGKILL,
135 SERVICE_FAILED,
136 SERVICE_AUTO_RESTART,
137 _SERVICE_STATE_MAX,
138 _SERVICE_STATE_INVALID = -1
139 } ServiceState;
140
141 typedef enum SliceState {
142 SLICE_DEAD,
143 SLICE_ACTIVE,
144 _SLICE_STATE_MAX,
145 _SLICE_STATE_INVALID = -1
146 } SliceState;
147
148 typedef enum SocketState {
149 SOCKET_DEAD,
150 SOCKET_START_PRE,
151 SOCKET_START_CHOWN,
152 SOCKET_START_POST,
153 SOCKET_LISTENING,
154 SOCKET_RUNNING,
155 SOCKET_STOP_PRE,
156 SOCKET_STOP_PRE_SIGTERM,
157 SOCKET_STOP_PRE_SIGKILL,
158 SOCKET_STOP_POST,
159 SOCKET_FINAL_SIGTERM,
160 SOCKET_FINAL_SIGKILL,
161 SOCKET_FAILED,
162 _SOCKET_STATE_MAX,
163 _SOCKET_STATE_INVALID = -1
164 } SocketState;
165
166 typedef enum SwapState {
167 SWAP_DEAD,
168 SWAP_ACTIVATING, /* /sbin/swapon is running, but the swap not yet enabled. */
169 SWAP_ACTIVATING_DONE, /* /sbin/swapon is running, and the swap is done. */
170 SWAP_ACTIVE,
171 SWAP_DEACTIVATING,
172 SWAP_DEACTIVATING_SIGTERM,
173 SWAP_DEACTIVATING_SIGKILL,
174 SWAP_FAILED,
175 _SWAP_STATE_MAX,
176 _SWAP_STATE_INVALID = -1
177 } SwapState;
178
179 typedef enum TargetState {
180 TARGET_DEAD,
181 TARGET_ACTIVE,
182 _TARGET_STATE_MAX,
183 _TARGET_STATE_INVALID = -1
184 } TargetState;
185
186 typedef enum TimerState {
187 TIMER_DEAD,
188 TIMER_WAITING,
189 TIMER_RUNNING,
190 TIMER_ELAPSED,
191 TIMER_FAILED,
192 _TIMER_STATE_MAX,
193 _TIMER_STATE_INVALID = -1
194 } TimerState;
195
196 typedef enum UnitDependency {
197 /* Positive dependencies */
198 UNIT_REQUIRES,
199 UNIT_REQUISITE,
200 UNIT_WANTS,
201 UNIT_BINDS_TO,
202 UNIT_PART_OF,
203
204 /* Inverse of the above */
205 UNIT_REQUIRED_BY, /* inverse of 'requires' is 'required_by' */
206 UNIT_REQUISITE_OF, /* inverse of 'requisite' is 'requisite_of' */
207 UNIT_WANTED_BY, /* inverse of 'wants' */
208 UNIT_BOUND_BY, /* inverse of 'binds_to' */
209 UNIT_CONSISTS_OF, /* inverse of 'part_of' */
210
211 /* Negative dependencies */
212 UNIT_CONFLICTS, /* inverse of 'conflicts' is 'conflicted_by' */
213 UNIT_CONFLICTED_BY,
214
215 /* Order */
216 UNIT_BEFORE, /* inverse of 'before' is 'after' and vice versa */
217 UNIT_AFTER,
218
219 /* On Failure */
220 UNIT_ON_FAILURE,
221
222 /* Triggers (i.e. a socket triggers a service) */
223 UNIT_TRIGGERS,
224 UNIT_TRIGGERED_BY,
225
226 /* Propagate reloads */
227 UNIT_PROPAGATES_RELOAD_TO,
228 UNIT_RELOAD_PROPAGATED_FROM,
229
230 /* Joins namespace of */
231 UNIT_JOINS_NAMESPACE_OF,
232
233 /* Reference information for GC logic */
234 UNIT_REFERENCES, /* Inverse of 'references' is 'referenced_by' */
235 UNIT_REFERENCED_BY,
236
237 _UNIT_DEPENDENCY_MAX,
238 _UNIT_DEPENDENCY_INVALID = -1
239 } UnitDependency;
240
241 typedef enum NotifyAccess {
242 NOTIFY_NONE,
243 NOTIFY_ALL,
244 NOTIFY_MAIN,
245 NOTIFY_EXEC,
246 _NOTIFY_ACCESS_MAX,
247 _NOTIFY_ACCESS_INVALID = -1
248 } NotifyAccess;
249
250 char *unit_dbus_path_from_name(const char *name);
251 int unit_name_from_dbus_path(const char *path, char **name);
252
253 const char* unit_dbus_interface_from_type(UnitType t);
254 const char *unit_dbus_interface_from_name(const char *name);
255
256 const char *unit_type_to_string(UnitType i) _const_;
257 UnitType unit_type_from_string(const char *s) _pure_;
258
259 const char *unit_load_state_to_string(UnitLoadState i) _const_;
260 UnitLoadState unit_load_state_from_string(const char *s) _pure_;
261
262 const char *unit_active_state_to_string(UnitActiveState i) _const_;
263 UnitActiveState unit_active_state_from_string(const char *s) _pure_;
264
265 const char* automount_state_to_string(AutomountState i) _const_;
266 AutomountState automount_state_from_string(const char *s) _pure_;
267
268 const char* device_state_to_string(DeviceState i) _const_;
269 DeviceState device_state_from_string(const char *s) _pure_;
270
271 const char* mount_state_to_string(MountState i) _const_;
272 MountState mount_state_from_string(const char *s) _pure_;
273
274 const char* path_state_to_string(PathState i) _const_;
275 PathState path_state_from_string(const char *s) _pure_;
276
277 const char* scope_state_to_string(ScopeState i) _const_;
278 ScopeState scope_state_from_string(const char *s) _pure_;
279
280 const char* service_state_to_string(ServiceState i) _const_;
281 ServiceState service_state_from_string(const char *s) _pure_;
282
283 const char* slice_state_to_string(SliceState i) _const_;
284 SliceState slice_state_from_string(const char *s) _pure_;
285
286 const char* socket_state_to_string(SocketState i) _const_;
287 SocketState socket_state_from_string(const char *s) _pure_;
288
289 const char* swap_state_to_string(SwapState i) _const_;
290 SwapState swap_state_from_string(const char *s) _pure_;
291
292 const char* target_state_to_string(TargetState i) _const_;
293 TargetState target_state_from_string(const char *s) _pure_;
294
295 const char *timer_state_to_string(TimerState i) _const_;
296 TimerState timer_state_from_string(const char *s) _pure_;
297
298 const char *unit_dependency_to_string(UnitDependency i) _const_;
299 UnitDependency unit_dependency_from_string(const char *s) _pure_;
300
301 const char* notify_access_to_string(NotifyAccess i) _const_;
302 NotifyAccess notify_access_from_string(const char *s) _pure_;