]>
Commit | Line | Data |
---|---|---|
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 | 13 | typedef 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 | ||
30 | typedef 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 | ||
42 | typedef 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 |
54 | typedef 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 |
63 | typedef 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 |
70 | typedef 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 */ | |
81 | typedef 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 | ||
89 | typedef 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 | ||
106 | typedef 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 | ||
115 | typedef 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 | ||
127 | typedef 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 */ | |
135 | SERVICE_RELOAD, | |
136 | SERVICE_STOP, /* No STOP_PRE state, instead just register multiple STOP executables */ | |
c87700a1 | 137 | SERVICE_STOP_WATCHDOG, |
523578aa LP |
138 | SERVICE_STOP_SIGTERM, |
139 | SERVICE_STOP_SIGKILL, | |
140 | SERVICE_STOP_POST, | |
bf760801 | 141 | SERVICE_FINAL_WATCHDOG, /* In case the STOP_POST executable needs to be aborted. */ |
523578aa LP |
142 | SERVICE_FINAL_SIGTERM, /* In case the STOP_POST executable hangs, we shoot that down, too */ |
143 | SERVICE_FINAL_SIGKILL, | |
144 | SERVICE_FAILED, | |
145 | SERVICE_AUTO_RESTART, | |
4c2f5842 | 146 | SERVICE_CLEANING, |
523578aa | 147 | _SERVICE_STATE_MAX, |
2d93c20e | 148 | _SERVICE_STATE_INVALID = -EINVAL, |
523578aa LP |
149 | } ServiceState; |
150 | ||
151 | typedef enum SliceState { | |
152 | SLICE_DEAD, | |
153 | SLICE_ACTIVE, | |
154 | _SLICE_STATE_MAX, | |
2d93c20e | 155 | _SLICE_STATE_INVALID = -EINVAL, |
523578aa LP |
156 | } SliceState; |
157 | ||
158 | typedef enum SocketState { | |
159 | SOCKET_DEAD, | |
160 | SOCKET_START_PRE, | |
161 | SOCKET_START_CHOWN, | |
162 | SOCKET_START_POST, | |
163 | SOCKET_LISTENING, | |
164 | SOCKET_RUNNING, | |
165 | SOCKET_STOP_PRE, | |
166 | SOCKET_STOP_PRE_SIGTERM, | |
167 | SOCKET_STOP_PRE_SIGKILL, | |
168 | SOCKET_STOP_POST, | |
169 | SOCKET_FINAL_SIGTERM, | |
170 | SOCKET_FINAL_SIGKILL, | |
171 | SOCKET_FAILED, | |
c968d76a | 172 | SOCKET_CLEANING, |
523578aa | 173 | _SOCKET_STATE_MAX, |
2d93c20e | 174 | _SOCKET_STATE_INVALID = -EINVAL, |
523578aa LP |
175 | } SocketState; |
176 | ||
177 | typedef enum SwapState { | |
178 | SWAP_DEAD, | |
179 | SWAP_ACTIVATING, /* /sbin/swapon is running, but the swap not yet enabled. */ | |
180 | SWAP_ACTIVATING_DONE, /* /sbin/swapon is running, and the swap is done. */ | |
181 | SWAP_ACTIVE, | |
182 | SWAP_DEACTIVATING, | |
183 | SWAP_DEACTIVATING_SIGTERM, | |
184 | SWAP_DEACTIVATING_SIGKILL, | |
185 | SWAP_FAILED, | |
a8b689b7 | 186 | SWAP_CLEANING, |
523578aa | 187 | _SWAP_STATE_MAX, |
2d93c20e | 188 | _SWAP_STATE_INVALID = -EINVAL, |
523578aa LP |
189 | } SwapState; |
190 | ||
191 | typedef enum TargetState { | |
192 | TARGET_DEAD, | |
193 | TARGET_ACTIVE, | |
194 | _TARGET_STATE_MAX, | |
2d93c20e | 195 | _TARGET_STATE_INVALID = -EINVAL, |
523578aa LP |
196 | } TargetState; |
197 | ||
198 | typedef enum TimerState { | |
199 | TIMER_DEAD, | |
200 | TIMER_WAITING, | |
201 | TIMER_RUNNING, | |
202 | TIMER_ELAPSED, | |
203 | TIMER_FAILED, | |
204 | _TIMER_STATE_MAX, | |
2d93c20e | 205 | _TIMER_STATE_INVALID = -EINVAL, |
523578aa LP |
206 | } TimerState; |
207 | ||
208 | typedef enum UnitDependency { | |
209 | /* Positive dependencies */ | |
210 | UNIT_REQUIRES, | |
211 | UNIT_REQUISITE, | |
212 | UNIT_WANTS, | |
213 | UNIT_BINDS_TO, | |
214 | UNIT_PART_OF, | |
0bc488c9 | 215 | UNIT_UPHOLDS, |
523578aa LP |
216 | |
217 | /* Inverse of the above */ | |
218 | UNIT_REQUIRED_BY, /* inverse of 'requires' is 'required_by' */ | |
219 | UNIT_REQUISITE_OF, /* inverse of 'requisite' is 'requisite_of' */ | |
220 | UNIT_WANTED_BY, /* inverse of 'wants' */ | |
221 | UNIT_BOUND_BY, /* inverse of 'binds_to' */ | |
222 | UNIT_CONSISTS_OF, /* inverse of 'part_of' */ | |
0bc488c9 | 223 | UNIT_UPHELD_BY, /* inverse of 'uphold' */ |
523578aa LP |
224 | |
225 | /* Negative dependencies */ | |
226 | UNIT_CONFLICTS, /* inverse of 'conflicts' is 'conflicted_by' */ | |
227 | UNIT_CONFLICTED_BY, | |
228 | ||
229 | /* Order */ | |
230 | UNIT_BEFORE, /* inverse of 'before' is 'after' and vice versa */ | |
231 | UNIT_AFTER, | |
232 | ||
294446dc LP |
233 | /* OnSuccess= + OnFailure= */ |
234 | UNIT_ON_SUCCESS, | |
235 | UNIT_ON_SUCCESS_OF, | |
523578aa | 236 | UNIT_ON_FAILURE, |
629b2a6f | 237 | UNIT_ON_FAILURE_OF, |
523578aa LP |
238 | |
239 | /* Triggers (i.e. a socket triggers a service) */ | |
240 | UNIT_TRIGGERS, | |
241 | UNIT_TRIGGERED_BY, | |
242 | ||
243 | /* Propagate reloads */ | |
244 | UNIT_PROPAGATES_RELOAD_TO, | |
245 | UNIT_RELOAD_PROPAGATED_FROM, | |
ffec78c0 LP |
246 | |
247 | /* Propagate stops */ | |
248 | UNIT_PROPAGATES_STOP_TO, | |
249 | UNIT_STOP_PROPAGATED_FROM, | |
523578aa LP |
250 | |
251 | /* Joins namespace of */ | |
252 | UNIT_JOINS_NAMESPACE_OF, | |
253 | ||
254 | /* Reference information for GC logic */ | |
255 | UNIT_REFERENCES, /* Inverse of 'references' is 'referenced_by' */ | |
256 | UNIT_REFERENCED_BY, | |
257 | ||
d219a2b0 LP |
258 | /* Slice= */ |
259 | UNIT_IN_SLICE, | |
260 | UNIT_SLICE_OF, | |
261 | ||
523578aa | 262 | _UNIT_DEPENDENCY_MAX, |
2d93c20e | 263 | _UNIT_DEPENDENCY_INVALID = -EINVAL, |
523578aa LP |
264 | } UnitDependency; |
265 | ||
266 | typedef enum NotifyAccess { | |
267 | NOTIFY_NONE, | |
268 | NOTIFY_ALL, | |
269 | NOTIFY_MAIN, | |
270 | NOTIFY_EXEC, | |
271 | _NOTIFY_ACCESS_MAX, | |
2d93c20e | 272 | _NOTIFY_ACCESS_INVALID = -EINVAL, |
523578aa LP |
273 | } NotifyAccess; |
274 | ||
275 | char *unit_dbus_path_from_name(const char *name); | |
276 | int unit_name_from_dbus_path(const char *path, char **name); | |
277 | ||
278 | const char* unit_dbus_interface_from_type(UnitType t); | |
279 | const char *unit_dbus_interface_from_name(const char *name); | |
280 | ||
281 | const char *unit_type_to_string(UnitType i) _const_; | |
282 | UnitType unit_type_from_string(const char *s) _pure_; | |
283 | ||
284 | const char *unit_load_state_to_string(UnitLoadState i) _const_; | |
285 | UnitLoadState unit_load_state_from_string(const char *s) _pure_; | |
286 | ||
287 | const char *unit_active_state_to_string(UnitActiveState i) _const_; | |
288 | UnitActiveState unit_active_state_from_string(const char *s) _pure_; | |
289 | ||
d9e45bc3 MS |
290 | const char *freezer_state_to_string(FreezerState i) _const_; |
291 | FreezerState freezer_state_from_string(const char *s) _pure_; | |
292 | ||
ff68472a ZJS |
293 | const char *unit_marker_to_string(UnitMarker m) _const_; |
294 | UnitMarker unit_marker_from_string(const char *s) _pure_; | |
295 | ||
523578aa LP |
296 | const char* automount_state_to_string(AutomountState i) _const_; |
297 | AutomountState automount_state_from_string(const char *s) _pure_; | |
298 | ||
299 | const char* device_state_to_string(DeviceState i) _const_; | |
300 | DeviceState device_state_from_string(const char *s) _pure_; | |
301 | ||
302 | const char* mount_state_to_string(MountState i) _const_; | |
303 | MountState mount_state_from_string(const char *s) _pure_; | |
304 | ||
305 | const char* path_state_to_string(PathState i) _const_; | |
306 | PathState path_state_from_string(const char *s) _pure_; | |
307 | ||
308 | const char* scope_state_to_string(ScopeState i) _const_; | |
309 | ScopeState scope_state_from_string(const char *s) _pure_; | |
310 | ||
311 | const char* service_state_to_string(ServiceState i) _const_; | |
312 | ServiceState service_state_from_string(const char *s) _pure_; | |
313 | ||
314 | const char* slice_state_to_string(SliceState i) _const_; | |
315 | SliceState slice_state_from_string(const char *s) _pure_; | |
316 | ||
317 | const char* socket_state_to_string(SocketState i) _const_; | |
318 | SocketState socket_state_from_string(const char *s) _pure_; | |
319 | ||
320 | const char* swap_state_to_string(SwapState i) _const_; | |
321 | SwapState swap_state_from_string(const char *s) _pure_; | |
322 | ||
323 | const char* target_state_to_string(TargetState i) _const_; | |
324 | TargetState target_state_from_string(const char *s) _pure_; | |
325 | ||
326 | const char *timer_state_to_string(TimerState i) _const_; | |
327 | TimerState timer_state_from_string(const char *s) _pure_; | |
328 | ||
329 | const char *unit_dependency_to_string(UnitDependency i) _const_; | |
330 | UnitDependency unit_dependency_from_string(const char *s) _pure_; | |
331 | ||
332 | const char* notify_access_to_string(NotifyAccess i) _const_; | |
333 | NotifyAccess notify_access_from_string(const char *s) _pure_; | |
9ae5fed6 J |
334 | |
335 | SpecialGlyph unit_active_state_to_glyph(UnitActiveState state); |