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