1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include "alloc-util.h"
5 #include "string-table.h"
9 char *unit_dbus_path_from_name(const char *name
) {
10 _cleanup_free_
char *e
= NULL
;
14 e
= bus_label_escape(name
);
18 return strappend("/org/freedesktop/systemd1/unit/", e
);
21 int unit_name_from_dbus_path(const char *path
, char **name
) {
25 e
= startswith(path
, "/org/freedesktop/systemd1/unit/");
29 n
= bus_label_unescape(e
);
37 const char* unit_dbus_interface_from_type(UnitType t
) {
39 static const char *const table
[_UNIT_TYPE_MAX
] = {
40 [UNIT_SERVICE
] = "org.freedesktop.systemd1.Service",
41 [UNIT_SOCKET
] = "org.freedesktop.systemd1.Socket",
42 [UNIT_TARGET
] = "org.freedesktop.systemd1.Target",
43 [UNIT_DEVICE
] = "org.freedesktop.systemd1.Device",
44 [UNIT_MOUNT
] = "org.freedesktop.systemd1.Mount",
45 [UNIT_AUTOMOUNT
] = "org.freedesktop.systemd1.Automount",
46 [UNIT_SWAP
] = "org.freedesktop.systemd1.Swap",
47 [UNIT_TIMER
] = "org.freedesktop.systemd1.Timer",
48 [UNIT_PATH
] = "org.freedesktop.systemd1.Path",
49 [UNIT_SLICE
] = "org.freedesktop.systemd1.Slice",
50 [UNIT_SCOPE
] = "org.freedesktop.systemd1.Scope",
55 if (t
>= _UNIT_TYPE_MAX
)
61 const char *unit_dbus_interface_from_name(const char *name
) {
64 t
= unit_name_to_type(name
);
68 return unit_dbus_interface_from_type(t
);
71 static const char* const unit_type_table
[_UNIT_TYPE_MAX
] = {
72 [UNIT_SERVICE
] = "service",
73 [UNIT_SOCKET
] = "socket",
74 [UNIT_TARGET
] = "target",
75 [UNIT_DEVICE
] = "device",
76 [UNIT_MOUNT
] = "mount",
77 [UNIT_AUTOMOUNT
] = "automount",
79 [UNIT_TIMER
] = "timer",
81 [UNIT_SLICE
] = "slice",
82 [UNIT_SCOPE
] = "scope",
85 DEFINE_STRING_TABLE_LOOKUP(unit_type
, UnitType
);
87 static const char* const unit_load_state_table
[_UNIT_LOAD_STATE_MAX
] = {
89 [UNIT_LOADED
] = "loaded",
90 [UNIT_NOT_FOUND
] = "not-found",
91 [UNIT_BAD_SETTING
] = "bad-setting",
92 [UNIT_ERROR
] = "error",
93 [UNIT_MERGED
] = "merged",
94 [UNIT_MASKED
] = "masked"
97 DEFINE_STRING_TABLE_LOOKUP(unit_load_state
, UnitLoadState
);
99 static const char* const unit_active_state_table
[_UNIT_ACTIVE_STATE_MAX
] = {
100 [UNIT_ACTIVE
] = "active",
101 [UNIT_RELOADING
] = "reloading",
102 [UNIT_INACTIVE
] = "inactive",
103 [UNIT_FAILED
] = "failed",
104 [UNIT_ACTIVATING
] = "activating",
105 [UNIT_DEACTIVATING
] = "deactivating"
108 DEFINE_STRING_TABLE_LOOKUP(unit_active_state
, UnitActiveState
);
110 static const char* const automount_state_table
[_AUTOMOUNT_STATE_MAX
] = {
111 [AUTOMOUNT_DEAD
] = "dead",
112 [AUTOMOUNT_WAITING
] = "waiting",
113 [AUTOMOUNT_RUNNING
] = "running",
114 [AUTOMOUNT_FAILED
] = "failed"
117 DEFINE_STRING_TABLE_LOOKUP(automount_state
, AutomountState
);
119 static const char* const device_state_table
[_DEVICE_STATE_MAX
] = {
120 [DEVICE_DEAD
] = "dead",
121 [DEVICE_TENTATIVE
] = "tentative",
122 [DEVICE_PLUGGED
] = "plugged",
125 DEFINE_STRING_TABLE_LOOKUP(device_state
, DeviceState
);
127 static const char* const mount_state_table
[_MOUNT_STATE_MAX
] = {
128 [MOUNT_DEAD
] = "dead",
129 [MOUNT_MOUNTING
] = "mounting",
130 [MOUNT_MOUNTING_DONE
] = "mounting-done",
131 [MOUNT_MOUNTED
] = "mounted",
132 [MOUNT_REMOUNTING
] = "remounting",
133 [MOUNT_UNMOUNTING
] = "unmounting",
134 [MOUNT_REMOUNTING_SIGTERM
] = "remounting-sigterm",
135 [MOUNT_REMOUNTING_SIGKILL
] = "remounting-sigkill",
136 [MOUNT_UNMOUNTING_SIGTERM
] = "unmounting-sigterm",
137 [MOUNT_UNMOUNTING_SIGKILL
] = "unmounting-sigkill",
138 [MOUNT_FAILED
] = "failed"
141 DEFINE_STRING_TABLE_LOOKUP(mount_state
, MountState
);
143 static const char* const path_state_table
[_PATH_STATE_MAX
] = {
144 [PATH_DEAD
] = "dead",
145 [PATH_WAITING
] = "waiting",
146 [PATH_RUNNING
] = "running",
147 [PATH_FAILED
] = "failed"
150 DEFINE_STRING_TABLE_LOOKUP(path_state
, PathState
);
152 static const char* const scope_state_table
[_SCOPE_STATE_MAX
] = {
153 [SCOPE_DEAD
] = "dead",
154 [SCOPE_RUNNING
] = "running",
155 [SCOPE_ABANDONED
] = "abandoned",
156 [SCOPE_STOP_SIGTERM
] = "stop-sigterm",
157 [SCOPE_STOP_SIGKILL
] = "stop-sigkill",
158 [SCOPE_FAILED
] = "failed",
161 DEFINE_STRING_TABLE_LOOKUP(scope_state
, ScopeState
);
163 static const char* const service_state_table
[_SERVICE_STATE_MAX
] = {
164 [SERVICE_DEAD
] = "dead",
165 [SERVICE_START_PRE
] = "start-pre",
166 [SERVICE_START
] = "start",
167 [SERVICE_START_POST
] = "start-post",
168 [SERVICE_RUNNING
] = "running",
169 [SERVICE_EXITED
] = "exited",
170 [SERVICE_RELOAD
] = "reload",
171 [SERVICE_STOP
] = "stop",
172 [SERVICE_STOP_SIGABRT
] = "stop-sigabrt",
173 [SERVICE_STOP_SIGTERM
] = "stop-sigterm",
174 [SERVICE_STOP_SIGKILL
] = "stop-sigkill",
175 [SERVICE_STOP_POST
] = "stop-post",
176 [SERVICE_FINAL_SIGTERM
] = "final-sigterm",
177 [SERVICE_FINAL_SIGKILL
] = "final-sigkill",
178 [SERVICE_FAILED
] = "failed",
179 [SERVICE_AUTO_RESTART
] = "auto-restart",
182 DEFINE_STRING_TABLE_LOOKUP(service_state
, ServiceState
);
184 static const char* const slice_state_table
[_SLICE_STATE_MAX
] = {
185 [SLICE_DEAD
] = "dead",
186 [SLICE_ACTIVE
] = "active"
189 DEFINE_STRING_TABLE_LOOKUP(slice_state
, SliceState
);
191 static const char* const socket_state_table
[_SOCKET_STATE_MAX
] = {
192 [SOCKET_DEAD
] = "dead",
193 [SOCKET_START_PRE
] = "start-pre",
194 [SOCKET_START_CHOWN
] = "start-chown",
195 [SOCKET_START_POST
] = "start-post",
196 [SOCKET_LISTENING
] = "listening",
197 [SOCKET_RUNNING
] = "running",
198 [SOCKET_STOP_PRE
] = "stop-pre",
199 [SOCKET_STOP_PRE_SIGTERM
] = "stop-pre-sigterm",
200 [SOCKET_STOP_PRE_SIGKILL
] = "stop-pre-sigkill",
201 [SOCKET_STOP_POST
] = "stop-post",
202 [SOCKET_FINAL_SIGTERM
] = "final-sigterm",
203 [SOCKET_FINAL_SIGKILL
] = "final-sigkill",
204 [SOCKET_FAILED
] = "failed"
207 DEFINE_STRING_TABLE_LOOKUP(socket_state
, SocketState
);
209 static const char* const swap_state_table
[_SWAP_STATE_MAX
] = {
210 [SWAP_DEAD
] = "dead",
211 [SWAP_ACTIVATING
] = "activating",
212 [SWAP_ACTIVATING_DONE
] = "activating-done",
213 [SWAP_ACTIVE
] = "active",
214 [SWAP_DEACTIVATING
] = "deactivating",
215 [SWAP_DEACTIVATING_SIGTERM
] = "deactivating-sigterm",
216 [SWAP_DEACTIVATING_SIGKILL
] = "deactivating-sigkill",
217 [SWAP_FAILED
] = "failed"
220 DEFINE_STRING_TABLE_LOOKUP(swap_state
, SwapState
);
222 static const char* const target_state_table
[_TARGET_STATE_MAX
] = {
223 [TARGET_DEAD
] = "dead",
224 [TARGET_ACTIVE
] = "active"
227 DEFINE_STRING_TABLE_LOOKUP(target_state
, TargetState
);
229 static const char* const timer_state_table
[_TIMER_STATE_MAX
] = {
230 [TIMER_DEAD
] = "dead",
231 [TIMER_WAITING
] = "waiting",
232 [TIMER_RUNNING
] = "running",
233 [TIMER_ELAPSED
] = "elapsed",
234 [TIMER_FAILED
] = "failed"
237 DEFINE_STRING_TABLE_LOOKUP(timer_state
, TimerState
);
239 static const char* const unit_dependency_table
[_UNIT_DEPENDENCY_MAX
] = {
240 [UNIT_REQUIRES
] = "Requires",
241 [UNIT_REQUISITE
] = "Requisite",
242 [UNIT_WANTS
] = "Wants",
243 [UNIT_BINDS_TO
] = "BindsTo",
244 [UNIT_PART_OF
] = "PartOf",
245 [UNIT_REQUIRED_BY
] = "RequiredBy",
246 [UNIT_REQUISITE_OF
] = "RequisiteOf",
247 [UNIT_WANTED_BY
] = "WantedBy",
248 [UNIT_BOUND_BY
] = "BoundBy",
249 [UNIT_CONSISTS_OF
] = "ConsistsOf",
250 [UNIT_CONFLICTS
] = "Conflicts",
251 [UNIT_CONFLICTED_BY
] = "ConflictedBy",
252 [UNIT_BEFORE
] = "Before",
253 [UNIT_AFTER
] = "After",
254 [UNIT_ON_FAILURE
] = "OnFailure",
255 [UNIT_TRIGGERS
] = "Triggers",
256 [UNIT_TRIGGERED_BY
] = "TriggeredBy",
257 [UNIT_PROPAGATES_RELOAD_TO
] = "PropagatesReloadTo",
258 [UNIT_RELOAD_PROPAGATED_FROM
] = "ReloadPropagatedFrom",
259 [UNIT_JOINS_NAMESPACE_OF
] = "JoinsNamespaceOf",
260 [UNIT_REFERENCES
] = "References",
261 [UNIT_REFERENCED_BY
] = "ReferencedBy",
264 DEFINE_STRING_TABLE_LOOKUP(unit_dependency
, UnitDependency
);
266 static const char* const notify_access_table
[_NOTIFY_ACCESS_MAX
] = {
267 [NOTIFY_NONE
] = "none",
268 [NOTIFY_MAIN
] = "main",
269 [NOTIFY_EXEC
] = "exec",
273 DEFINE_STRING_TABLE_LOOKUP(notify_access
, NotifyAccess
);