]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/unit-def.h
hexdecoct: make unbase64mem and unhexmem always use SIZE_MAX
[thirdparty/systemd.git] / src / basic / unit-def.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
523578aa
LP
2#pragma once
3
523578aa
LP
4#include <stdbool.h>
5
c37f7963 6#include "errno-list.h"
d8e32c47 7#include "glyph-util.h"
523578aa
LP
8#include "macro.h"
9
fcfc7e11
MO
10/* The enum order is used to order unit jobs in the job queue
11 * when other criteria (cpu weight, nice level) are identical.
162392b7 12 * In this case service units have the highest priority. */
523578aa 13typedef enum UnitType {
22f401b2 14 UNIT_SERVICE,
fcfc7e11
MO
15 UNIT_MOUNT,
16 UNIT_SWAP,
523578aa
LP
17 UNIT_SOCKET,
18 UNIT_TARGET,
19 UNIT_DEVICE,
523578aa 20 UNIT_AUTOMOUNT,
523578aa
LP
21 UNIT_TIMER,
22 UNIT_PATH,
23 UNIT_SLICE,
24 UNIT_SCOPE,
25 _UNIT_TYPE_MAX,
2d93c20e 26 _UNIT_TYPE_INVALID = -EINVAL,
c37f7963 27 _UNIT_TYPE_ERRNO_MAX = -ERRNO_MAX, /* Ensure the whole errno range fits into this enum */
523578aa
LP
28} UnitType;
29
30typedef enum UnitLoadState {
22f401b2 31 UNIT_STUB,
523578aa 32 UNIT_LOADED,
c4555ad8
LP
33 UNIT_NOT_FOUND, /* error condition #1: unit file not found */
34 UNIT_BAD_SETTING, /* error condition #2: we couldn't parse some essential unit file setting */
35 UNIT_ERROR, /* error condition #3: other "system" error, catchall for the rest */
523578aa
LP
36 UNIT_MERGED,
37 UNIT_MASKED,
38 _UNIT_LOAD_STATE_MAX,
2d93c20e 39 _UNIT_LOAD_STATE_INVALID = -EINVAL,
523578aa
LP
40} UnitLoadState;
41
42typedef enum UnitActiveState {
43 UNIT_ACTIVE,
44 UNIT_RELOADING,
45 UNIT_INACTIVE,
46 UNIT_FAILED,
47 UNIT_ACTIVATING,
48 UNIT_DEACTIVATING,
380dc8b0 49 UNIT_MAINTENANCE,
523578aa 50 _UNIT_ACTIVE_STATE_MAX,
2d93c20e 51 _UNIT_ACTIVE_STATE_INVALID = -EINVAL,
523578aa
LP
52} UnitActiveState;
53
d9e45bc3
MS
54typedef enum FreezerState {
55 FREEZER_RUNNING,
56 FREEZER_FREEZING,
57 FREEZER_FROZEN,
58 FREEZER_THAWING,
59 _FREEZER_STATE_MAX,
2d93c20e 60 _FREEZER_STATE_INVALID = -EINVAL,
d9e45bc3
MS
61} FreezerState;
62
ff68472a
ZJS
63typedef enum UnitMarker {
64 UNIT_MARKER_NEEDS_RELOAD,
65 UNIT_MARKER_NEEDS_RESTART,
66 _UNIT_MARKER_MAX,
7a563bb2 67 _UNIT_MARKER_INVALID = -EINVAL,
ff68472a
ZJS
68} UnitMarker;
69
523578aa
LP
70typedef enum AutomountState {
71 AUTOMOUNT_DEAD,
72 AUTOMOUNT_WAITING,
73 AUTOMOUNT_RUNNING,
74 AUTOMOUNT_FAILED,
75 _AUTOMOUNT_STATE_MAX,
2d93c20e 76 _AUTOMOUNT_STATE_INVALID = -EINVAL,
523578aa
LP
77} AutomountState;
78
79/* We simply watch devices, we cannot plug/unplug them. That
80 * simplifies the state engine greatly */
81typedef enum DeviceState {
82 DEVICE_DEAD,
83 DEVICE_TENTATIVE, /* mounted or swapped, but not (yet) announced by udev */
84 DEVICE_PLUGGED, /* announced by udev */
85 _DEVICE_STATE_MAX,
2d93c20e 86 _DEVICE_STATE_INVALID = -EINVAL,
523578aa
LP
87} DeviceState;
88
89typedef enum MountState {
90 MOUNT_DEAD,
91 MOUNT_MOUNTING, /* /usr/bin/mount is running, but the mount is not done yet. */
92 MOUNT_MOUNTING_DONE, /* /usr/bin/mount is running, and the mount is done. */
93 MOUNT_MOUNTED,
94 MOUNT_REMOUNTING,
95 MOUNT_UNMOUNTING,
96 MOUNT_REMOUNTING_SIGTERM,
97 MOUNT_REMOUNTING_SIGKILL,
98 MOUNT_UNMOUNTING_SIGTERM,
99 MOUNT_UNMOUNTING_SIGKILL,
100 MOUNT_FAILED,
17e9d53d 101 MOUNT_CLEANING,
523578aa 102 _MOUNT_STATE_MAX,
2d93c20e 103 _MOUNT_STATE_INVALID = -EINVAL,
523578aa
LP
104} MountState;
105
106typedef enum PathState {
107 PATH_DEAD,
108 PATH_WAITING,
109 PATH_RUNNING,
110 PATH_FAILED,
111 _PATH_STATE_MAX,
2d93c20e 112 _PATH_STATE_INVALID = -EINVAL,
523578aa
LP
113} PathState;
114
115typedef enum ScopeState {
116 SCOPE_DEAD,
03860190 117 SCOPE_START_CHOWN,
523578aa
LP
118 SCOPE_RUNNING,
119 SCOPE_ABANDONED,
120 SCOPE_STOP_SIGTERM,
121 SCOPE_STOP_SIGKILL,
122 SCOPE_FAILED,
123 _SCOPE_STATE_MAX,
2d93c20e 124 _SCOPE_STATE_INVALID = -EINVAL,
523578aa
LP
125} ScopeState;
126
127typedef enum ServiceState {
128 SERVICE_DEAD,
31cd5f63 129 SERVICE_CONDITION,
523578aa
LP
130 SERVICE_START_PRE,
131 SERVICE_START,
132 SERVICE_START_POST,
133 SERVICE_RUNNING,
134 SERVICE_EXITED, /* Nothing is running anymore, but RemainAfterExit is true hence this is OK */
3bd28bf7
LP
135 SERVICE_RELOAD, /* Reloading via ExecReload= */
136 SERVICE_RELOAD_SIGNAL, /* Reloading via SIGHUP requested */
137 SERVICE_RELOAD_NOTIFY, /* Waiting for READY=1 after RELOADING=1 notify */
523578aa 138 SERVICE_STOP, /* No STOP_PRE state, instead just register multiple STOP executables */
c87700a1 139 SERVICE_STOP_WATCHDOG,
523578aa
LP
140 SERVICE_STOP_SIGTERM,
141 SERVICE_STOP_SIGKILL,
142 SERVICE_STOP_POST,
bf760801 143 SERVICE_FINAL_WATCHDOG, /* In case the STOP_POST executable needs to be aborted. */
523578aa
LP
144 SERVICE_FINAL_SIGTERM, /* In case the STOP_POST executable hangs, we shoot that down, too */
145 SERVICE_FINAL_SIGKILL,
146 SERVICE_FAILED,
a1d31573
LP
147 SERVICE_DEAD_BEFORE_AUTO_RESTART,
148 SERVICE_FAILED_BEFORE_AUTO_RESTART,
b9c1883a 149 SERVICE_DEAD_RESOURCES_PINNED, /* Like SERVICE_DEAD, but with pinned resources */
523578aa 150 SERVICE_AUTO_RESTART,
09d04ad3 151 SERVICE_AUTO_RESTART_QUEUED,
4c2f5842 152 SERVICE_CLEANING,
523578aa 153 _SERVICE_STATE_MAX,
2d93c20e 154 _SERVICE_STATE_INVALID = -EINVAL,
523578aa
LP
155} ServiceState;
156
157typedef enum SliceState {
158 SLICE_DEAD,
159 SLICE_ACTIVE,
160 _SLICE_STATE_MAX,
2d93c20e 161 _SLICE_STATE_INVALID = -EINVAL,
523578aa
LP
162} SliceState;
163
164typedef enum SocketState {
165 SOCKET_DEAD,
166 SOCKET_START_PRE,
167 SOCKET_START_CHOWN,
168 SOCKET_START_POST,
169 SOCKET_LISTENING,
170 SOCKET_RUNNING,
171 SOCKET_STOP_PRE,
172 SOCKET_STOP_PRE_SIGTERM,
173 SOCKET_STOP_PRE_SIGKILL,
174 SOCKET_STOP_POST,
175 SOCKET_FINAL_SIGTERM,
176 SOCKET_FINAL_SIGKILL,
177 SOCKET_FAILED,
c968d76a 178 SOCKET_CLEANING,
523578aa 179 _SOCKET_STATE_MAX,
2d93c20e 180 _SOCKET_STATE_INVALID = -EINVAL,
523578aa
LP
181} SocketState;
182
183typedef enum SwapState {
184 SWAP_DEAD,
185 SWAP_ACTIVATING, /* /sbin/swapon is running, but the swap not yet enabled. */
186 SWAP_ACTIVATING_DONE, /* /sbin/swapon is running, and the swap is done. */
187 SWAP_ACTIVE,
188 SWAP_DEACTIVATING,
189 SWAP_DEACTIVATING_SIGTERM,
190 SWAP_DEACTIVATING_SIGKILL,
191 SWAP_FAILED,
a8b689b7 192 SWAP_CLEANING,
523578aa 193 _SWAP_STATE_MAX,
2d93c20e 194 _SWAP_STATE_INVALID = -EINVAL,
523578aa
LP
195} SwapState;
196
197typedef enum TargetState {
198 TARGET_DEAD,
199 TARGET_ACTIVE,
200 _TARGET_STATE_MAX,
2d93c20e 201 _TARGET_STATE_INVALID = -EINVAL,
523578aa
LP
202} TargetState;
203
204typedef enum TimerState {
205 TIMER_DEAD,
206 TIMER_WAITING,
207 TIMER_RUNNING,
208 TIMER_ELAPSED,
209 TIMER_FAILED,
210 _TIMER_STATE_MAX,
2d93c20e 211 _TIMER_STATE_INVALID = -EINVAL,
523578aa
LP
212} TimerState;
213
214typedef enum UnitDependency {
215 /* Positive dependencies */
216 UNIT_REQUIRES,
217 UNIT_REQUISITE,
218 UNIT_WANTS,
219 UNIT_BINDS_TO,
220 UNIT_PART_OF,
0bc488c9 221 UNIT_UPHOLDS,
523578aa
LP
222
223 /* Inverse of the above */
224 UNIT_REQUIRED_BY, /* inverse of 'requires' is 'required_by' */
225 UNIT_REQUISITE_OF, /* inverse of 'requisite' is 'requisite_of' */
226 UNIT_WANTED_BY, /* inverse of 'wants' */
227 UNIT_BOUND_BY, /* inverse of 'binds_to' */
228 UNIT_CONSISTS_OF, /* inverse of 'part_of' */
0bc488c9 229 UNIT_UPHELD_BY, /* inverse of 'uphold' */
523578aa
LP
230
231 /* Negative dependencies */
232 UNIT_CONFLICTS, /* inverse of 'conflicts' is 'conflicted_by' */
233 UNIT_CONFLICTED_BY,
234
235 /* Order */
236 UNIT_BEFORE, /* inverse of 'before' is 'after' and vice versa */
237 UNIT_AFTER,
238
294446dc
LP
239 /* OnSuccess= + OnFailure= */
240 UNIT_ON_SUCCESS,
241 UNIT_ON_SUCCESS_OF,
523578aa 242 UNIT_ON_FAILURE,
629b2a6f 243 UNIT_ON_FAILURE_OF,
523578aa
LP
244
245 /* Triggers (i.e. a socket triggers a service) */
246 UNIT_TRIGGERS,
247 UNIT_TRIGGERED_BY,
248
249 /* Propagate reloads */
250 UNIT_PROPAGATES_RELOAD_TO,
251 UNIT_RELOAD_PROPAGATED_FROM,
ffec78c0
LP
252
253 /* Propagate stops */
254 UNIT_PROPAGATES_STOP_TO,
255 UNIT_STOP_PROPAGATED_FROM,
523578aa
LP
256
257 /* Joins namespace of */
258 UNIT_JOINS_NAMESPACE_OF,
259
260 /* Reference information for GC logic */
261 UNIT_REFERENCES, /* Inverse of 'references' is 'referenced_by' */
262 UNIT_REFERENCED_BY,
263
d219a2b0
LP
264 /* Slice= */
265 UNIT_IN_SLICE,
266 UNIT_SLICE_OF,
267
523578aa 268 _UNIT_DEPENDENCY_MAX,
2d93c20e 269 _UNIT_DEPENDENCY_INVALID = -EINVAL,
523578aa
LP
270} UnitDependency;
271
272typedef enum NotifyAccess {
273 NOTIFY_NONE,
274 NOTIFY_ALL,
275 NOTIFY_MAIN,
276 NOTIFY_EXEC,
277 _NOTIFY_ACCESS_MAX,
2d93c20e 278 _NOTIFY_ACCESS_INVALID = -EINVAL,
523578aa
LP
279} NotifyAccess;
280
281char *unit_dbus_path_from_name(const char *name);
282int unit_name_from_dbus_path(const char *path, char **name);
283
284const char* unit_dbus_interface_from_type(UnitType t);
285const char *unit_dbus_interface_from_name(const char *name);
286
287const char *unit_type_to_string(UnitType i) _const_;
288UnitType unit_type_from_string(const char *s) _pure_;
289
1b17dd90
DDM
290const char* unit_type_to_capitalized_string(UnitType t);
291
523578aa
LP
292const char *unit_load_state_to_string(UnitLoadState i) _const_;
293UnitLoadState unit_load_state_from_string(const char *s) _pure_;
294
295const char *unit_active_state_to_string(UnitActiveState i) _const_;
296UnitActiveState unit_active_state_from_string(const char *s) _pure_;
297
d9e45bc3
MS
298const char *freezer_state_to_string(FreezerState i) _const_;
299FreezerState freezer_state_from_string(const char *s) _pure_;
300
ff68472a
ZJS
301const char *unit_marker_to_string(UnitMarker m) _const_;
302UnitMarker unit_marker_from_string(const char *s) _pure_;
303
523578aa
LP
304const char* automount_state_to_string(AutomountState i) _const_;
305AutomountState automount_state_from_string(const char *s) _pure_;
306
307const char* device_state_to_string(DeviceState i) _const_;
308DeviceState device_state_from_string(const char *s) _pure_;
309
310const char* mount_state_to_string(MountState i) _const_;
311MountState mount_state_from_string(const char *s) _pure_;
312
313const char* path_state_to_string(PathState i) _const_;
314PathState path_state_from_string(const char *s) _pure_;
315
316const char* scope_state_to_string(ScopeState i) _const_;
317ScopeState scope_state_from_string(const char *s) _pure_;
318
319const char* service_state_to_string(ServiceState i) _const_;
320ServiceState service_state_from_string(const char *s) _pure_;
321
322const char* slice_state_to_string(SliceState i) _const_;
323SliceState slice_state_from_string(const char *s) _pure_;
324
325const char* socket_state_to_string(SocketState i) _const_;
326SocketState socket_state_from_string(const char *s) _pure_;
327
328const char* swap_state_to_string(SwapState i) _const_;
329SwapState swap_state_from_string(const char *s) _pure_;
330
331const char* target_state_to_string(TargetState i) _const_;
332TargetState target_state_from_string(const char *s) _pure_;
333
334const char *timer_state_to_string(TimerState i) _const_;
335TimerState timer_state_from_string(const char *s) _pure_;
336
337const char *unit_dependency_to_string(UnitDependency i) _const_;
338UnitDependency unit_dependency_from_string(const char *s) _pure_;
339
340const char* notify_access_to_string(NotifyAccess i) _const_;
341NotifyAccess notify_access_from_string(const char *s) _pure_;
9ae5fed6
J
342
343SpecialGlyph unit_active_state_to_glyph(UnitActiveState state);