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