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