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