]> git.proxmox.com Git - systemd.git/blob - src/basic/unit-name.c
Merge tag 'upstream/229'
[systemd.git] / src / basic / unit-name.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2010 Lennart Poettering
5
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.
10
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.
15
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/>.
18 ***/
19
20 #include <errno.h>
21 #include <stddef.h>
22 #include <stdint.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "alloc-util.h"
27 #include "bus-label.h"
28 #include "glob-util.h"
29 #include "hexdecoct.h"
30 #include "macro.h"
31 #include "path-util.h"
32 #include "string-table.h"
33 #include "string-util.h"
34 #include "strv.h"
35 #include "unit-name.h"
36
37 /* Characters valid in a unit name. */
38 #define VALID_CHARS \
39 DIGITS \
40 LETTERS \
41 ":-_.\\"
42
43 /* The same, but also permits the single @ character that may appear */
44 #define VALID_CHARS_WITH_AT \
45 "@" \
46 VALID_CHARS
47
48 /* All chars valid in a unit name glob */
49 #define VALID_CHARS_GLOB \
50 VALID_CHARS_WITH_AT \
51 "[]!-*?"
52
53 bool unit_name_is_valid(const char *n, UnitNameFlags flags) {
54 const char *e, *i, *at;
55
56 assert((flags & ~(UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE)) == 0);
57
58 if (_unlikely_(flags == 0))
59 return false;
60
61 if (isempty(n))
62 return false;
63
64 if (strlen(n) >= UNIT_NAME_MAX)
65 return false;
66
67 e = strrchr(n, '.');
68 if (!e || e == n)
69 return false;
70
71 if (unit_type_from_string(e + 1) < 0)
72 return false;
73
74 for (i = n, at = NULL; i < e; i++) {
75
76 if (*i == '@' && !at)
77 at = i;
78
79 if (!strchr("@" VALID_CHARS, *i))
80 return false;
81 }
82
83 if (at == n)
84 return false;
85
86 if (flags & UNIT_NAME_PLAIN)
87 if (!at)
88 return true;
89
90 if (flags & UNIT_NAME_INSTANCE)
91 if (at && e > at + 1)
92 return true;
93
94 if (flags & UNIT_NAME_TEMPLATE)
95 if (at && e == at + 1)
96 return true;
97
98 return false;
99 }
100
101 bool unit_prefix_is_valid(const char *p) {
102
103 /* We don't allow additional @ in the prefix string */
104
105 if (isempty(p))
106 return false;
107
108 return in_charset(p, VALID_CHARS);
109 }
110
111 bool unit_instance_is_valid(const char *i) {
112
113 /* The max length depends on the length of the string, so we
114 * don't really check this here. */
115
116 if (isempty(i))
117 return false;
118
119 /* We allow additional @ in the instance string, we do not
120 * allow them in the prefix! */
121
122 return in_charset(i, "@" VALID_CHARS);
123 }
124
125 bool unit_suffix_is_valid(const char *s) {
126 if (isempty(s))
127 return false;
128
129 if (s[0] != '.')
130 return false;
131
132 if (unit_type_from_string(s + 1) < 0)
133 return false;
134
135 return true;
136 }
137
138 int unit_name_to_prefix(const char *n, char **ret) {
139 const char *p;
140 char *s;
141
142 assert(n);
143 assert(ret);
144
145 if (!unit_name_is_valid(n, UNIT_NAME_ANY))
146 return -EINVAL;
147
148 p = strchr(n, '@');
149 if (!p)
150 p = strrchr(n, '.');
151
152 assert_se(p);
153
154 s = strndup(n, p - n);
155 if (!s)
156 return -ENOMEM;
157
158 *ret = s;
159 return 0;
160 }
161
162 int unit_name_to_instance(const char *n, char **instance) {
163 const char *p, *d;
164 char *i;
165
166 assert(n);
167 assert(instance);
168
169 if (!unit_name_is_valid(n, UNIT_NAME_ANY))
170 return -EINVAL;
171
172 /* Everything past the first @ and before the last . is the instance */
173 p = strchr(n, '@');
174 if (!p) {
175 *instance = NULL;
176 return 0;
177 }
178
179 p++;
180
181 d = strrchr(p, '.');
182 if (!d)
183 return -EINVAL;
184
185 i = strndup(p, d-p);
186 if (!i)
187 return -ENOMEM;
188
189 *instance = i;
190 return 1;
191 }
192
193 int unit_name_to_prefix_and_instance(const char *n, char **ret) {
194 const char *d;
195 char *s;
196
197 assert(n);
198 assert(ret);
199
200 if (!unit_name_is_valid(n, UNIT_NAME_ANY))
201 return -EINVAL;
202
203 d = strrchr(n, '.');
204 if (!d)
205 return -EINVAL;
206
207 s = strndup(n, d - n);
208 if (!s)
209 return -ENOMEM;
210
211 *ret = s;
212 return 0;
213 }
214
215 UnitType unit_name_to_type(const char *n) {
216 const char *e;
217
218 assert(n);
219
220 if (!unit_name_is_valid(n, UNIT_NAME_ANY))
221 return _UNIT_TYPE_INVALID;
222
223 assert_se(e = strrchr(n, '.'));
224
225 return unit_type_from_string(e + 1);
226 }
227
228 int unit_name_change_suffix(const char *n, const char *suffix, char **ret) {
229 char *e, *s;
230 size_t a, b;
231
232 assert(n);
233 assert(suffix);
234 assert(ret);
235
236 if (!unit_name_is_valid(n, UNIT_NAME_ANY))
237 return -EINVAL;
238
239 if (!unit_suffix_is_valid(suffix))
240 return -EINVAL;
241
242 assert_se(e = strrchr(n, '.'));
243
244 a = e - n;
245 b = strlen(suffix);
246
247 s = new(char, a + b + 1);
248 if (!s)
249 return -ENOMEM;
250
251 strcpy(mempcpy(s, n, a), suffix);
252 *ret = s;
253
254 return 0;
255 }
256
257 int unit_name_build(const char *prefix, const char *instance, const char *suffix, char **ret) {
258 char *s;
259
260 assert(prefix);
261 assert(suffix);
262 assert(ret);
263
264 if (!unit_prefix_is_valid(prefix))
265 return -EINVAL;
266
267 if (instance && !unit_instance_is_valid(instance))
268 return -EINVAL;
269
270 if (!unit_suffix_is_valid(suffix))
271 return -EINVAL;
272
273 if (!instance)
274 s = strappend(prefix, suffix);
275 else
276 s = strjoin(prefix, "@", instance, suffix, NULL);
277 if (!s)
278 return -ENOMEM;
279
280 *ret = s;
281 return 0;
282 }
283
284 static char *do_escape_char(char c, char *t) {
285 assert(t);
286
287 *(t++) = '\\';
288 *(t++) = 'x';
289 *(t++) = hexchar(c >> 4);
290 *(t++) = hexchar(c);
291
292 return t;
293 }
294
295 static char *do_escape(const char *f, char *t) {
296 assert(f);
297 assert(t);
298
299 /* do not create units with a leading '.', like for "/.dotdir" mount points */
300 if (*f == '.') {
301 t = do_escape_char(*f, t);
302 f++;
303 }
304
305 for (; *f; f++) {
306 if (*f == '/')
307 *(t++) = '-';
308 else if (*f == '-' || *f == '\\' || !strchr(VALID_CHARS, *f))
309 t = do_escape_char(*f, t);
310 else
311 *(t++) = *f;
312 }
313
314 return t;
315 }
316
317 char *unit_name_escape(const char *f) {
318 char *r, *t;
319
320 assert(f);
321
322 r = new(char, strlen(f)*4+1);
323 if (!r)
324 return NULL;
325
326 t = do_escape(f, r);
327 *t = 0;
328
329 return r;
330 }
331
332 int unit_name_unescape(const char *f, char **ret) {
333 _cleanup_free_ char *r = NULL;
334 char *t;
335
336 assert(f);
337
338 r = strdup(f);
339 if (!r)
340 return -ENOMEM;
341
342 for (t = r; *f; f++) {
343 if (*f == '-')
344 *(t++) = '/';
345 else if (*f == '\\') {
346 int a, b;
347
348 if (f[1] != 'x')
349 return -EINVAL;
350
351 a = unhexchar(f[2]);
352 if (a < 0)
353 return -EINVAL;
354
355 b = unhexchar(f[3]);
356 if (b < 0)
357 return -EINVAL;
358
359 *(t++) = (char) (((uint8_t) a << 4U) | (uint8_t) b);
360 f += 3;
361 } else
362 *(t++) = *f;
363 }
364
365 *t = 0;
366
367 *ret = r;
368 r = NULL;
369
370 return 0;
371 }
372
373 int unit_name_path_escape(const char *f, char **ret) {
374 char *p, *s;
375
376 assert(f);
377 assert(ret);
378
379 p = strdupa(f);
380 if (!p)
381 return -ENOMEM;
382
383 path_kill_slashes(p);
384
385 if (STR_IN_SET(p, "/", ""))
386 s = strdup("-");
387 else {
388 char *e;
389
390 if (!path_is_safe(p))
391 return -EINVAL;
392
393 /* Truncate trailing slashes */
394 e = endswith(p, "/");
395 if (e)
396 *e = 0;
397
398 /* Truncate leading slashes */
399 if (p[0] == '/')
400 p++;
401
402 s = unit_name_escape(p);
403 }
404 if (!s)
405 return -ENOMEM;
406
407 *ret = s;
408 return 0;
409 }
410
411 int unit_name_path_unescape(const char *f, char **ret) {
412 char *s;
413 int r;
414
415 assert(f);
416
417 if (isempty(f))
418 return -EINVAL;
419
420 if (streq(f, "-")) {
421 s = strdup("/");
422 if (!s)
423 return -ENOMEM;
424 } else {
425 char *w;
426
427 r = unit_name_unescape(f, &w);
428 if (r < 0)
429 return r;
430
431 /* Don't accept trailing or leading slashes */
432 if (startswith(w, "/") || endswith(w, "/")) {
433 free(w);
434 return -EINVAL;
435 }
436
437 /* Prefix a slash again */
438 s = strappend("/", w);
439 free(w);
440 if (!s)
441 return -ENOMEM;
442
443 if (!path_is_safe(s)) {
444 free(s);
445 return -EINVAL;
446 }
447 }
448
449 if (ret)
450 *ret = s;
451 else
452 free(s);
453
454 return 0;
455 }
456
457 int unit_name_replace_instance(const char *f, const char *i, char **ret) {
458 const char *p, *e;
459 char *s;
460 size_t a, b;
461
462 assert(f);
463 assert(i);
464 assert(ret);
465
466 if (!unit_name_is_valid(f, UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE))
467 return -EINVAL;
468 if (!unit_instance_is_valid(i))
469 return -EINVAL;
470
471 assert_se(p = strchr(f, '@'));
472 assert_se(e = strrchr(f, '.'));
473
474 a = p - f;
475 b = strlen(i);
476
477 s = new(char, a + 1 + b + strlen(e) + 1);
478 if (!s)
479 return -ENOMEM;
480
481 strcpy(mempcpy(mempcpy(s, f, a + 1), i, b), e);
482
483 *ret = s;
484 return 0;
485 }
486
487 int unit_name_template(const char *f, char **ret) {
488 const char *p, *e;
489 char *s;
490 size_t a;
491
492 assert(f);
493 assert(ret);
494
495 if (!unit_name_is_valid(f, UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE))
496 return -EINVAL;
497
498 assert_se(p = strchr(f, '@'));
499 assert_se(e = strrchr(f, '.'));
500
501 a = p - f;
502
503 s = new(char, a + 1 + strlen(e) + 1);
504 if (!s)
505 return -ENOMEM;
506
507 strcpy(mempcpy(s, f, a + 1), e);
508
509 *ret = s;
510 return 0;
511 }
512
513 int unit_name_from_path(const char *path, const char *suffix, char **ret) {
514 _cleanup_free_ char *p = NULL;
515 char *s = NULL;
516 int r;
517
518 assert(path);
519 assert(suffix);
520 assert(ret);
521
522 if (!unit_suffix_is_valid(suffix))
523 return -EINVAL;
524
525 r = unit_name_path_escape(path, &p);
526 if (r < 0)
527 return r;
528
529 s = strappend(p, suffix);
530 if (!s)
531 return -ENOMEM;
532
533 *ret = s;
534 return 0;
535 }
536
537 int unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix, char **ret) {
538 _cleanup_free_ char *p = NULL;
539 char *s;
540 int r;
541
542 assert(prefix);
543 assert(path);
544 assert(suffix);
545 assert(ret);
546
547 if (!unit_prefix_is_valid(prefix))
548 return -EINVAL;
549
550 if (!unit_suffix_is_valid(suffix))
551 return -EINVAL;
552
553 r = unit_name_path_escape(path, &p);
554 if (r < 0)
555 return r;
556
557 s = strjoin(prefix, "@", p, suffix, NULL);
558 if (!s)
559 return -ENOMEM;
560
561 *ret = s;
562 return 0;
563 }
564
565 int unit_name_to_path(const char *name, char **ret) {
566 _cleanup_free_ char *prefix = NULL;
567 int r;
568
569 assert(name);
570
571 r = unit_name_to_prefix(name, &prefix);
572 if (r < 0)
573 return r;
574
575 return unit_name_path_unescape(prefix, ret);
576 }
577
578 char *unit_dbus_path_from_name(const char *name) {
579 _cleanup_free_ char *e = NULL;
580
581 assert(name);
582
583 e = bus_label_escape(name);
584 if (!e)
585 return NULL;
586
587 return strappend("/org/freedesktop/systemd1/unit/", e);
588 }
589
590 int unit_name_from_dbus_path(const char *path, char **name) {
591 const char *e;
592 char *n;
593
594 e = startswith(path, "/org/freedesktop/systemd1/unit/");
595 if (!e)
596 return -EINVAL;
597
598 n = bus_label_unescape(e);
599 if (!n)
600 return -ENOMEM;
601
602 *name = n;
603 return 0;
604 }
605
606 const char* unit_dbus_interface_from_type(UnitType t) {
607
608 static const char *const table[_UNIT_TYPE_MAX] = {
609 [UNIT_SERVICE] = "org.freedesktop.systemd1.Service",
610 [UNIT_SOCKET] = "org.freedesktop.systemd1.Socket",
611 [UNIT_BUSNAME] = "org.freedesktop.systemd1.BusName",
612 [UNIT_TARGET] = "org.freedesktop.systemd1.Target",
613 [UNIT_DEVICE] = "org.freedesktop.systemd1.Device",
614 [UNIT_MOUNT] = "org.freedesktop.systemd1.Mount",
615 [UNIT_AUTOMOUNT] = "org.freedesktop.systemd1.Automount",
616 [UNIT_SWAP] = "org.freedesktop.systemd1.Swap",
617 [UNIT_TIMER] = "org.freedesktop.systemd1.Timer",
618 [UNIT_PATH] = "org.freedesktop.systemd1.Path",
619 [UNIT_SLICE] = "org.freedesktop.systemd1.Slice",
620 [UNIT_SCOPE] = "org.freedesktop.systemd1.Scope",
621 };
622
623 if (t < 0)
624 return NULL;
625 if (t >= _UNIT_TYPE_MAX)
626 return NULL;
627
628 return table[t];
629 }
630
631 const char *unit_dbus_interface_from_name(const char *name) {
632 UnitType t;
633
634 t = unit_name_to_type(name);
635 if (t < 0)
636 return NULL;
637
638 return unit_dbus_interface_from_type(t);
639 }
640
641 static char *do_escape_mangle(const char *f, UnitNameMangle allow_globs, char *t) {
642 const char *valid_chars;
643
644 assert(f);
645 assert(IN_SET(allow_globs, UNIT_NAME_GLOB, UNIT_NAME_NOGLOB));
646 assert(t);
647
648 /* We'll only escape the obvious characters here, to play
649 * safe. */
650
651 valid_chars = allow_globs == UNIT_NAME_GLOB ? VALID_CHARS_GLOB : VALID_CHARS_WITH_AT;
652
653 for (; *f; f++) {
654 if (*f == '/')
655 *(t++) = '-';
656 else if (!strchr(valid_chars, *f))
657 t = do_escape_char(*f, t);
658 else
659 *(t++) = *f;
660 }
661
662 return t;
663 }
664
665 /**
666 * Convert a string to a unit name. /dev/blah is converted to dev-blah.device,
667 * /blah/blah is converted to blah-blah.mount, anything else is left alone,
668 * except that @suffix is appended if a valid unit suffix is not present.
669 *
670 * If @allow_globs, globs characters are preserved. Otherwise, they are escaped.
671 */
672 int unit_name_mangle_with_suffix(const char *name, UnitNameMangle allow_globs, const char *suffix, char **ret) {
673 char *s, *t;
674 int r;
675
676 assert(name);
677 assert(suffix);
678 assert(ret);
679
680 if (isempty(name)) /* We cannot mangle empty unit names to become valid, sorry. */
681 return -EINVAL;
682
683 if (!unit_suffix_is_valid(suffix))
684 return -EINVAL;
685
686 /* Already a fully valid unit name? If so, no mangling is necessary... */
687 if (unit_name_is_valid(name, UNIT_NAME_ANY))
688 goto good;
689
690 /* Already a fully valid globbing expression? If so, no mangling is necessary either... */
691 if (allow_globs == UNIT_NAME_GLOB &&
692 string_is_glob(name) &&
693 in_charset(name, VALID_CHARS_GLOB))
694 goto good;
695
696 if (is_device_path(name)) {
697 r = unit_name_from_path(name, ".device", ret);
698 if (r >= 0)
699 return 1;
700 if (r != -EINVAL)
701 return r;
702 }
703
704 if (path_is_absolute(name)) {
705 r = unit_name_from_path(name, ".mount", ret);
706 if (r >= 0)
707 return 1;
708 if (r != -EINVAL)
709 return r;
710 }
711
712 s = new(char, strlen(name) * 4 + strlen(suffix) + 1);
713 if (!s)
714 return -ENOMEM;
715
716 t = do_escape_mangle(name, allow_globs, s);
717 *t = 0;
718
719 /* Append a suffix if it doesn't have any, but only if this is not a glob, so that we can allow "foo.*" as a
720 * valid glob. */
721 if ((allow_globs != UNIT_NAME_GLOB || !string_is_glob(s)) && unit_name_to_type(s) < 0)
722 strcpy(t, suffix);
723
724 *ret = s;
725 return 1;
726
727 good:
728 s = strdup(name);
729 if (!s)
730 return -ENOMEM;
731
732 *ret = s;
733 return 0;
734 }
735
736 int slice_build_parent_slice(const char *slice, char **ret) {
737 char *s, *dash;
738 int r;
739
740 assert(slice);
741 assert(ret);
742
743 if (!slice_name_is_valid(slice))
744 return -EINVAL;
745
746 if (streq(slice, "-.slice")) {
747 *ret = NULL;
748 return 0;
749 }
750
751 s = strdup(slice);
752 if (!s)
753 return -ENOMEM;
754
755 dash = strrchr(s, '-');
756 if (dash)
757 strcpy(dash, ".slice");
758 else {
759 r = free_and_strdup(&s, "-.slice");
760 if (r < 0) {
761 free(s);
762 return r;
763 }
764 }
765
766 *ret = s;
767 return 1;
768 }
769
770 int slice_build_subslice(const char *slice, const char*name, char **ret) {
771 char *subslice;
772
773 assert(slice);
774 assert(name);
775 assert(ret);
776
777 if (!slice_name_is_valid(slice))
778 return -EINVAL;
779
780 if (!unit_prefix_is_valid(name))
781 return -EINVAL;
782
783 if (streq(slice, "-.slice"))
784 subslice = strappend(name, ".slice");
785 else {
786 char *e;
787
788 assert_se(e = endswith(slice, ".slice"));
789
790 subslice = new(char, (e - slice) + 1 + strlen(name) + 6 + 1);
791 if (!subslice)
792 return -ENOMEM;
793
794 stpcpy(stpcpy(stpcpy(mempcpy(subslice, slice, e - slice), "-"), name), ".slice");
795 }
796
797 *ret = subslice;
798 return 0;
799 }
800
801 bool slice_name_is_valid(const char *name) {
802 const char *p, *e;
803 bool dash = false;
804
805 if (!unit_name_is_valid(name, UNIT_NAME_PLAIN))
806 return false;
807
808 if (streq(name, "-.slice"))
809 return true;
810
811 e = endswith(name, ".slice");
812 if (!e)
813 return false;
814
815 for (p = name; p < e; p++) {
816
817 if (*p == '-') {
818
819 /* Don't allow initial dash */
820 if (p == name)
821 return false;
822
823 /* Don't allow multiple dashes */
824 if (dash)
825 return false;
826
827 dash = true;
828 } else
829 dash = false;
830 }
831
832 /* Don't allow trailing hash */
833 if (dash)
834 return false;
835
836 return true;
837 }
838
839 static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
840 [UNIT_SERVICE] = "service",
841 [UNIT_SOCKET] = "socket",
842 [UNIT_BUSNAME] = "busname",
843 [UNIT_TARGET] = "target",
844 [UNIT_DEVICE] = "device",
845 [UNIT_MOUNT] = "mount",
846 [UNIT_AUTOMOUNT] = "automount",
847 [UNIT_SWAP] = "swap",
848 [UNIT_TIMER] = "timer",
849 [UNIT_PATH] = "path",
850 [UNIT_SLICE] = "slice",
851 [UNIT_SCOPE] = "scope",
852 };
853
854 DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
855
856 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
857 [UNIT_STUB] = "stub",
858 [UNIT_LOADED] = "loaded",
859 [UNIT_NOT_FOUND] = "not-found",
860 [UNIT_ERROR] = "error",
861 [UNIT_MERGED] = "merged",
862 [UNIT_MASKED] = "masked"
863 };
864
865 DEFINE_STRING_TABLE_LOOKUP(unit_load_state, UnitLoadState);
866
867 static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = {
868 [UNIT_ACTIVE] = "active",
869 [UNIT_RELOADING] = "reloading",
870 [UNIT_INACTIVE] = "inactive",
871 [UNIT_FAILED] = "failed",
872 [UNIT_ACTIVATING] = "activating",
873 [UNIT_DEACTIVATING] = "deactivating"
874 };
875
876 DEFINE_STRING_TABLE_LOOKUP(unit_active_state, UnitActiveState);
877
878 static const char* const automount_state_table[_AUTOMOUNT_STATE_MAX] = {
879 [AUTOMOUNT_DEAD] = "dead",
880 [AUTOMOUNT_WAITING] = "waiting",
881 [AUTOMOUNT_RUNNING] = "running",
882 [AUTOMOUNT_FAILED] = "failed"
883 };
884
885 DEFINE_STRING_TABLE_LOOKUP(automount_state, AutomountState);
886
887 static const char* const busname_state_table[_BUSNAME_STATE_MAX] = {
888 [BUSNAME_DEAD] = "dead",
889 [BUSNAME_MAKING] = "making",
890 [BUSNAME_REGISTERED] = "registered",
891 [BUSNAME_LISTENING] = "listening",
892 [BUSNAME_RUNNING] = "running",
893 [BUSNAME_SIGTERM] = "sigterm",
894 [BUSNAME_SIGKILL] = "sigkill",
895 [BUSNAME_FAILED] = "failed",
896 };
897
898 DEFINE_STRING_TABLE_LOOKUP(busname_state, BusNameState);
899
900 static const char* const device_state_table[_DEVICE_STATE_MAX] = {
901 [DEVICE_DEAD] = "dead",
902 [DEVICE_TENTATIVE] = "tentative",
903 [DEVICE_PLUGGED] = "plugged",
904 };
905
906 DEFINE_STRING_TABLE_LOOKUP(device_state, DeviceState);
907
908 static const char* const mount_state_table[_MOUNT_STATE_MAX] = {
909 [MOUNT_DEAD] = "dead",
910 [MOUNT_MOUNTING] = "mounting",
911 [MOUNT_MOUNTING_DONE] = "mounting-done",
912 [MOUNT_MOUNTED] = "mounted",
913 [MOUNT_REMOUNTING] = "remounting",
914 [MOUNT_UNMOUNTING] = "unmounting",
915 [MOUNT_MOUNTING_SIGTERM] = "mounting-sigterm",
916 [MOUNT_MOUNTING_SIGKILL] = "mounting-sigkill",
917 [MOUNT_REMOUNTING_SIGTERM] = "remounting-sigterm",
918 [MOUNT_REMOUNTING_SIGKILL] = "remounting-sigkill",
919 [MOUNT_UNMOUNTING_SIGTERM] = "unmounting-sigterm",
920 [MOUNT_UNMOUNTING_SIGKILL] = "unmounting-sigkill",
921 [MOUNT_FAILED] = "failed"
922 };
923
924 DEFINE_STRING_TABLE_LOOKUP(mount_state, MountState);
925
926 static const char* const path_state_table[_PATH_STATE_MAX] = {
927 [PATH_DEAD] = "dead",
928 [PATH_WAITING] = "waiting",
929 [PATH_RUNNING] = "running",
930 [PATH_FAILED] = "failed"
931 };
932
933 DEFINE_STRING_TABLE_LOOKUP(path_state, PathState);
934
935 static const char* const scope_state_table[_SCOPE_STATE_MAX] = {
936 [SCOPE_DEAD] = "dead",
937 [SCOPE_RUNNING] = "running",
938 [SCOPE_ABANDONED] = "abandoned",
939 [SCOPE_STOP_SIGTERM] = "stop-sigterm",
940 [SCOPE_STOP_SIGKILL] = "stop-sigkill",
941 [SCOPE_FAILED] = "failed",
942 };
943
944 DEFINE_STRING_TABLE_LOOKUP(scope_state, ScopeState);
945
946 static const char* const service_state_table[_SERVICE_STATE_MAX] = {
947 [SERVICE_DEAD] = "dead",
948 [SERVICE_START_PRE] = "start-pre",
949 [SERVICE_START] = "start",
950 [SERVICE_START_POST] = "start-post",
951 [SERVICE_RUNNING] = "running",
952 [SERVICE_EXITED] = "exited",
953 [SERVICE_RELOAD] = "reload",
954 [SERVICE_STOP] = "stop",
955 [SERVICE_STOP_SIGABRT] = "stop-sigabrt",
956 [SERVICE_STOP_SIGTERM] = "stop-sigterm",
957 [SERVICE_STOP_SIGKILL] = "stop-sigkill",
958 [SERVICE_STOP_POST] = "stop-post",
959 [SERVICE_FINAL_SIGTERM] = "final-sigterm",
960 [SERVICE_FINAL_SIGKILL] = "final-sigkill",
961 [SERVICE_FAILED] = "failed",
962 [SERVICE_AUTO_RESTART] = "auto-restart",
963 };
964
965 DEFINE_STRING_TABLE_LOOKUP(service_state, ServiceState);
966
967 static const char* const slice_state_table[_SLICE_STATE_MAX] = {
968 [SLICE_DEAD] = "dead",
969 [SLICE_ACTIVE] = "active"
970 };
971
972 DEFINE_STRING_TABLE_LOOKUP(slice_state, SliceState);
973
974 static const char* const socket_state_table[_SOCKET_STATE_MAX] = {
975 [SOCKET_DEAD] = "dead",
976 [SOCKET_START_PRE] = "start-pre",
977 [SOCKET_START_CHOWN] = "start-chown",
978 [SOCKET_START_POST] = "start-post",
979 [SOCKET_LISTENING] = "listening",
980 [SOCKET_RUNNING] = "running",
981 [SOCKET_STOP_PRE] = "stop-pre",
982 [SOCKET_STOP_PRE_SIGTERM] = "stop-pre-sigterm",
983 [SOCKET_STOP_PRE_SIGKILL] = "stop-pre-sigkill",
984 [SOCKET_STOP_POST] = "stop-post",
985 [SOCKET_FINAL_SIGTERM] = "final-sigterm",
986 [SOCKET_FINAL_SIGKILL] = "final-sigkill",
987 [SOCKET_FAILED] = "failed"
988 };
989
990 DEFINE_STRING_TABLE_LOOKUP(socket_state, SocketState);
991
992 static const char* const swap_state_table[_SWAP_STATE_MAX] = {
993 [SWAP_DEAD] = "dead",
994 [SWAP_ACTIVATING] = "activating",
995 [SWAP_ACTIVATING_DONE] = "activating-done",
996 [SWAP_ACTIVE] = "active",
997 [SWAP_DEACTIVATING] = "deactivating",
998 [SWAP_ACTIVATING_SIGTERM] = "activating-sigterm",
999 [SWAP_ACTIVATING_SIGKILL] = "activating-sigkill",
1000 [SWAP_DEACTIVATING_SIGTERM] = "deactivating-sigterm",
1001 [SWAP_DEACTIVATING_SIGKILL] = "deactivating-sigkill",
1002 [SWAP_FAILED] = "failed"
1003 };
1004
1005 DEFINE_STRING_TABLE_LOOKUP(swap_state, SwapState);
1006
1007 static const char* const target_state_table[_TARGET_STATE_MAX] = {
1008 [TARGET_DEAD] = "dead",
1009 [TARGET_ACTIVE] = "active"
1010 };
1011
1012 DEFINE_STRING_TABLE_LOOKUP(target_state, TargetState);
1013
1014 static const char* const timer_state_table[_TIMER_STATE_MAX] = {
1015 [TIMER_DEAD] = "dead",
1016 [TIMER_WAITING] = "waiting",
1017 [TIMER_RUNNING] = "running",
1018 [TIMER_ELAPSED] = "elapsed",
1019 [TIMER_FAILED] = "failed"
1020 };
1021
1022 DEFINE_STRING_TABLE_LOOKUP(timer_state, TimerState);
1023
1024 static const char* const unit_dependency_table[_UNIT_DEPENDENCY_MAX] = {
1025 [UNIT_REQUIRES] = "Requires",
1026 [UNIT_REQUISITE] = "Requisite",
1027 [UNIT_WANTS] = "Wants",
1028 [UNIT_BINDS_TO] = "BindsTo",
1029 [UNIT_PART_OF] = "PartOf",
1030 [UNIT_REQUIRED_BY] = "RequiredBy",
1031 [UNIT_REQUISITE_OF] = "RequisiteOf",
1032 [UNIT_WANTED_BY] = "WantedBy",
1033 [UNIT_BOUND_BY] = "BoundBy",
1034 [UNIT_CONSISTS_OF] = "ConsistsOf",
1035 [UNIT_CONFLICTS] = "Conflicts",
1036 [UNIT_CONFLICTED_BY] = "ConflictedBy",
1037 [UNIT_BEFORE] = "Before",
1038 [UNIT_AFTER] = "After",
1039 [UNIT_ON_FAILURE] = "OnFailure",
1040 [UNIT_TRIGGERS] = "Triggers",
1041 [UNIT_TRIGGERED_BY] = "TriggeredBy",
1042 [UNIT_PROPAGATES_RELOAD_TO] = "PropagatesReloadTo",
1043 [UNIT_RELOAD_PROPAGATED_FROM] = "ReloadPropagatedFrom",
1044 [UNIT_JOINS_NAMESPACE_OF] = "JoinsNamespaceOf",
1045 [UNIT_REFERENCES] = "References",
1046 [UNIT_REFERENCED_BY] = "ReferencedBy",
1047 };
1048
1049 DEFINE_STRING_TABLE_LOOKUP(unit_dependency, UnitDependency);