]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/unit-name.h
Remove snapshot unit type
[thirdparty/systemd.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 typedef enum UnitLoadState {
48 UNIT_STUB = 0,
49 UNIT_LOADED,
50 UNIT_NOT_FOUND,
51 UNIT_ERROR,
52 UNIT_MERGED,
53 UNIT_MASKED,
54 _UNIT_LOAD_STATE_MAX,
55 _UNIT_LOAD_STATE_INVALID = -1
56 } UnitLoadState;
57
58 typedef enum UnitActiveState {
59 UNIT_ACTIVE,
60 UNIT_RELOADING,
61 UNIT_INACTIVE,
62 UNIT_FAILED,
63 UNIT_ACTIVATING,
64 UNIT_DEACTIVATING,
65 _UNIT_ACTIVE_STATE_MAX,
66 _UNIT_ACTIVE_STATE_INVALID = -1
67 } UnitActiveState;
68
69 typedef enum AutomountState {
70 AUTOMOUNT_DEAD,
71 AUTOMOUNT_WAITING,
72 AUTOMOUNT_RUNNING,
73 AUTOMOUNT_FAILED,
74 _AUTOMOUNT_STATE_MAX,
75 _AUTOMOUNT_STATE_INVALID = -1
76 } AutomountState;
77
78 typedef enum BusNameState {
79 BUSNAME_DEAD,
80 BUSNAME_MAKING,
81 BUSNAME_REGISTERED,
82 BUSNAME_LISTENING,
83 BUSNAME_RUNNING,
84 BUSNAME_SIGTERM,
85 BUSNAME_SIGKILL,
86 BUSNAME_FAILED,
87 _BUSNAME_STATE_MAX,
88 _BUSNAME_STATE_INVALID = -1
89 } BusNameState;
90
91 /* We simply watch devices, we cannot plug/unplug them. That
92 * simplifies the state engine greatly */
93 typedef enum DeviceState {
94 DEVICE_DEAD,
95 DEVICE_TENTATIVE, /* mounted or swapped, but not (yet) announced by udev */
96 DEVICE_PLUGGED, /* announced by udev */
97 _DEVICE_STATE_MAX,
98 _DEVICE_STATE_INVALID = -1
99 } DeviceState;
100
101 typedef enum MountState {
102 MOUNT_DEAD,
103 MOUNT_MOUNTING, /* /usr/bin/mount is running, but the mount is not done yet. */
104 MOUNT_MOUNTING_DONE, /* /usr/bin/mount is running, and the mount is done. */
105 MOUNT_MOUNTED,
106 MOUNT_REMOUNTING,
107 MOUNT_UNMOUNTING,
108 MOUNT_MOUNTING_SIGTERM,
109 MOUNT_MOUNTING_SIGKILL,
110 MOUNT_REMOUNTING_SIGTERM,
111 MOUNT_REMOUNTING_SIGKILL,
112 MOUNT_UNMOUNTING_SIGTERM,
113 MOUNT_UNMOUNTING_SIGKILL,
114 MOUNT_FAILED,
115 _MOUNT_STATE_MAX,
116 _MOUNT_STATE_INVALID = -1
117 } MountState;
118
119 typedef enum PathState {
120 PATH_DEAD,
121 PATH_WAITING,
122 PATH_RUNNING,
123 PATH_FAILED,
124 _PATH_STATE_MAX,
125 _PATH_STATE_INVALID = -1
126 } PathState;
127
128 typedef enum ScopeState {
129 SCOPE_DEAD,
130 SCOPE_RUNNING,
131 SCOPE_ABANDONED,
132 SCOPE_STOP_SIGTERM,
133 SCOPE_STOP_SIGKILL,
134 SCOPE_FAILED,
135 _SCOPE_STATE_MAX,
136 _SCOPE_STATE_INVALID = -1
137 } ScopeState;
138
139 typedef enum ServiceState {
140 SERVICE_DEAD,
141 SERVICE_START_PRE,
142 SERVICE_START,
143 SERVICE_START_POST,
144 SERVICE_RUNNING,
145 SERVICE_EXITED, /* Nothing is running anymore, but RemainAfterExit is true hence this is OK */
146 SERVICE_RELOAD,
147 SERVICE_STOP, /* No STOP_PRE state, instead just register multiple STOP executables */
148 SERVICE_STOP_SIGABRT, /* Watchdog timeout */
149 SERVICE_STOP_SIGTERM,
150 SERVICE_STOP_SIGKILL,
151 SERVICE_STOP_POST,
152 SERVICE_FINAL_SIGTERM, /* In case the STOP_POST executable hangs, we shoot that down, too */
153 SERVICE_FINAL_SIGKILL,
154 SERVICE_FAILED,
155 SERVICE_AUTO_RESTART,
156 _SERVICE_STATE_MAX,
157 _SERVICE_STATE_INVALID = -1
158 } ServiceState;
159
160 typedef enum SliceState {
161 SLICE_DEAD,
162 SLICE_ACTIVE,
163 _SLICE_STATE_MAX,
164 _SLICE_STATE_INVALID = -1
165 } SliceState;
166
167 typedef enum SocketState {
168 SOCKET_DEAD,
169 SOCKET_START_PRE,
170 SOCKET_START_CHOWN,
171 SOCKET_START_POST,
172 SOCKET_LISTENING,
173 SOCKET_RUNNING,
174 SOCKET_STOP_PRE,
175 SOCKET_STOP_PRE_SIGTERM,
176 SOCKET_STOP_PRE_SIGKILL,
177 SOCKET_STOP_POST,
178 SOCKET_FINAL_SIGTERM,
179 SOCKET_FINAL_SIGKILL,
180 SOCKET_FAILED,
181 _SOCKET_STATE_MAX,
182 _SOCKET_STATE_INVALID = -1
183 } SocketState;
184
185 typedef enum SwapState {
186 SWAP_DEAD,
187 SWAP_ACTIVATING, /* /sbin/swapon is running, but the swap not yet enabled. */
188 SWAP_ACTIVATING_DONE, /* /sbin/swapon is running, and the swap is done. */
189 SWAP_ACTIVE,
190 SWAP_DEACTIVATING,
191 SWAP_ACTIVATING_SIGTERM,
192 SWAP_ACTIVATING_SIGKILL,
193 SWAP_DEACTIVATING_SIGTERM,
194 SWAP_DEACTIVATING_SIGKILL,
195 SWAP_FAILED,
196 _SWAP_STATE_MAX,
197 _SWAP_STATE_INVALID = -1
198 } SwapState;
199
200
201 typedef enum TargetState {
202 TARGET_DEAD,
203 TARGET_ACTIVE,
204 _TARGET_STATE_MAX,
205 _TARGET_STATE_INVALID = -1
206 } TargetState;
207
208 typedef enum TimerState {
209 TIMER_DEAD,
210 TIMER_WAITING,
211 TIMER_RUNNING,
212 TIMER_ELAPSED,
213 TIMER_FAILED,
214 _TIMER_STATE_MAX,
215 _TIMER_STATE_INVALID = -1
216 } TimerState;
217
218 typedef enum UnitDependency {
219 /* Positive dependencies */
220 UNIT_REQUIRES,
221 UNIT_REQUIRES_OVERRIDABLE,
222 UNIT_REQUISITE,
223 UNIT_REQUISITE_OVERRIDABLE,
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_REQUIRED_BY_OVERRIDABLE, /* inverse of 'requires_overridable' is 'required_by_overridable' */
231 UNIT_REQUISITE_OF, /* inverse of 'requisite' is 'requisite_of' */
232 UNIT_REQUISITE_OF_OVERRIDABLE,/* inverse of 'requisite_overridable' is 'requisite_of_overridable' */
233 UNIT_WANTED_BY, /* inverse of 'wants' */
234 UNIT_BOUND_BY, /* inverse of 'binds_to' */
235 UNIT_CONSISTS_OF, /* inverse of 'part_of' */
236
237 /* Negative dependencies */
238 UNIT_CONFLICTS, /* inverse of 'conflicts' is 'conflicted_by' */
239 UNIT_CONFLICTED_BY,
240
241 /* Order */
242 UNIT_BEFORE, /* inverse of 'before' is 'after' and vice versa */
243 UNIT_AFTER,
244
245 /* On Failure */
246 UNIT_ON_FAILURE,
247
248 /* Triggers (i.e. a socket triggers a service) */
249 UNIT_TRIGGERS,
250 UNIT_TRIGGERED_BY,
251
252 /* Propagate reloads */
253 UNIT_PROPAGATES_RELOAD_TO,
254 UNIT_RELOAD_PROPAGATED_FROM,
255
256 /* Joins namespace of */
257 UNIT_JOINS_NAMESPACE_OF,
258
259 /* Reference information for GC logic */
260 UNIT_REFERENCES, /* Inverse of 'references' is 'referenced_by' */
261 UNIT_REFERENCED_BY,
262
263 _UNIT_DEPENDENCY_MAX,
264 _UNIT_DEPENDENCY_INVALID = -1
265 } UnitDependency;
266
267 typedef enum UnitNameFlags {
268 UNIT_NAME_PLAIN = 1, /* Allow foo.service */
269 UNIT_NAME_INSTANCE = 2, /* Allow foo@bar.service */
270 UNIT_NAME_TEMPLATE = 4, /* Allow foo@.service */
271 UNIT_NAME_ANY = UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE,
272 } UnitNameFlags;
273
274 bool unit_name_is_valid(const char *n, UnitNameFlags flags) _pure_;
275 bool unit_prefix_is_valid(const char *p) _pure_;
276 bool unit_instance_is_valid(const char *i) _pure_;
277 bool unit_suffix_is_valid(const char *s) _pure_;
278
279 static inline int unit_prefix_and_instance_is_valid(const char *p) {
280 /* For prefix+instance and instance the same rules apply */
281 return unit_instance_is_valid(p);
282 }
283
284 int unit_name_to_prefix(const char *n, char **prefix);
285 int unit_name_to_instance(const char *n, char **instance);
286 int unit_name_to_prefix_and_instance(const char *n, char **ret);
287
288 UnitType unit_name_to_type(const char *n) _pure_;
289
290 int unit_name_change_suffix(const char *n, const char *suffix, char **ret);
291
292 int unit_name_build(const char *prefix, const char *instance, const char *suffix, char **ret);
293
294 char *unit_name_escape(const char *f);
295 int unit_name_unescape(const char *f, char **ret);
296 int unit_name_path_escape(const char *f, char **ret);
297 int unit_name_path_unescape(const char *f, char **ret);
298
299 int unit_name_replace_instance(const char *f, const char *i, char **ret);
300
301 int unit_name_template(const char *f, char **ret);
302
303 int unit_name_from_path(const char *path, const char *suffix, char **ret);
304 int unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix, char **ret);
305 int unit_name_to_path(const char *name, char **ret);
306
307 char *unit_dbus_path_from_name(const char *name);
308 int unit_name_from_dbus_path(const char *path, char **name);
309
310 const char* unit_dbus_interface_from_type(UnitType t);
311 const char *unit_dbus_interface_from_name(const char *name);
312
313 typedef enum UnitNameMangle {
314 UNIT_NAME_NOGLOB,
315 UNIT_NAME_GLOB,
316 } UnitNameMangle;
317
318 int unit_name_mangle_with_suffix(const char *name, UnitNameMangle allow_globs, const char *suffix, char **ret);
319
320 static inline int unit_name_mangle(const char *name, UnitNameMangle allow_globs, char **ret) {
321 return unit_name_mangle_with_suffix(name, allow_globs, ".service", ret);
322 }
323
324 int slice_build_parent_slice(const char *slice, char **ret);
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 const char *unit_load_state_to_string(UnitLoadState i) _const_;
332 UnitLoadState unit_load_state_from_string(const char *s) _pure_;
333
334 const char *unit_active_state_to_string(UnitActiveState i) _const_;
335 UnitActiveState unit_active_state_from_string(const char *s) _pure_;
336
337 const char* automount_state_to_string(AutomountState i) _const_;
338 AutomountState automount_state_from_string(const char *s) _pure_;
339
340 const char* busname_state_to_string(BusNameState i) _const_;
341 BusNameState busname_state_from_string(const char *s) _pure_;
342
343 const char* device_state_to_string(DeviceState i) _const_;
344 DeviceState device_state_from_string(const char *s) _pure_;
345
346 const char* mount_state_to_string(MountState i) _const_;
347 MountState mount_state_from_string(const char *s) _pure_;
348
349 const char* path_state_to_string(PathState i) _const_;
350 PathState path_state_from_string(const char *s) _pure_;
351
352 const char* scope_state_to_string(ScopeState i) _const_;
353 ScopeState scope_state_from_string(const char *s) _pure_;
354
355 const char* service_state_to_string(ServiceState i) _const_;
356 ServiceState service_state_from_string(const char *s) _pure_;
357
358 const char* slice_state_to_string(SliceState i) _const_;
359 SliceState slice_state_from_string(const char *s) _pure_;
360
361 const char* socket_state_to_string(SocketState i) _const_;
362 SocketState socket_state_from_string(const char *s) _pure_;
363
364 const char* swap_state_to_string(SwapState i) _const_;
365 SwapState swap_state_from_string(const char *s) _pure_;
366
367 const char* target_state_to_string(TargetState i) _const_;
368 TargetState target_state_from_string(const char *s) _pure_;
369
370 const char *timer_state_to_string(TimerState i) _const_;
371 TimerState timer_state_from_string(const char *s) _pure_;
372
373 const char *unit_dependency_to_string(UnitDependency i) _const_;
374 UnitDependency unit_dependency_from_string(const char *s) _pure_;