2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "alloc-util.h"
21 #include "bus-label.h"
22 #include "string-table.h"
24 #include "unit-name.h"
26 char *unit_dbus_path_from_name(const char *name
) {
27 _cleanup_free_
char *e
= NULL
;
31 e
= bus_label_escape(name
);
35 return strappend("/org/freedesktop/systemd1/unit/", e
);
38 int unit_name_from_dbus_path(const char *path
, char **name
) {
42 e
= startswith(path
, "/org/freedesktop/systemd1/unit/");
46 n
= bus_label_unescape(e
);
54 const char* unit_dbus_interface_from_type(UnitType t
) {
56 static const char *const table
[_UNIT_TYPE_MAX
] = {
57 [UNIT_SERVICE
] = "org.freedesktop.systemd1.Service",
58 [UNIT_SOCKET
] = "org.freedesktop.systemd1.Socket",
59 [UNIT_TARGET
] = "org.freedesktop.systemd1.Target",
60 [UNIT_DEVICE
] = "org.freedesktop.systemd1.Device",
61 [UNIT_MOUNT
] = "org.freedesktop.systemd1.Mount",
62 [UNIT_AUTOMOUNT
] = "org.freedesktop.systemd1.Automount",
63 [UNIT_SWAP
] = "org.freedesktop.systemd1.Swap",
64 [UNIT_TIMER
] = "org.freedesktop.systemd1.Timer",
65 [UNIT_PATH
] = "org.freedesktop.systemd1.Path",
66 [UNIT_SLICE
] = "org.freedesktop.systemd1.Slice",
67 [UNIT_SCOPE
] = "org.freedesktop.systemd1.Scope",
72 if (t
>= _UNIT_TYPE_MAX
)
78 const char *unit_dbus_interface_from_name(const char *name
) {
81 t
= unit_name_to_type(name
);
85 return unit_dbus_interface_from_type(t
);
88 static const char* const unit_type_table
[_UNIT_TYPE_MAX
] = {
89 [UNIT_SERVICE
] = "service",
90 [UNIT_SOCKET
] = "socket",
91 [UNIT_TARGET
] = "target",
92 [UNIT_DEVICE
] = "device",
93 [UNIT_MOUNT
] = "mount",
94 [UNIT_AUTOMOUNT
] = "automount",
96 [UNIT_TIMER
] = "timer",
98 [UNIT_SLICE
] = "slice",
99 [UNIT_SCOPE
] = "scope",
102 DEFINE_STRING_TABLE_LOOKUP(unit_type
, UnitType
);
104 static const char* const unit_load_state_table
[_UNIT_LOAD_STATE_MAX
] = {
105 [UNIT_STUB
] = "stub",
106 [UNIT_LOADED
] = "loaded",
107 [UNIT_NOT_FOUND
] = "not-found",
108 [UNIT_ERROR
] = "error",
109 [UNIT_MERGED
] = "merged",
110 [UNIT_MASKED
] = "masked"
113 DEFINE_STRING_TABLE_LOOKUP(unit_load_state
, UnitLoadState
);
115 static const char* const unit_active_state_table
[_UNIT_ACTIVE_STATE_MAX
] = {
116 [UNIT_ACTIVE
] = "active",
117 [UNIT_RELOADING
] = "reloading",
118 [UNIT_INACTIVE
] = "inactive",
119 [UNIT_FAILED
] = "failed",
120 [UNIT_ACTIVATING
] = "activating",
121 [UNIT_DEACTIVATING
] = "deactivating"
124 DEFINE_STRING_TABLE_LOOKUP(unit_active_state
, UnitActiveState
);
126 static const char* const automount_state_table
[_AUTOMOUNT_STATE_MAX
] = {
127 [AUTOMOUNT_DEAD
] = "dead",
128 [AUTOMOUNT_WAITING
] = "waiting",
129 [AUTOMOUNT_RUNNING
] = "running",
130 [AUTOMOUNT_FAILED
] = "failed"
133 DEFINE_STRING_TABLE_LOOKUP(automount_state
, AutomountState
);
135 static const char* const device_state_table
[_DEVICE_STATE_MAX
] = {
136 [DEVICE_DEAD
] = "dead",
137 [DEVICE_TENTATIVE
] = "tentative",
138 [DEVICE_PLUGGED
] = "plugged",
141 DEFINE_STRING_TABLE_LOOKUP(device_state
, DeviceState
);
143 static const char* const mount_state_table
[_MOUNT_STATE_MAX
] = {
144 [MOUNT_DEAD
] = "dead",
145 [MOUNT_MOUNTING
] = "mounting",
146 [MOUNT_MOUNTING_DONE
] = "mounting-done",
147 [MOUNT_MOUNTED
] = "mounted",
148 [MOUNT_REMOUNTING
] = "remounting",
149 [MOUNT_UNMOUNTING
] = "unmounting",
150 [MOUNT_REMOUNTING_SIGTERM
] = "remounting-sigterm",
151 [MOUNT_REMOUNTING_SIGKILL
] = "remounting-sigkill",
152 [MOUNT_UNMOUNTING_SIGTERM
] = "unmounting-sigterm",
153 [MOUNT_UNMOUNTING_SIGKILL
] = "unmounting-sigkill",
154 [MOUNT_FAILED
] = "failed"
157 DEFINE_STRING_TABLE_LOOKUP(mount_state
, MountState
);
159 static const char* const path_state_table
[_PATH_STATE_MAX
] = {
160 [PATH_DEAD
] = "dead",
161 [PATH_WAITING
] = "waiting",
162 [PATH_RUNNING
] = "running",
163 [PATH_FAILED
] = "failed"
166 DEFINE_STRING_TABLE_LOOKUP(path_state
, PathState
);
168 static const char* const scope_state_table
[_SCOPE_STATE_MAX
] = {
169 [SCOPE_DEAD
] = "dead",
170 [SCOPE_RUNNING
] = "running",
171 [SCOPE_ABANDONED
] = "abandoned",
172 [SCOPE_STOP_SIGTERM
] = "stop-sigterm",
173 [SCOPE_STOP_SIGKILL
] = "stop-sigkill",
174 [SCOPE_FAILED
] = "failed",
177 DEFINE_STRING_TABLE_LOOKUP(scope_state
, ScopeState
);
179 static const char* const service_state_table
[_SERVICE_STATE_MAX
] = {
180 [SERVICE_DEAD
] = "dead",
181 [SERVICE_START_PRE
] = "start-pre",
182 [SERVICE_START
] = "start",
183 [SERVICE_START_POST
] = "start-post",
184 [SERVICE_RUNNING
] = "running",
185 [SERVICE_EXITED
] = "exited",
186 [SERVICE_RELOAD
] = "reload",
187 [SERVICE_STOP
] = "stop",
188 [SERVICE_STOP_SIGABRT
] = "stop-sigabrt",
189 [SERVICE_STOP_SIGTERM
] = "stop-sigterm",
190 [SERVICE_STOP_SIGKILL
] = "stop-sigkill",
191 [SERVICE_STOP_POST
] = "stop-post",
192 [SERVICE_FINAL_SIGTERM
] = "final-sigterm",
193 [SERVICE_FINAL_SIGKILL
] = "final-sigkill",
194 [SERVICE_FAILED
] = "failed",
195 [SERVICE_AUTO_RESTART
] = "auto-restart",
198 DEFINE_STRING_TABLE_LOOKUP(service_state
, ServiceState
);
200 static const char* const slice_state_table
[_SLICE_STATE_MAX
] = {
201 [SLICE_DEAD
] = "dead",
202 [SLICE_ACTIVE
] = "active"
205 DEFINE_STRING_TABLE_LOOKUP(slice_state
, SliceState
);
207 static const char* const socket_state_table
[_SOCKET_STATE_MAX
] = {
208 [SOCKET_DEAD
] = "dead",
209 [SOCKET_START_PRE
] = "start-pre",
210 [SOCKET_START_CHOWN
] = "start-chown",
211 [SOCKET_START_POST
] = "start-post",
212 [SOCKET_LISTENING
] = "listening",
213 [SOCKET_RUNNING
] = "running",
214 [SOCKET_STOP_PRE
] = "stop-pre",
215 [SOCKET_STOP_PRE_SIGTERM
] = "stop-pre-sigterm",
216 [SOCKET_STOP_PRE_SIGKILL
] = "stop-pre-sigkill",
217 [SOCKET_STOP_POST
] = "stop-post",
218 [SOCKET_FINAL_SIGTERM
] = "final-sigterm",
219 [SOCKET_FINAL_SIGKILL
] = "final-sigkill",
220 [SOCKET_FAILED
] = "failed"
223 DEFINE_STRING_TABLE_LOOKUP(socket_state
, SocketState
);
225 static const char* const swap_state_table
[_SWAP_STATE_MAX
] = {
226 [SWAP_DEAD
] = "dead",
227 [SWAP_ACTIVATING
] = "activating",
228 [SWAP_ACTIVATING_DONE
] = "activating-done",
229 [SWAP_ACTIVE
] = "active",
230 [SWAP_DEACTIVATING
] = "deactivating",
231 [SWAP_DEACTIVATING_SIGTERM
] = "deactivating-sigterm",
232 [SWAP_DEACTIVATING_SIGKILL
] = "deactivating-sigkill",
233 [SWAP_FAILED
] = "failed"
236 DEFINE_STRING_TABLE_LOOKUP(swap_state
, SwapState
);
238 static const char* const target_state_table
[_TARGET_STATE_MAX
] = {
239 [TARGET_DEAD
] = "dead",
240 [TARGET_ACTIVE
] = "active"
243 DEFINE_STRING_TABLE_LOOKUP(target_state
, TargetState
);
245 static const char* const timer_state_table
[_TIMER_STATE_MAX
] = {
246 [TIMER_DEAD
] = "dead",
247 [TIMER_WAITING
] = "waiting",
248 [TIMER_RUNNING
] = "running",
249 [TIMER_ELAPSED
] = "elapsed",
250 [TIMER_FAILED
] = "failed"
253 DEFINE_STRING_TABLE_LOOKUP(timer_state
, TimerState
);
255 static const char* const unit_dependency_table
[_UNIT_DEPENDENCY_MAX
] = {
256 [UNIT_REQUIRES
] = "Requires",
257 [UNIT_REQUISITE
] = "Requisite",
258 [UNIT_WANTS
] = "Wants",
259 [UNIT_BINDS_TO
] = "BindsTo",
260 [UNIT_PART_OF
] = "PartOf",
261 [UNIT_REQUIRED_BY
] = "RequiredBy",
262 [UNIT_REQUISITE_OF
] = "RequisiteOf",
263 [UNIT_WANTED_BY
] = "WantedBy",
264 [UNIT_BOUND_BY
] = "BoundBy",
265 [UNIT_CONSISTS_OF
] = "ConsistsOf",
266 [UNIT_CONFLICTS
] = "Conflicts",
267 [UNIT_CONFLICTED_BY
] = "ConflictedBy",
268 [UNIT_BEFORE
] = "Before",
269 [UNIT_AFTER
] = "After",
270 [UNIT_ON_FAILURE
] = "OnFailure",
271 [UNIT_TRIGGERS
] = "Triggers",
272 [UNIT_TRIGGERED_BY
] = "TriggeredBy",
273 [UNIT_PROPAGATES_RELOAD_TO
] = "PropagatesReloadTo",
274 [UNIT_RELOAD_PROPAGATED_FROM
] = "ReloadPropagatedFrom",
275 [UNIT_JOINS_NAMESPACE_OF
] = "JoinsNamespaceOf",
276 [UNIT_REFERENCES
] = "References",
277 [UNIT_REFERENCED_BY
] = "ReferencedBy",
280 DEFINE_STRING_TABLE_LOOKUP(unit_dependency
, UnitDependency
);
282 static const char* const notify_access_table
[_NOTIFY_ACCESS_MAX
] = {
283 [NOTIFY_NONE
] = "none",
284 [NOTIFY_MAIN
] = "main",
285 [NOTIFY_EXEC
] = "exec",
289 DEFINE_STRING_TABLE_LOOKUP(notify_access
, NotifyAccess
);