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