Debian Codegraph @

src/basic/unit-def.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "basic-forward.h"
5
6 /* The enum order is used to order unit jobs in the job queue
7 * when other criteria (cpu weight, nice level) are identical.
8 * In this case service units have the highest priority. */
9 typedef enum UnitType {
10 UNIT_SERVICE,
11 UNIT_MOUNT,
12 UNIT_SWAP,
13 UNIT_SOCKET,
14 UNIT_TARGET,
15 UNIT_DEVICE,
16 UNIT_AUTOMOUNT,
17 UNIT_TIMER,
18 UNIT_PATH,
19 UNIT_SLICE,
20 UNIT_SCOPE,
21 _UNIT_TYPE_MAX,
22 _UNIT_TYPE_INVALID = -EINVAL,
23 _UNIT_TYPE_ERRNO_MAX = -ERRNO_MAX, /* Ensure the whole errno range fits into this enum */
24 } UnitType;
25
26 typedef enum UnitLoadState {
27 UNIT_STUB,
28 UNIT_LOADED,
29 UNIT_NOT_FOUND, /* error condition #1: unit file not found */
30 UNIT_BAD_SETTING, /* error condition #2: we couldn't parse some essential unit file setting */
31 UNIT_ERROR, /* error condition #3: other "system" error, catchall for the rest */
32 UNIT_MERGED,
33 UNIT_MASKED,
34 _UNIT_LOAD_STATE_MAX,
35 _UNIT_LOAD_STATE_INVALID = -EINVAL,
36 } UnitLoadState;
37
38 typedef enum UnitActiveState {
39 UNIT_ACTIVE,
40 UNIT_RELOADING,
41 UNIT_INACTIVE,
42 UNIT_FAILED,
43 UNIT_ACTIVATING,
44 UNIT_DEACTIVATING,
45 UNIT_MAINTENANCE,
46 UNIT_REFRESHING,
47 _UNIT_ACTIVE_STATE_MAX,
48 _UNIT_ACTIVE_STATE_INVALID = -EINVAL,
49 } UnitActiveState;
50
51 typedef enum FreezerState {
52 FREEZER_RUNNING,
53 FREEZER_FREEZING, /* freezing due to user request */
54 FREEZER_FROZEN,
55 FREEZER_FREEZING_BY_PARENT, /* freezing as a result of parent slice freezing */
56 FREEZER_FROZEN_BY_PARENT,
57 FREEZER_THAWING,
58 _FREEZER_STATE_MAX,
59 _FREEZER_STATE_INVALID = -EINVAL,
60 } FreezerState;
61
62 typedef enum UnitMarker {
63 UNIT_MARKER_NEEDS_RELOAD,
64 UNIT_MARKER_NEEDS_RESTART,
65 UNIT_MARKER_NEEDS_STOP,
66 UNIT_MARKER_NEEDS_START,
67 _UNIT_MARKER_MAX,
68 _UNIT_MARKER_INVALID = -EINVAL,
69 } UnitMarker;
70
71 typedef enum AutomountState {
72 AUTOMOUNT_DEAD,
73 AUTOMOUNT_WAITING,
74 AUTOMOUNT_RUNNING,
75 AUTOMOUNT_FAILED,
76 _AUTOMOUNT_STATE_MAX,
77 _AUTOMOUNT_STATE_INVALID = -EINVAL,
78 } AutomountState;
79
80 /* We simply watch devices, we cannot plug/unplug them. That
81 * simplifies the state engine greatly */
82 typedef enum DeviceState {
83 DEVICE_DEAD,
84 DEVICE_TENTATIVE, /* mounted or swapped, but not (yet) announced by udev */
85 DEVICE_PLUGGED, /* announced by udev */
86 _DEVICE_STATE_MAX,
87 _DEVICE_STATE_INVALID = -EINVAL,
88 } DeviceState;
89
90 typedef enum MountState {
91 MOUNT_DEAD,
92 MOUNT_MOUNTING, /* /usr/bin/mount is running, but the mount is not done yet. */
93 MOUNT_MOUNTING_DONE, /* /usr/bin/mount is running, and the mount is done. */
94 MOUNT_MOUNTED,
95 MOUNT_REMOUNTING,
96 MOUNT_UNMOUNTING,
97 MOUNT_REMOUNTING_SIGTERM,
98 MOUNT_REMOUNTING_SIGKILL,
99 MOUNT_UNMOUNTING_SIGTERM,
100 MOUNT_UNMOUNTING_SIGKILL,
101 MOUNT_FAILED,
102 MOUNT_CLEANING,
103 _MOUNT_STATE_MAX,
104 _MOUNT_STATE_INVALID = -EINVAL,
105 } MountState;
106
107 typedef enum PathState {
108 PATH_DEAD,
109 PATH_WAITING,
110 PATH_RUNNING,
111 PATH_FAILED,
112 _PATH_STATE_MAX,
113 _PATH_STATE_INVALID = -EINVAL,
114 } PathState;
115
116 typedef enum ScopeState {
117 SCOPE_DEAD,
118 SCOPE_START_CHOWN,
119 SCOPE_RUNNING,
120 SCOPE_ABANDONED,
121 SCOPE_STOP_SIGTERM,
122 SCOPE_STOP_SIGKILL,
123 SCOPE_FAILED,
124 _SCOPE_STATE_MAX,
125 _SCOPE_STATE_INVALID = -EINVAL,
126 } ScopeState;
127
128 typedef enum ServiceState {
129 SERVICE_DEAD,
130 SERVICE_CONDITION,
131 SERVICE_START_PRE,
132 SERVICE_START,
133 SERVICE_START_POST,
134 SERVICE_RUNNING,
135 SERVICE_EXITED, /* Nothing is running anymore, but RemainAfterExit is true hence this is OK */
136 SERVICE_REFRESH_EXTENSIONS, /* Refreshing extensions for a reload request */
137 SERVICE_REFRESH_CREDENTIALS, /* ditto, but for credentials */
138 SERVICE_RELOAD, /* Reloading via ExecReload= */
139 SERVICE_RELOAD_SIGNAL, /* Reloading via SIGHUP requested */
140 SERVICE_RELOAD_NOTIFY, /* Waiting for READY=1 after RELOADING=1 notify */
141 SERVICE_RELOAD_POST,
142 SERVICE_MOUNTING, /* Performing a live mount into the namespace of the service */
143 SERVICE_STOP, /* No STOP_PRE state, instead just register multiple STOP executables */
144 SERVICE_STOP_WATCHDOG,
145 SERVICE_STOP_SIGTERM,
146 SERVICE_STOP_SIGKILL,
147 SERVICE_STOP_POST,
148 SERVICE_FINAL_WATCHDOG, /* In case the STOP_POST executable needs to be aborted. */
149 SERVICE_FINAL_SIGTERM, /* In case the STOP_POST executable hangs, we shoot that down, too */
150 SERVICE_FINAL_SIGKILL,
151 SERVICE_FAILED,
152 SERVICE_DEAD_BEFORE_AUTO_RESTART,
153 SERVICE_FAILED_BEFORE_AUTO_RESTART,
154 SERVICE_DEAD_RESOURCES_PINNED, /* Like SERVICE_DEAD, but with pinned resources */
155 SERVICE_AUTO_RESTART,
156 SERVICE_AUTO_RESTART_QUEUED,
157 SERVICE_CLEANING,
158 _SERVICE_STATE_MAX,
159 _SERVICE_STATE_INVALID = -EINVAL,
160 } ServiceState;
161
162 typedef enum SliceState {
163 SLICE_DEAD,
164 SLICE_ACTIVE,
165 _SLICE_STATE_MAX,
166 _SLICE_STATE_INVALID = -EINVAL,
167 } SliceState;
168
169 typedef enum SocketState {
170 SOCKET_DEAD,
171 SOCKET_START_PRE,
172 SOCKET_START_OPEN,
173 SOCKET_START_CHOWN,
174 SOCKET_START_POST,
175 SOCKET_LISTENING,
176 SOCKET_DEFERRED,
177 SOCKET_RUNNING,
178 SOCKET_STOP_PRE,
179 SOCKET_STOP_PRE_SIGTERM,
180 SOCKET_STOP_PRE_SIGKILL,
181 SOCKET_STOP_POST,
182 SOCKET_FINAL_SIGTERM,
183 SOCKET_FINAL_SIGKILL,
184 SOCKET_FAILED,
185 SOCKET_CLEANING,
186 _SOCKET_STATE_MAX,
187 _SOCKET_STATE_INVALID = -EINVAL,
188 } SocketState;
189
190 typedef enum SwapState {
191 SWAP_DEAD,
192 SWAP_ACTIVATING, /* /sbin/swapon is running, but the swap not yet enabled. */
193 SWAP_ACTIVATING_DONE, /* /sbin/swapon is running, and the swap is done. */
194 SWAP_ACTIVE,
195 SWAP_DEACTIVATING,
196 SWAP_DEACTIVATING_SIGTERM,
197 SWAP_DEACTIVATING_SIGKILL,
198 SWAP_FAILED,
199 SWAP_CLEANING,
200 _SWAP_STATE_MAX,
201 _SWAP_STATE_INVALID = -EINVAL,
202 } SwapState;
203
204 typedef enum TargetState {
205 TARGET_DEAD,
206 TARGET_ACTIVE,
207 _TARGET_STATE_MAX,
208 _TARGET_STATE_INVALID = -EINVAL,
209 } TargetState;
210
211 typedef enum TimerState {
212 TIMER_DEAD,
213 TIMER_WAITING,
214 TIMER_RUNNING,
215 TIMER_ELAPSED,
216 TIMER_FAILED,
217 _TIMER_STATE_MAX,
218 _TIMER_STATE_INVALID = -EINVAL,
219 } TimerState;
220
221 typedef enum UnitDependency {
222 /* Positive dependencies */
223 UNIT_REQUIRES,
224 UNIT_REQUISITE,
225 UNIT_WANTS,
226 UNIT_BINDS_TO,
227 UNIT_PART_OF,
228 UNIT_UPHOLDS,
229
230 /* Inverse of the above */
231 UNIT_REQUIRED_BY, /* inverse of 'requires' is 'required_by' */
232 UNIT_REQUISITE_OF, /* inverse of 'requisite' is 'requisite_of' */
233 UNIT_WANTED_BY, /* inverse of 'wants' */
234 UNIT_BOUND_BY, /* inverse of 'binds_to' */
235 UNIT_CONSISTS_OF, /* inverse of 'part_of' */
236 UNIT_UPHELD_BY, /* inverse of 'uphold' */
237
238 /* Negative dependencies */
239 UNIT_CONFLICTS, /* inverse of 'conflicts' is 'conflicted_by' */
240 UNIT_CONFLICTED_BY,
241
242 /* Order */
243 UNIT_BEFORE, /* inverse of 'before' is 'after' and vice versa */
244 UNIT_AFTER,
245
246 /* OnSuccess= + OnFailure= */
247 UNIT_ON_SUCCESS,
248 UNIT_ON_SUCCESS_OF,
249 UNIT_ON_FAILURE,
250 UNIT_ON_FAILURE_OF,
251
252 /* Triggers (i.e. a socket triggers a service) */
253 UNIT_TRIGGERS,
254 UNIT_TRIGGERED_BY,
255
256 /* Propagate reloads */
257 UNIT_PROPAGATES_RELOAD_TO,
258 UNIT_RELOAD_PROPAGATED_FROM,
259
260 /* Propagate stops */
261 UNIT_PROPAGATES_STOP_TO,
262 UNIT_STOP_PROPAGATED_FROM,
263
264 /* Joins namespace of */
265 UNIT_JOINS_NAMESPACE_OF,
266
267 /* Reference information for GC logic */
268 UNIT_REFERENCES, /* Inverse of 'references' is 'referenced_by' */
269 UNIT_REFERENCED_BY,
270
271 /* Slice= */
272 UNIT_IN_SLICE,
273 UNIT_SLICE_OF,
274
275 _UNIT_DEPENDENCY_MAX,
276 _UNIT_DEPENDENCY_INVALID = -EINVAL,
277 } UnitDependency;
278
279 typedef enum NotifyAccess {
280 NOTIFY_NONE,
281 NOTIFY_ALL,
282 NOTIFY_MAIN,
283 NOTIFY_EXEC,
284 _NOTIFY_ACCESS_MAX,
285 _NOTIFY_ACCESS_INVALID = -EINVAL,
286 } NotifyAccess;
287
288 typedef enum JobMode {
289 JOB_FAIL, /* Fail if a conflicting job is already queued */
290 JOB_LENIENT, /* Fail if any conflicting unit is active (even weaker than JOB_FAIL) */
291 JOB_REPLACE, /* Replace an existing conflicting job */
292 JOB_REPLACE_IRREVERSIBLY, /* Like JOB_REPLACE + produce irreversible jobs */
293 JOB_ISOLATE, /* Start a unit, and stop all others */
294 JOB_FLUSH, /* Flush out all other queued jobs when queueing this one */
295 JOB_IGNORE_DEPENDENCIES, /* Ignore both requirement and ordering dependencies */
296 JOB_IGNORE_REQUIREMENTS, /* Ignore requirement dependencies */
297 JOB_TRIGGERING, /* Adds TRIGGERED_BY dependencies to the same transaction */
298 JOB_RESTART_DEPENDENCIES, /* A "start" job for the specified unit becomes "restart" for depending units */
299 _JOB_MODE_MAX,
300 _JOB_MODE_INVALID = -EINVAL,
301 } JobMode;
302
303 typedef enum ExecDirectoryType {
304 EXEC_DIRECTORY_RUNTIME,
305 EXEC_DIRECTORY_STATE,
306 EXEC_DIRECTORY_CACHE,
307 EXEC_DIRECTORY_LOGS,
308 EXEC_DIRECTORY_CONFIGURATION,
309 _EXEC_DIRECTORY_TYPE_MAX,
310 _EXEC_DIRECTORY_TYPE_INVALID = -EINVAL,
311 } ExecDirectoryType;
312
313 char* unit_dbus_path_from_name(const char *name);
314 int unit_name_from_dbus_path(const char *path, char **name);
315
316 const char* unit_dbus_interface_from_type(UnitType t);
317 const char* unit_dbus_interface_from_name(const char *name);
318
319 DECLARE_STRING_TABLE_LOOKUP(unit_type, UnitType);
320 void unit_types_list(void);
321
322 DECLARE_STRING_TABLE_LOOKUP(unit_load_state, UnitLoadState);
323 DECLARE_STRING_TABLE_LOOKUP(unit_active_state, UnitActiveState);
324 const char* unit_type_to_capitalized_string(UnitType t);
325
326 DECLARE_STRING_TABLE_LOOKUP(freezer_state, FreezerState);
327 FreezerState freezer_state_finish(FreezerState state) _const_;
328 FreezerState freezer_state_objective(FreezerState state) _const_;
329
330 DECLARE_STRING_TABLE_LOOKUP(unit_marker, UnitMarker);
331 DECLARE_STRING_TABLE_LOOKUP(automount_state, AutomountState);
332 DECLARE_STRING_TABLE_LOOKUP(device_state, DeviceState);
333 DECLARE_STRING_TABLE_LOOKUP(mount_state, MountState);
334 DECLARE_STRING_TABLE_LOOKUP(path_state, PathState);
335 DECLARE_STRING_TABLE_LOOKUP(scope_state, ScopeState);
336 DECLARE_STRING_TABLE_LOOKUP(service_state, ServiceState);
337 DECLARE_STRING_TABLE_LOOKUP(slice_state, SliceState);
338 DECLARE_STRING_TABLE_LOOKUP(socket_state, SocketState);
339 DECLARE_STRING_TABLE_LOOKUP(swap_state, SwapState);
340 DECLARE_STRING_TABLE_LOOKUP(target_state, TargetState);
341 DECLARE_STRING_TABLE_LOOKUP(timer_state, TimerState);
342 DECLARE_STRING_TABLE_LOOKUP(unit_dependency, UnitDependency);
343 DECLARE_STRING_TABLE_LOOKUP(notify_access, NotifyAccess);
344 DECLARE_STRING_TABLE_LOOKUP(job_mode, JobMode);
345 DECLARE_STRING_TABLE_LOOKUP(exec_directory_type, ExecDirectoryType);
346
347 Glyph unit_active_state_to_glyph(UnitActiveState state);