1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2010 Lennart Poettering
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.
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.
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/>.
28 #define UNIT_NAME_MAX 256
30 typedef enum UnitType {
44 _UNIT_TYPE_INVALID = -1
47 /// UNNEEDED by elogind
49 typedef enum UnitLoadState {
57 _UNIT_LOAD_STATE_INVALID = -1
60 typedef enum UnitActiveState {
67 _UNIT_ACTIVE_STATE_MAX,
68 _UNIT_ACTIVE_STATE_INVALID = -1
71 typedef enum AutomountState {
77 _AUTOMOUNT_STATE_INVALID = -1
80 typedef enum BusNameState {
90 _BUSNAME_STATE_INVALID = -1
93 /* We simply watch devices, we cannot plug/unplug them. That
94 * simplifies the state engine greatly */
95 typedef enum DeviceState {
97 DEVICE_TENTATIVE, /* mounted or swapped, but not (yet) announced by udev */
98 DEVICE_PLUGGED, /* announced by udev */
100 _DEVICE_STATE_INVALID = -1
103 typedef enum MountState {
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. */
110 MOUNT_MOUNTING_SIGTERM,
111 MOUNT_MOUNTING_SIGKILL,
112 MOUNT_REMOUNTING_SIGTERM,
113 MOUNT_REMOUNTING_SIGKILL,
114 MOUNT_UNMOUNTING_SIGTERM,
115 MOUNT_UNMOUNTING_SIGKILL,
118 _MOUNT_STATE_INVALID = -1
121 typedef enum PathState {
127 _PATH_STATE_INVALID = -1
130 typedef enum ScopeState {
138 _SCOPE_STATE_INVALID = -1
141 typedef enum ServiceState {
147 SERVICE_EXITED, /* Nothing is running anymore, but RemainAfterExit is true hence this is OK */
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,
154 SERVICE_FINAL_SIGTERM, /* In case the STOP_POST executable hangs, we shoot that down, too */
155 SERVICE_FINAL_SIGKILL,
157 SERVICE_AUTO_RESTART,
159 _SERVICE_STATE_INVALID = -1
162 typedef enum SliceState {
166 _SLICE_STATE_INVALID = -1
169 typedef enum SocketState {
177 SOCKET_STOP_PRE_SIGTERM,
178 SOCKET_STOP_PRE_SIGKILL,
180 SOCKET_FINAL_SIGTERM,
181 SOCKET_FINAL_SIGKILL,
184 _SOCKET_STATE_INVALID = -1
187 typedef enum SwapState {
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. */
193 SWAP_ACTIVATING_SIGTERM,
194 SWAP_ACTIVATING_SIGKILL,
195 SWAP_DEACTIVATING_SIGTERM,
196 SWAP_DEACTIVATING_SIGKILL,
199 _SWAP_STATE_INVALID = -1
203 typedef enum TargetState {
207 _TARGET_STATE_INVALID = -1
210 typedef enum TimerState {
217 _TIMER_STATE_INVALID = -1
220 typedef enum UnitDependency {
221 /* Positive dependencies */
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' */
235 /* Negative dependencies */
236 UNIT_CONFLICTS, /* inverse of 'conflicts' is 'conflicted_by' */
240 UNIT_BEFORE, /* inverse of 'before' is 'after' and vice versa */
246 /* Triggers (i.e. a socket triggers a service) */
250 /* Propagate reloads */
251 UNIT_PROPAGATES_RELOAD_TO,
252 UNIT_RELOAD_PROPAGATED_FROM,
254 /* Joins namespace of */
255 UNIT_JOINS_NAMESPACE_OF,
257 /* Reference information for GC logic */
258 UNIT_REFERENCES, /* Inverse of 'references' is 'referenced_by' */
261 _UNIT_DEPENDENCY_MAX,
262 _UNIT_DEPENDENCY_INVALID = -1
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,
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_;
278 /// UNNEEDED by elogind
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);
285 int unit_name_to_prefix(const char *n, char **prefix);
286 int unit_name_to_instance(const char *n, char **instance);
287 int unit_name_to_prefix_and_instance(const char *n, char **ret);
289 UnitType unit_name_to_type(const char *n) _pure_;
291 int unit_name_change_suffix(const char *n, const char *suffix, char **ret);
294 int unit_name_build(const char *prefix, const char *instance, const char *suffix, char **ret);
296 /// UNNEEDED by elogind
298 char *unit_name_escape(const char *f);
299 int unit_name_unescape(const char *f, char **ret);
300 int unit_name_path_escape(const char *f, char **ret);
301 int unit_name_path_unescape(const char *f, char **ret);
303 int unit_name_replace_instance(const char *f, const char *i, char **ret);
305 int unit_name_template(const char *f, char **ret);
307 int unit_name_from_path(const char *path, const char *suffix, char **ret);
308 int unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix, char **ret);
309 int unit_name_to_path(const char *name, char **ret);
311 char *unit_dbus_path_from_name(const char *name);
312 int unit_name_from_dbus_path(const char *path, char **name);
314 const char* unit_dbus_interface_from_type(UnitType t);
315 const char *unit_dbus_interface_from_name(const char *name);
317 typedef enum UnitNameMangle {
322 int unit_name_mangle_with_suffix(const char *name, UnitNameMangle allow_globs, const char *suffix, char **ret);
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);
328 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);
333 const char *unit_type_to_string(UnitType i) _const_;
334 UnitType unit_type_from_string(const char *s) _pure_;
336 /// UNNEEDED by elogind
338 const char *unit_load_state_to_string(UnitLoadState i) _const_;
339 UnitLoadState unit_load_state_from_string(const char *s) _pure_;
341 const char *unit_active_state_to_string(UnitActiveState i) _const_;
342 UnitActiveState unit_active_state_from_string(const char *s) _pure_;
344 const char* automount_state_to_string(AutomountState i) _const_;
345 AutomountState automount_state_from_string(const char *s) _pure_;
347 const char* busname_state_to_string(BusNameState i) _const_;
348 BusNameState busname_state_from_string(const char *s) _pure_;
350 const char* device_state_to_string(DeviceState i) _const_;
351 DeviceState device_state_from_string(const char *s) _pure_;
353 const char* mount_state_to_string(MountState i) _const_;
354 MountState mount_state_from_string(const char *s) _pure_;
356 const char* path_state_to_string(PathState i) _const_;
357 PathState path_state_from_string(const char *s) _pure_;
359 const char* scope_state_to_string(ScopeState i) _const_;
360 ScopeState scope_state_from_string(const char *s) _pure_;
362 const char* service_state_to_string(ServiceState i) _const_;
363 ServiceState service_state_from_string(const char *s) _pure_;
365 const char* slice_state_to_string(SliceState i) _const_;
366 SliceState slice_state_from_string(const char *s) _pure_;
368 const char* socket_state_to_string(SocketState i) _const_;
369 SocketState socket_state_from_string(const char *s) _pure_;
371 const char* swap_state_to_string(SwapState i) _const_;
372 SwapState swap_state_from_string(const char *s) _pure_;
374 const char* target_state_to_string(TargetState i) _const_;
375 TargetState target_state_from_string(const char *s) _pure_;
377 const char *timer_state_to_string(TimerState i) _const_;
378 TimerState timer_state_from_string(const char *s) _pure_;
380 const char *unit_dependency_to_string(UnitDependency i) _const_;
381 UnitDependency unit_dependency_from_string(const char *s) _pure_;