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