chiark / gitweb /
cgroup2: use new fstype for unified hierarchy
[elogind.git] / src / basic / unit-name.h
1 #pragma once
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2010 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <stdbool.h>
23
24 #include "macro.h"
25
26 #define UNIT_NAME_MAX 256
27
28 typedef enum UnitType {
29         UNIT_SERVICE = 0,
30         UNIT_SOCKET,
31         UNIT_BUSNAME,
32         UNIT_TARGET,
33         UNIT_DEVICE,
34         UNIT_MOUNT,
35         UNIT_AUTOMOUNT,
36         UNIT_SWAP,
37         UNIT_TIMER,
38         UNIT_PATH,
39         UNIT_SLICE,
40         UNIT_SCOPE,
41         _UNIT_TYPE_MAX,
42         _UNIT_TYPE_INVALID = -1
43 } UnitType;
44
45 #if 0 /// UNNEEDED by elogind
46 typedef enum UnitLoadState {
47         UNIT_STUB = 0,
48         UNIT_LOADED,
49         UNIT_NOT_FOUND,
50         UNIT_ERROR,
51         UNIT_MERGED,
52         UNIT_MASKED,
53         _UNIT_LOAD_STATE_MAX,
54         _UNIT_LOAD_STATE_INVALID = -1
55 } UnitLoadState;
56
57 typedef enum UnitActiveState {
58         UNIT_ACTIVE,
59         UNIT_RELOADING,
60         UNIT_INACTIVE,
61         UNIT_FAILED,
62         UNIT_ACTIVATING,
63         UNIT_DEACTIVATING,
64         _UNIT_ACTIVE_STATE_MAX,
65         _UNIT_ACTIVE_STATE_INVALID = -1
66 } UnitActiveState;
67
68 typedef enum AutomountState {
69         AUTOMOUNT_DEAD,
70         AUTOMOUNT_WAITING,
71         AUTOMOUNT_RUNNING,
72         AUTOMOUNT_FAILED,
73         _AUTOMOUNT_STATE_MAX,
74         _AUTOMOUNT_STATE_INVALID = -1
75 } AutomountState;
76
77 typedef enum BusNameState {
78         BUSNAME_DEAD,
79         BUSNAME_MAKING,
80         BUSNAME_REGISTERED,
81         BUSNAME_LISTENING,
82         BUSNAME_RUNNING,
83         BUSNAME_SIGTERM,
84         BUSNAME_SIGKILL,
85         BUSNAME_FAILED,
86         _BUSNAME_STATE_MAX,
87         _BUSNAME_STATE_INVALID = -1
88 } BusNameState;
89
90 /* We simply watch devices, we cannot plug/unplug them. That
91  * simplifies the state engine greatly */
92 typedef enum DeviceState {
93         DEVICE_DEAD,
94         DEVICE_TENTATIVE, /* mounted or swapped, but not (yet) announced by udev */
95         DEVICE_PLUGGED,   /* announced by udev */
96         _DEVICE_STATE_MAX,
97         _DEVICE_STATE_INVALID = -1
98 } DeviceState;
99
100 typedef enum MountState {
101         MOUNT_DEAD,
102         MOUNT_MOUNTING,               /* /usr/bin/mount is running, but the mount is not done yet. */
103         MOUNT_MOUNTING_DONE,          /* /usr/bin/mount is running, and the mount is done. */
104         MOUNT_MOUNTED,
105         MOUNT_REMOUNTING,
106         MOUNT_UNMOUNTING,
107         MOUNT_MOUNTING_SIGTERM,
108         MOUNT_MOUNTING_SIGKILL,
109         MOUNT_REMOUNTING_SIGTERM,
110         MOUNT_REMOUNTING_SIGKILL,
111         MOUNT_UNMOUNTING_SIGTERM,
112         MOUNT_UNMOUNTING_SIGKILL,
113         MOUNT_FAILED,
114         _MOUNT_STATE_MAX,
115         _MOUNT_STATE_INVALID = -1
116 } MountState;
117
118 typedef enum PathState {
119         PATH_DEAD,
120         PATH_WAITING,
121         PATH_RUNNING,
122         PATH_FAILED,
123         _PATH_STATE_MAX,
124         _PATH_STATE_INVALID = -1
125 } PathState;
126
127 typedef enum ScopeState {
128         SCOPE_DEAD,
129         SCOPE_RUNNING,
130         SCOPE_ABANDONED,
131         SCOPE_STOP_SIGTERM,
132         SCOPE_STOP_SIGKILL,
133         SCOPE_FAILED,
134         _SCOPE_STATE_MAX,
135         _SCOPE_STATE_INVALID = -1
136 } ScopeState;
137
138 typedef enum ServiceState {
139         SERVICE_DEAD,
140         SERVICE_START_PRE,
141         SERVICE_START,
142         SERVICE_START_POST,
143         SERVICE_RUNNING,
144         SERVICE_EXITED,            /* Nothing is running anymore, but RemainAfterExit is true hence this is OK */
145         SERVICE_RELOAD,
146         SERVICE_STOP,              /* No STOP_PRE state, instead just register multiple STOP executables */
147         SERVICE_STOP_SIGABRT,      /* Watchdog timeout */
148         SERVICE_STOP_SIGTERM,
149         SERVICE_STOP_SIGKILL,
150         SERVICE_STOP_POST,
151         SERVICE_FINAL_SIGTERM,     /* In case the STOP_POST executable hangs, we shoot that down, too */
152         SERVICE_FINAL_SIGKILL,
153         SERVICE_FAILED,
154         SERVICE_AUTO_RESTART,
155         _SERVICE_STATE_MAX,
156         _SERVICE_STATE_INVALID = -1
157 } ServiceState;
158
159 typedef enum SliceState {
160         SLICE_DEAD,
161         SLICE_ACTIVE,
162         _SLICE_STATE_MAX,
163         _SLICE_STATE_INVALID = -1
164 } SliceState;
165
166 typedef enum SocketState {
167         SOCKET_DEAD,
168         SOCKET_START_PRE,
169         SOCKET_START_CHOWN,
170         SOCKET_START_POST,
171         SOCKET_LISTENING,
172         SOCKET_RUNNING,
173         SOCKET_STOP_PRE,
174         SOCKET_STOP_PRE_SIGTERM,
175         SOCKET_STOP_PRE_SIGKILL,
176         SOCKET_STOP_POST,
177         SOCKET_FINAL_SIGTERM,
178         SOCKET_FINAL_SIGKILL,
179         SOCKET_FAILED,
180         _SOCKET_STATE_MAX,
181         _SOCKET_STATE_INVALID = -1
182 } SocketState;
183
184 typedef enum SwapState {
185         SWAP_DEAD,
186         SWAP_ACTIVATING,               /* /sbin/swapon is running, but the swap not yet enabled. */
187         SWAP_ACTIVATING_DONE,          /* /sbin/swapon is running, and the swap is done. */
188         SWAP_ACTIVE,
189         SWAP_DEACTIVATING,
190         SWAP_ACTIVATING_SIGTERM,
191         SWAP_ACTIVATING_SIGKILL,
192         SWAP_DEACTIVATING_SIGTERM,
193         SWAP_DEACTIVATING_SIGKILL,
194         SWAP_FAILED,
195         _SWAP_STATE_MAX,
196         _SWAP_STATE_INVALID = -1
197 } SwapState;
198
199
200 typedef enum TargetState {
201         TARGET_DEAD,
202         TARGET_ACTIVE,
203         _TARGET_STATE_MAX,
204         _TARGET_STATE_INVALID = -1
205 } TargetState;
206
207 typedef enum TimerState {
208         TIMER_DEAD,
209         TIMER_WAITING,
210         TIMER_RUNNING,
211         TIMER_ELAPSED,
212         TIMER_FAILED,
213         _TIMER_STATE_MAX,
214         _TIMER_STATE_INVALID = -1
215 } TimerState;
216
217 typedef enum UnitDependency {
218         /* Positive dependencies */
219         UNIT_REQUIRES,
220         UNIT_REQUISITE,
221         UNIT_WANTS,
222         UNIT_BINDS_TO,
223         UNIT_PART_OF,
224
225         /* Inverse of the above */
226         UNIT_REQUIRED_BY,             /* inverse of 'requires' is 'required_by' */
227         UNIT_REQUISITE_OF,            /* inverse of 'requisite' is 'requisite_of' */
228         UNIT_WANTED_BY,               /* inverse of 'wants' */
229         UNIT_BOUND_BY,                /* inverse of 'binds_to' */
230         UNIT_CONSISTS_OF,             /* inverse of 'part_of' */
231
232         /* Negative dependencies */
233         UNIT_CONFLICTS,               /* inverse of 'conflicts' is 'conflicted_by' */
234         UNIT_CONFLICTED_BY,
235
236         /* Order */
237         UNIT_BEFORE,                  /* inverse of 'before' is 'after' and vice versa */
238         UNIT_AFTER,
239
240         /* On Failure */
241         UNIT_ON_FAILURE,
242
243         /* Triggers (i.e. a socket triggers a service) */
244         UNIT_TRIGGERS,
245         UNIT_TRIGGERED_BY,
246
247         /* Propagate reloads */
248         UNIT_PROPAGATES_RELOAD_TO,
249         UNIT_RELOAD_PROPAGATED_FROM,
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
258         _UNIT_DEPENDENCY_MAX,
259         _UNIT_DEPENDENCY_INVALID = -1
260 } UnitDependency;
261 #endif // 0
262
263 typedef enum UnitNameFlags {
264         UNIT_NAME_PLAIN = 1,      /* Allow foo.service */
265         UNIT_NAME_INSTANCE = 2,   /* Allow foo@bar.service */
266         UNIT_NAME_TEMPLATE = 4,   /* Allow foo@.service */
267         UNIT_NAME_ANY = UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE,
268 } UnitNameFlags;
269
270 bool unit_name_is_valid(const char *n, UnitNameFlags flags) _pure_;
271 bool unit_prefix_is_valid(const char *p) _pure_;
272 bool unit_instance_is_valid(const char *i) _pure_;
273 bool unit_suffix_is_valid(const char *s) _pure_;
274
275 #if 0 /// UNNEEDED by elogind
276 static inline int unit_prefix_and_instance_is_valid(const char *p) {
277         /* For prefix+instance and instance the same rules apply */
278         return unit_instance_is_valid(p);
279 }
280
281 int unit_name_to_prefix(const char *n, char **prefix);
282 int unit_name_to_instance(const char *n, char **instance);
283 int unit_name_to_prefix_and_instance(const char *n, char **ret);
284
285 UnitType unit_name_to_type(const char *n) _pure_;
286
287 int unit_name_change_suffix(const char *n, const char *suffix, char **ret);
288 #endif // 0
289
290 int unit_name_build(const char *prefix, const char *instance, const char *suffix, char **ret);
291
292 #if 0 /// UNNEEDED by elogind
293 char *unit_name_escape(const char *f);
294 int unit_name_unescape(const char *f, char **ret);
295 int unit_name_path_escape(const char *f, char **ret);
296 int unit_name_path_unescape(const char *f, char **ret);
297
298 int unit_name_replace_instance(const char *f, const char *i, char **ret);
299
300 int unit_name_template(const char *f, char **ret);
301
302 int unit_name_from_path(const char *path, const char *suffix, char **ret);
303 int unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix, char **ret);
304 int unit_name_to_path(const char *name, char **ret);
305
306 char *unit_dbus_path_from_name(const char *name);
307 int unit_name_from_dbus_path(const char *path, char **name);
308
309 const char* unit_dbus_interface_from_type(UnitType t);
310 const char *unit_dbus_interface_from_name(const char *name);
311
312 typedef enum UnitNameMangle {
313         UNIT_NAME_NOGLOB,
314         UNIT_NAME_GLOB,
315 } UnitNameMangle;
316
317 int unit_name_mangle_with_suffix(const char *name, UnitNameMangle allow_globs, const char *suffix, char **ret);
318
319 static inline int unit_name_mangle(const char *name, UnitNameMangle allow_globs, char **ret) {
320         return unit_name_mangle_with_suffix(name, allow_globs, ".service", ret);
321 }
322
323 int slice_build_parent_slice(const char *slice, char **ret);
324 #endif // 0
325 int slice_build_subslice(const char *slice, const char*name, char **subslice);
326 bool slice_name_is_valid(const char *name);
327
328 const char *unit_type_to_string(UnitType i) _const_;
329 UnitType unit_type_from_string(const char *s) _pure_;
330
331 #if 0 /// UNNEEDED by elogind
332 const char *unit_load_state_to_string(UnitLoadState i) _const_;
333 UnitLoadState unit_load_state_from_string(const char *s) _pure_;
334
335 const char *unit_active_state_to_string(UnitActiveState i) _const_;
336 UnitActiveState unit_active_state_from_string(const char *s) _pure_;
337
338 const char* automount_state_to_string(AutomountState i) _const_;
339 AutomountState automount_state_from_string(const char *s) _pure_;
340
341 const char* busname_state_to_string(BusNameState i) _const_;
342 BusNameState busname_state_from_string(const char *s) _pure_;
343
344 const char* device_state_to_string(DeviceState i) _const_;
345 DeviceState device_state_from_string(const char *s) _pure_;
346
347 const char* mount_state_to_string(MountState i) _const_;
348 MountState mount_state_from_string(const char *s) _pure_;
349
350 const char* path_state_to_string(PathState i) _const_;
351 PathState path_state_from_string(const char *s) _pure_;
352
353 const char* scope_state_to_string(ScopeState i) _const_;
354 ScopeState scope_state_from_string(const char *s) _pure_;
355
356 const char* service_state_to_string(ServiceState i) _const_;
357 ServiceState service_state_from_string(const char *s) _pure_;
358
359 const char* slice_state_to_string(SliceState i) _const_;
360 SliceState slice_state_from_string(const char *s) _pure_;
361
362 const char* socket_state_to_string(SocketState i) _const_;
363 SocketState socket_state_from_string(const char *s) _pure_;
364
365 const char* swap_state_to_string(SwapState i) _const_;
366 SwapState swap_state_from_string(const char *s) _pure_;
367
368 const char* target_state_to_string(TargetState i) _const_;
369 TargetState target_state_from_string(const char *s) _pure_;
370
371 const char *timer_state_to_string(TimerState i) _const_;
372 TimerState timer_state_from_string(const char *s) _pure_;
373
374 const char *unit_dependency_to_string(UnitDependency i) _const_;
375 UnitDependency unit_dependency_from_string(const char *s) _pure_;
376 #endif // 0