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