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
{
45 _UNIT_TYPE_INVALID
= -1
48 typedef enum UnitLoadState
{
56 _UNIT_LOAD_STATE_INVALID
= -1
59 typedef enum UnitActiveState
{
66 _UNIT_ACTIVE_STATE_MAX
,
67 _UNIT_ACTIVE_STATE_INVALID
= -1
70 typedef enum AutomountState
{
76 _AUTOMOUNT_STATE_INVALID
= -1
79 typedef enum BusNameState
{
89 _BUSNAME_STATE_INVALID
= -1
92 /* We simply watch devices, we cannot plug/unplug them. That
93 * simplifies the state engine greatly */
94 typedef enum DeviceState
{
96 DEVICE_TENTATIVE
, /* mounted or swapped, but not (yet) announced by udev */
97 DEVICE_PLUGGED
, /* announced by udev */
99 _DEVICE_STATE_INVALID
= -1
102 typedef enum MountState
{
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. */
109 MOUNT_MOUNTING_SIGTERM
,
110 MOUNT_MOUNTING_SIGKILL
,
111 MOUNT_REMOUNTING_SIGTERM
,
112 MOUNT_REMOUNTING_SIGKILL
,
113 MOUNT_UNMOUNTING_SIGTERM
,
114 MOUNT_UNMOUNTING_SIGKILL
,
117 _MOUNT_STATE_INVALID
= -1
120 typedef enum PathState
{
126 _PATH_STATE_INVALID
= -1
129 typedef enum ScopeState
{
137 _SCOPE_STATE_INVALID
= -1
140 typedef enum ServiceState
{
146 SERVICE_EXITED
, /* Nothing is running anymore, but RemainAfterExit is true hence this is OK */
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
,
153 SERVICE_FINAL_SIGTERM
, /* In case the STOP_POST executable hangs, we shoot that down, too */
154 SERVICE_FINAL_SIGKILL
,
156 SERVICE_AUTO_RESTART
,
158 _SERVICE_STATE_INVALID
= -1
161 typedef enum SliceState
{
165 _SLICE_STATE_INVALID
= -1
168 typedef enum SnapshotState
{
172 _SNAPSHOT_STATE_INVALID
= -1
175 typedef enum SocketState
{
183 SOCKET_STOP_PRE_SIGTERM
,
184 SOCKET_STOP_PRE_SIGKILL
,
186 SOCKET_FINAL_SIGTERM
,
187 SOCKET_FINAL_SIGKILL
,
190 _SOCKET_STATE_INVALID
= -1
193 typedef enum SwapState
{
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. */
199 SWAP_ACTIVATING_SIGTERM
,
200 SWAP_ACTIVATING_SIGKILL
,
201 SWAP_DEACTIVATING_SIGTERM
,
202 SWAP_DEACTIVATING_SIGKILL
,
205 _SWAP_STATE_INVALID
= -1
209 typedef enum TargetState
{
213 _TARGET_STATE_INVALID
= -1
216 typedef enum TimerState
{
223 _TIMER_STATE_INVALID
= -1
226 typedef enum UnitDependency
{
227 /* Positive dependencies */
229 UNIT_REQUIRES_OVERRIDABLE
,
231 UNIT_REQUISITE_OVERRIDABLE
,
236 /* Inverse of the above */
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' */
241 UNIT_WANTED_BY
, /* inverse of 'wants' */
242 UNIT_BOUND_BY
, /* inverse of 'binds_to' */
243 UNIT_CONSISTS_OF
, /* inverse of 'part_of' */
245 /* Negative dependencies */
246 UNIT_CONFLICTS
, /* inverse of 'conflicts' is 'conflicted_by' */
250 UNIT_BEFORE
, /* inverse of 'before' is 'after' and vice versa */
256 /* Triggers (i.e. a socket triggers a service) */
260 /* Propagate reloads */
261 UNIT_PROPAGATES_RELOAD_TO
,
262 UNIT_RELOAD_PROPAGATED_FROM
,
264 /* Joins namespace of */
265 UNIT_JOINS_NAMESPACE_OF
,
267 /* Reference information for GC logic */
268 UNIT_REFERENCES
, /* Inverse of 'references' is 'referenced_by' */
271 _UNIT_DEPENDENCY_MAX
,
272 _UNIT_DEPENDENCY_INVALID
= -1
275 typedef 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
,
282 bool unit_name_is_valid(const char *n
, UnitNameFlags flags
) _pure_
;
283 bool unit_prefix_is_valid(const char *p
) _pure_
;
284 bool unit_instance_is_valid(const char *i
) _pure_
;
285 bool unit_suffix_is_valid(const char *s
) _pure_
;
287 static 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
);
292 int unit_name_to_prefix(const char *n
, char **prefix
);
293 int unit_name_to_instance(const char *n
, char **instance
);
294 int unit_name_to_prefix_and_instance(const char *n
, char **ret
);
296 UnitType
unit_name_to_type(const char *n
) _pure_
;
298 int unit_name_change_suffix(const char *n
, const char *suffix
, char **ret
);
300 int unit_name_build(const char *prefix
, const char *instance
, const char *suffix
, char **ret
);
302 char *unit_name_escape(const char *f
);
303 int unit_name_unescape(const char *f
, char **ret
);
304 int unit_name_path_escape(const char *f
, char **ret
);
305 int unit_name_path_unescape(const char *f
, char **ret
);
307 int unit_name_replace_instance(const char *f
, const char *i
, char **ret
);
309 int unit_name_template(const char *f
, char **ret
);
311 int unit_name_from_path(const char *path
, const char *suffix
, char **ret
);
312 int unit_name_from_path_instance(const char *prefix
, const char *path
, const char *suffix
, char **ret
);
313 int unit_name_to_path(const char *name
, char **ret
);
315 char *unit_dbus_path_from_name(const char *name
);
316 int unit_name_from_dbus_path(const char *path
, char **name
);
318 const char* unit_dbus_interface_from_type(UnitType t
);
319 const char *unit_dbus_interface_from_name(const char *name
);
321 typedef enum UnitNameMangle
{
326 int unit_name_mangle_with_suffix(const char *name
, UnitNameMangle allow_globs
, const char *suffix
, char **ret
);
328 static 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
);
332 int slice_build_parent_slice(const char *slice
, char **ret
);
333 int slice_build_subslice(const char *slice
, const char*name
, char **subslice
);
334 bool slice_name_is_valid(const char *name
);
336 const char *unit_type_to_string(UnitType i
) _const_
;
337 UnitType
unit_type_from_string(const char *s
) _pure_
;
339 const char *unit_load_state_to_string(UnitLoadState i
) _const_
;
340 UnitLoadState
unit_load_state_from_string(const char *s
) _pure_
;
342 const char *unit_active_state_to_string(UnitActiveState i
) _const_
;
343 UnitActiveState
unit_active_state_from_string(const char *s
) _pure_
;
345 const char* automount_state_to_string(AutomountState i
) _const_
;
346 AutomountState
automount_state_from_string(const char *s
) _pure_
;
348 const char* busname_state_to_string(BusNameState i
) _const_
;
349 BusNameState
busname_state_from_string(const char *s
) _pure_
;
351 const char* device_state_to_string(DeviceState i
) _const_
;
352 DeviceState
device_state_from_string(const char *s
) _pure_
;
354 const char* mount_state_to_string(MountState i
) _const_
;
355 MountState
mount_state_from_string(const char *s
) _pure_
;
357 const char* path_state_to_string(PathState i
) _const_
;
358 PathState
path_state_from_string(const char *s
) _pure_
;
360 const char* scope_state_to_string(ScopeState i
) _const_
;
361 ScopeState
scope_state_from_string(const char *s
) _pure_
;
363 const char* service_state_to_string(ServiceState i
) _const_
;
364 ServiceState
service_state_from_string(const char *s
) _pure_
;
366 const char* slice_state_to_string(SliceState i
) _const_
;
367 SliceState
slice_state_from_string(const char *s
) _pure_
;
369 const char* snapshot_state_to_string(SnapshotState i
) _const_
;
370 SnapshotState
snapshot_state_from_string(const char *s
) _pure_
;
372 const char* socket_state_to_string(SocketState i
) _const_
;
373 SocketState
socket_state_from_string(const char *s
) _pure_
;
375 const char* swap_state_to_string(SwapState i
) _const_
;
376 SwapState
swap_state_from_string(const char *s
) _pure_
;
378 const char* target_state_to_string(TargetState i
) _const_
;
379 TargetState
target_state_from_string(const char *s
) _pure_
;
381 const char *timer_state_to_string(TimerState i
) _const_
;
382 TimerState
timer_state_from_string(const char *s
) _pure_
;
384 const char *unit_dependency_to_string(UnitDependency i
) _const_
;
385 UnitDependency
unit_dependency_from_string(const char *s
) _pure_
;