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