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