]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/unit-name.c
Merge pull request #6992 from keszybz/fix-test-copy
[thirdparty/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);
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 (IN_SET(*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);
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_TARGET] = "org.freedesktop.systemd1.Target",
612 [UNIT_DEVICE] = "org.freedesktop.systemd1.Device",
613 [UNIT_MOUNT] = "org.freedesktop.systemd1.Mount",
614 [UNIT_AUTOMOUNT] = "org.freedesktop.systemd1.Automount",
615 [UNIT_SWAP] = "org.freedesktop.systemd1.Swap",
616 [UNIT_TIMER] = "org.freedesktop.systemd1.Timer",
617 [UNIT_PATH] = "org.freedesktop.systemd1.Path",
618 [UNIT_SLICE] = "org.freedesktop.systemd1.Slice",
619 [UNIT_SCOPE] = "org.freedesktop.systemd1.Scope",
620 };
621
622 if (t < 0)
623 return NULL;
624 if (t >= _UNIT_TYPE_MAX)
625 return NULL;
626
627 return table[t];
628 }
629
630 const char *unit_dbus_interface_from_name(const char *name) {
631 UnitType t;
632
633 t = unit_name_to_type(name);
634 if (t < 0)
635 return NULL;
636
637 return unit_dbus_interface_from_type(t);
638 }
639
640 static char *do_escape_mangle(const char *f, UnitNameMangle allow_globs, char *t) {
641 const char *valid_chars;
642
643 assert(f);
644 assert(IN_SET(allow_globs, UNIT_NAME_GLOB, UNIT_NAME_NOGLOB));
645 assert(t);
646
647 /* We'll only escape the obvious characters here, to play
648 * safe. */
649
650 valid_chars = allow_globs == UNIT_NAME_GLOB ? VALID_CHARS_GLOB : VALID_CHARS_WITH_AT;
651
652 for (; *f; f++) {
653 if (*f == '/')
654 *(t++) = '-';
655 else if (!strchr(valid_chars, *f))
656 t = do_escape_char(*f, t);
657 else
658 *(t++) = *f;
659 }
660
661 return t;
662 }
663
664 /**
665 * Convert a string to a unit name. /dev/blah is converted to dev-blah.device,
666 * /blah/blah is converted to blah-blah.mount, anything else is left alone,
667 * except that @suffix is appended if a valid unit suffix is not present.
668 *
669 * If @allow_globs, globs characters are preserved. Otherwise, they are escaped.
670 */
671 int unit_name_mangle_with_suffix(const char *name, UnitNameMangle allow_globs, const char *suffix, char **ret) {
672 char *s, *t;
673 int r;
674
675 assert(name);
676 assert(suffix);
677 assert(ret);
678
679 if (isempty(name)) /* We cannot mangle empty unit names to become valid, sorry. */
680 return -EINVAL;
681
682 if (!unit_suffix_is_valid(suffix))
683 return -EINVAL;
684
685 /* Already a fully valid unit name? If so, no mangling is necessary... */
686 if (unit_name_is_valid(name, UNIT_NAME_ANY))
687 goto good;
688
689 /* Already a fully valid globbing expression? If so, no mangling is necessary either... */
690 if (allow_globs == UNIT_NAME_GLOB &&
691 string_is_glob(name) &&
692 in_charset(name, VALID_CHARS_GLOB))
693 goto good;
694
695 if (is_device_path(name)) {
696 r = unit_name_from_path(name, ".device", ret);
697 if (r >= 0)
698 return 1;
699 if (r != -EINVAL)
700 return r;
701 }
702
703 if (path_is_absolute(name)) {
704 r = unit_name_from_path(name, ".mount", ret);
705 if (r >= 0)
706 return 1;
707 if (r != -EINVAL)
708 return r;
709 }
710
711 s = new(char, strlen(name) * 4 + strlen(suffix) + 1);
712 if (!s)
713 return -ENOMEM;
714
715 t = do_escape_mangle(name, allow_globs, s);
716 *t = 0;
717
718 /* 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
719 * valid glob. */
720 if ((allow_globs != UNIT_NAME_GLOB || !string_is_glob(s)) && unit_name_to_type(s) < 0)
721 strcpy(t, suffix);
722
723 *ret = s;
724 return 1;
725
726 good:
727 s = strdup(name);
728 if (!s)
729 return -ENOMEM;
730
731 *ret = s;
732 return 0;
733 }
734
735 int slice_build_parent_slice(const char *slice, char **ret) {
736 char *s, *dash;
737 int r;
738
739 assert(slice);
740 assert(ret);
741
742 if (!slice_name_is_valid(slice))
743 return -EINVAL;
744
745 if (streq(slice, "-.slice")) {
746 *ret = NULL;
747 return 0;
748 }
749
750 s = strdup(slice);
751 if (!s)
752 return -ENOMEM;
753
754 dash = strrchr(s, '-');
755 if (dash)
756 strcpy(dash, ".slice");
757 else {
758 r = free_and_strdup(&s, "-.slice");
759 if (r < 0) {
760 free(s);
761 return r;
762 }
763 }
764
765 *ret = s;
766 return 1;
767 }
768
769 int slice_build_subslice(const char *slice, const char*name, char **ret) {
770 char *subslice;
771
772 assert(slice);
773 assert(name);
774 assert(ret);
775
776 if (!slice_name_is_valid(slice))
777 return -EINVAL;
778
779 if (!unit_prefix_is_valid(name))
780 return -EINVAL;
781
782 if (streq(slice, "-.slice"))
783 subslice = strappend(name, ".slice");
784 else {
785 char *e;
786
787 assert_se(e = endswith(slice, ".slice"));
788
789 subslice = new(char, (e - slice) + 1 + strlen(name) + 6 + 1);
790 if (!subslice)
791 return -ENOMEM;
792
793 stpcpy(stpcpy(stpcpy(mempcpy(subslice, slice, e - slice), "-"), name), ".slice");
794 }
795
796 *ret = subslice;
797 return 0;
798 }
799
800 bool slice_name_is_valid(const char *name) {
801 const char *p, *e;
802 bool dash = false;
803
804 if (!unit_name_is_valid(name, UNIT_NAME_PLAIN))
805 return false;
806
807 if (streq(name, "-.slice"))
808 return true;
809
810 e = endswith(name, ".slice");
811 if (!e)
812 return false;
813
814 for (p = name; p < e; p++) {
815
816 if (*p == '-') {
817
818 /* Don't allow initial dash */
819 if (p == name)
820 return false;
821
822 /* Don't allow multiple dashes */
823 if (dash)
824 return false;
825
826 dash = true;
827 } else
828 dash = false;
829 }
830
831 /* Don't allow trailing hash */
832 if (dash)
833 return false;
834
835 return true;
836 }
837
838 static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
839 [UNIT_SERVICE] = "service",
840 [UNIT_SOCKET] = "socket",
841 [UNIT_TARGET] = "target",
842 [UNIT_DEVICE] = "device",
843 [UNIT_MOUNT] = "mount",
844 [UNIT_AUTOMOUNT] = "automount",
845 [UNIT_SWAP] = "swap",
846 [UNIT_TIMER] = "timer",
847 [UNIT_PATH] = "path",
848 [UNIT_SLICE] = "slice",
849 [UNIT_SCOPE] = "scope",
850 };
851
852 DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
853
854 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
855 [UNIT_STUB] = "stub",
856 [UNIT_LOADED] = "loaded",
857 [UNIT_NOT_FOUND] = "not-found",
858 [UNIT_ERROR] = "error",
859 [UNIT_MERGED] = "merged",
860 [UNIT_MASKED] = "masked"
861 };
862
863 DEFINE_STRING_TABLE_LOOKUP(unit_load_state, UnitLoadState);
864
865 static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = {
866 [UNIT_ACTIVE] = "active",
867 [UNIT_RELOADING] = "reloading",
868 [UNIT_INACTIVE] = "inactive",
869 [UNIT_FAILED] = "failed",
870 [UNIT_ACTIVATING] = "activating",
871 [UNIT_DEACTIVATING] = "deactivating"
872 };
873
874 DEFINE_STRING_TABLE_LOOKUP(unit_active_state, UnitActiveState);
875
876 static const char* const automount_state_table[_AUTOMOUNT_STATE_MAX] = {
877 [AUTOMOUNT_DEAD] = "dead",
878 [AUTOMOUNT_WAITING] = "waiting",
879 [AUTOMOUNT_RUNNING] = "running",
880 [AUTOMOUNT_FAILED] = "failed"
881 };
882
883 DEFINE_STRING_TABLE_LOOKUP(automount_state, AutomountState);
884
885 static const char* const device_state_table[_DEVICE_STATE_MAX] = {
886 [DEVICE_DEAD] = "dead",
887 [DEVICE_TENTATIVE] = "tentative",
888 [DEVICE_PLUGGED] = "plugged",
889 };
890
891 DEFINE_STRING_TABLE_LOOKUP(device_state, DeviceState);
892
893 static const char* const mount_state_table[_MOUNT_STATE_MAX] = {
894 [MOUNT_DEAD] = "dead",
895 [MOUNT_MOUNTING] = "mounting",
896 [MOUNT_MOUNTING_DONE] = "mounting-done",
897 [MOUNT_MOUNTED] = "mounted",
898 [MOUNT_REMOUNTING] = "remounting",
899 [MOUNT_UNMOUNTING] = "unmounting",
900 [MOUNT_REMOUNTING_SIGTERM] = "remounting-sigterm",
901 [MOUNT_REMOUNTING_SIGKILL] = "remounting-sigkill",
902 [MOUNT_UNMOUNTING_SIGTERM] = "unmounting-sigterm",
903 [MOUNT_UNMOUNTING_SIGKILL] = "unmounting-sigkill",
904 [MOUNT_FAILED] = "failed"
905 };
906
907 DEFINE_STRING_TABLE_LOOKUP(mount_state, MountState);
908
909 static const char* const path_state_table[_PATH_STATE_MAX] = {
910 [PATH_DEAD] = "dead",
911 [PATH_WAITING] = "waiting",
912 [PATH_RUNNING] = "running",
913 [PATH_FAILED] = "failed"
914 };
915
916 DEFINE_STRING_TABLE_LOOKUP(path_state, PathState);
917
918 static const char* const scope_state_table[_SCOPE_STATE_MAX] = {
919 [SCOPE_DEAD] = "dead",
920 [SCOPE_RUNNING] = "running",
921 [SCOPE_ABANDONED] = "abandoned",
922 [SCOPE_STOP_SIGTERM] = "stop-sigterm",
923 [SCOPE_STOP_SIGKILL] = "stop-sigkill",
924 [SCOPE_FAILED] = "failed",
925 };
926
927 DEFINE_STRING_TABLE_LOOKUP(scope_state, ScopeState);
928
929 static const char* const service_state_table[_SERVICE_STATE_MAX] = {
930 [SERVICE_DEAD] = "dead",
931 [SERVICE_START_PRE] = "start-pre",
932 [SERVICE_START] = "start",
933 [SERVICE_START_POST] = "start-post",
934 [SERVICE_RUNNING] = "running",
935 [SERVICE_EXITED] = "exited",
936 [SERVICE_RELOAD] = "reload",
937 [SERVICE_STOP] = "stop",
938 [SERVICE_STOP_SIGABRT] = "stop-sigabrt",
939 [SERVICE_STOP_SIGTERM] = "stop-sigterm",
940 [SERVICE_STOP_SIGKILL] = "stop-sigkill",
941 [SERVICE_STOP_POST] = "stop-post",
942 [SERVICE_FINAL_SIGTERM] = "final-sigterm",
943 [SERVICE_FINAL_SIGKILL] = "final-sigkill",
944 [SERVICE_FAILED] = "failed",
945 [SERVICE_AUTO_RESTART] = "auto-restart",
946 };
947
948 DEFINE_STRING_TABLE_LOOKUP(service_state, ServiceState);
949
950 static const char* const slice_state_table[_SLICE_STATE_MAX] = {
951 [SLICE_DEAD] = "dead",
952 [SLICE_ACTIVE] = "active"
953 };
954
955 DEFINE_STRING_TABLE_LOOKUP(slice_state, SliceState);
956
957 static const char* const socket_state_table[_SOCKET_STATE_MAX] = {
958 [SOCKET_DEAD] = "dead",
959 [SOCKET_START_PRE] = "start-pre",
960 [SOCKET_START_CHOWN] = "start-chown",
961 [SOCKET_START_POST] = "start-post",
962 [SOCKET_LISTENING] = "listening",
963 [SOCKET_RUNNING] = "running",
964 [SOCKET_STOP_PRE] = "stop-pre",
965 [SOCKET_STOP_PRE_SIGTERM] = "stop-pre-sigterm",
966 [SOCKET_STOP_PRE_SIGKILL] = "stop-pre-sigkill",
967 [SOCKET_STOP_POST] = "stop-post",
968 [SOCKET_FINAL_SIGTERM] = "final-sigterm",
969 [SOCKET_FINAL_SIGKILL] = "final-sigkill",
970 [SOCKET_FAILED] = "failed"
971 };
972
973 DEFINE_STRING_TABLE_LOOKUP(socket_state, SocketState);
974
975 static const char* const swap_state_table[_SWAP_STATE_MAX] = {
976 [SWAP_DEAD] = "dead",
977 [SWAP_ACTIVATING] = "activating",
978 [SWAP_ACTIVATING_DONE] = "activating-done",
979 [SWAP_ACTIVE] = "active",
980 [SWAP_DEACTIVATING] = "deactivating",
981 [SWAP_DEACTIVATING_SIGTERM] = "deactivating-sigterm",
982 [SWAP_DEACTIVATING_SIGKILL] = "deactivating-sigkill",
983 [SWAP_FAILED] = "failed"
984 };
985
986 DEFINE_STRING_TABLE_LOOKUP(swap_state, SwapState);
987
988 static const char* const target_state_table[_TARGET_STATE_MAX] = {
989 [TARGET_DEAD] = "dead",
990 [TARGET_ACTIVE] = "active"
991 };
992
993 DEFINE_STRING_TABLE_LOOKUP(target_state, TargetState);
994
995 static const char* const timer_state_table[_TIMER_STATE_MAX] = {
996 [TIMER_DEAD] = "dead",
997 [TIMER_WAITING] = "waiting",
998 [TIMER_RUNNING] = "running",
999 [TIMER_ELAPSED] = "elapsed",
1000 [TIMER_FAILED] = "failed"
1001 };
1002
1003 DEFINE_STRING_TABLE_LOOKUP(timer_state, TimerState);
1004
1005 static const char* const unit_dependency_table[_UNIT_DEPENDENCY_MAX] = {
1006 [UNIT_REQUIRES] = "Requires",
1007 [UNIT_REQUISITE] = "Requisite",
1008 [UNIT_WANTS] = "Wants",
1009 [UNIT_BINDS_TO] = "BindsTo",
1010 [UNIT_PART_OF] = "PartOf",
1011 [UNIT_REQUIRED_BY] = "RequiredBy",
1012 [UNIT_REQUISITE_OF] = "RequisiteOf",
1013 [UNIT_WANTED_BY] = "WantedBy",
1014 [UNIT_BOUND_BY] = "BoundBy",
1015 [UNIT_CONSISTS_OF] = "ConsistsOf",
1016 [UNIT_CONFLICTS] = "Conflicts",
1017 [UNIT_CONFLICTED_BY] = "ConflictedBy",
1018 [UNIT_BEFORE] = "Before",
1019 [UNIT_AFTER] = "After",
1020 [UNIT_ON_FAILURE] = "OnFailure",
1021 [UNIT_TRIGGERS] = "Triggers",
1022 [UNIT_TRIGGERED_BY] = "TriggeredBy",
1023 [UNIT_PROPAGATES_RELOAD_TO] = "PropagatesReloadTo",
1024 [UNIT_RELOAD_PROPAGATED_FROM] = "ReloadPropagatedFrom",
1025 [UNIT_JOINS_NAMESPACE_OF] = "JoinsNamespaceOf",
1026 [UNIT_REFERENCES] = "References",
1027 [UNIT_REFERENCED_BY] = "ReferencedBy",
1028 };
1029
1030 DEFINE_STRING_TABLE_LOOKUP(unit_dependency, UnitDependency);
1031
1032 static const char* const notify_access_table[_NOTIFY_ACCESS_MAX] = {
1033 [NOTIFY_NONE] = "none",
1034 [NOTIFY_MAIN] = "main",
1035 [NOTIFY_EXEC] = "exec",
1036 [NOTIFY_ALL] = "all"
1037 };
1038
1039 DEFINE_STRING_TABLE_LOOKUP(notify_access, NotifyAccess);