load-fragment.c 62.8 KB
Newer Older
1
2
/*-*- Mode: C; c-basic-offset: 8 -*-*/

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/***
  This file is part of systemd.

  Copyright 2010 Lennart Poettering

  systemd is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  systemd is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/

Lennart Poettering's avatar
Lennart Poettering committed
22
#include <linux/oom.h>
23
24
25
#include <assert.h>
#include <errno.h>
#include <string.h>
Lennart Poettering's avatar
Lennart Poettering committed
26
27
#include <unistd.h>
#include <fcntl.h>
28
29
#include <sched.h>
#include <sys/prctl.h>
30
#include <sys/mount.h>
Kay Sievers's avatar
Kay Sievers committed
31
#include <linux/fs.h>
32

Lennart Poettering's avatar
Lennart Poettering committed
33
#include "unit.h"
34
35
36
#include "strv.h"
#include "conf-parser.h"
#include "load-fragment.h"
37
#include "log.h"
38
#include "ioprio.h"
39
40
#include "securebits.h"
#include "missing.h"
41
#include "unit-name.h"
42

43
44
45
#define COMMENTS "#;\n"
#define LINE_MAX 4096

46
static int config_parse_deps(
47
48
49
50
51
52
53
54
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

Lennart Poettering's avatar
Lennart Poettering committed
55
56
        UnitDependency d = PTR_TO_UINT(data);
        Unit *u = userdata;
57
58
59
60
61
62
63
64
        char *w;
        size_t l;
        char *state;

        assert(filename);
        assert(lvalue);
        assert(rvalue);

65
        FOREACH_WORD(w, l, rvalue, state) {
66
                char *t, *k;
67
68
69
70
71
                int r;

                if (!(t = strndup(w, l)))
                        return -ENOMEM;

72
                k = unit_name_printf(u, t);
73
74
                free(t);

75
76
77
                if (!k)
                        return -ENOMEM;

78
                r = unit_add_dependency_by_name(u, d, k, NULL, true);
79
80
                free(k);

81
82
83
84
85
86
87
                if (r < 0)
                        return r;
        }

        return 0;
}

88
static int config_parse_names(
89
90
91
92
93
94
95
96
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

Lennart Poettering's avatar
Lennart Poettering committed
97
        Unit *u = userdata;
98
99
100
101
102
103
104
105
106
        char *w;
        size_t l;
        char *state;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

107
        FOREACH_WORD(w, l, rvalue, state) {
108
                char *t, *k;
109
110
111
112
113
                int r;

                if (!(t = strndup(w, l)))
                        return -ENOMEM;

114
                k = unit_name_printf(u, t);
115
                free(t);
116

117
118
119
120
121
122
                if (!k)
                        return -ENOMEM;

                r = unit_merge_by_name(u, k);
                free(k);

123
124
                if (r < 0)
                        return r;
125
126
127
128
129
        }

        return 0;
}

130
static int config_parse_string_printf(
131
132
133
134
135
136
137
138
139
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        Unit *u = userdata;
140
        char **s = data;
141
142
143
144
145
        char *k;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
146
147
        assert(s);
        assert(u);
148
149
150
151

        if (!(k = unit_full_printf(u, rvalue)))
                return -ENOMEM;

152
        free(*s);
153
        if (*k)
154
                *s = k;
155
156
        else {
                free(k);
157
                *s = NULL;
158
159
160
161
162
        }

        return 0;
}

163
164
165
166
167
168
169
170
171
static int config_parse_listen(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

172
        int r;
Lennart Poettering's avatar
Lennart Poettering committed
173
174
        SocketPort *p;
        Socket *s;
175

176
177
178
179
180
        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

Lennart Poettering's avatar
Lennart Poettering committed
181
182
183
184
185
186
187
188
189
190
191
192
        s = (Socket*) data;

        if (!(p = new0(SocketPort, 1)))
                return -ENOMEM;

        if (streq(lvalue, "ListenFIFO")) {
                p->type = SOCKET_FIFO;

                if (!(p->path = strdup(rvalue))) {
                        free(p);
                        return -ENOMEM;
                }
193
194

                path_kill_slashes(p->path);
Lennart Poettering's avatar
Lennart Poettering committed
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
        } else {
                p->type = SOCKET_SOCKET;

                if ((r = socket_address_parse(&p->address, rvalue)) < 0) {
                        log_error("[%s:%u] Failed to parse address value: %s", filename, line, rvalue);
                        free(p);
                        return r;
                }

                if (streq(lvalue, "ListenStream"))
                        p->address.type = SOCK_STREAM;
                else if (streq(lvalue, "ListenDatagram"))
                        p->address.type = SOCK_DGRAM;
                else {
                        assert(streq(lvalue, "ListenSequentialPacket"));
                        p->address.type = SOCK_SEQPACKET;
                }

                if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) {
                        free(p);
                        return -EPROTONOSUPPORT;
                }
217
218
        }

Lennart Poettering's avatar
Lennart Poettering committed
219
        p->fd = -1;
220
        LIST_PREPEND(SocketPort, port, s->ports, p);
Lennart Poettering's avatar
Lennart Poettering committed
221

222
        return 0;
223
224
}

225
static int config_parse_socket_bind(
226
227
228
229
230
231
232
233
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

Lennart Poettering's avatar
Lennart Poettering committed
234
        Socket *s;
235
        SocketAddressBindIPv6Only b;
236
237
238
239
240
241

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

Lennart Poettering's avatar
Lennart Poettering committed
242
243
        s = (Socket*) data;

244
245
246
247
248
249
250
        if ((b = socket_address_bind_ipv6_only_from_string(rvalue)) < 0) {
                int r;

                if ((r = parse_boolean(rvalue)) < 0) {
                        log_error("[%s:%u] Failed to parse bind IPv6 only value: %s", filename, line, rvalue);
                        return -EBADMSG;
                }
251

252
253
254
                s->bind_ipv6_only = r ? SOCKET_ADDRESS_IPV6_ONLY : SOCKET_ADDRESS_BOTH;
        } else
                s->bind_ipv6_only = b;
Lennart Poettering's avatar
Lennart Poettering committed
255

256
257
258
        return 0;
}

259
260
261
262
263
264
265
266
267
static int config_parse_nice(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

268
269
        ExecContext *c = data;
        int priority, r;
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        if ((r = safe_atoi(rvalue, &priority)) < 0) {
                log_error("[%s:%u] Failed to parse nice priority: %s", filename, line, rvalue);
                return r;
        }

        if (priority < PRIO_MIN || priority >= PRIO_MAX) {
                log_error("[%s:%u] Nice priority out of range: %s", filename, line, rvalue);
                return -ERANGE;
        }

286
287
288
        c->nice = priority;
        c->nice_set = false;

289
290
291
292
293
294
295
296
297
298
299
300
        return 0;
}

static int config_parse_oom_adjust(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

301
302
        ExecContext *c = data;
        int oa, r;
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        if ((r = safe_atoi(rvalue, &oa)) < 0) {
                log_error("[%s:%u] Failed to parse OOM adjust value: %s", filename, line, rvalue);
                return r;
        }

        if (oa < OOM_DISABLE || oa > OOM_ADJUST_MAX) {
                log_error("[%s:%u] OOM adjust value out of range: %s", filename, line, rvalue);
                return -ERANGE;
        }

319
320
321
        c->oom_adjust = oa;
        c->oom_adjust_set = true;

322
323
324
        return 0;
}

325
static int config_parse_mode(
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        mode_t *m = data;
        long l;
        char *x = NULL;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        errno = 0;
        l = strtol(rvalue, &x, 8);
        if (!x || *x || errno) {
346
                log_error("[%s:%u] Failed to parse mode value: %s", filename, line, rvalue);
347
348
349
                return errno ? -errno : -EINVAL;
        }

350
351
        if (l < 0000 || l > 07777) {
                log_error("[%s:%u] mode value out of range: %s", filename, line, rvalue);
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
                return -ERANGE;
        }

        *m = (mode_t) l;
        return 0;
}

static int config_parse_exec(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

368
        ExecCommand **e = data, *nce = NULL;
369
370
371
372
        char **n;
        char *w;
        unsigned k;
        size_t l;
373
374
        char *state, *path = NULL;
        bool honour_argv0, write_to_path;
375
376
377
378
379
380

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

381
382
383
384
385
386
387
388
389
390
391
        /* We accept an absolute path as first argument, or
         * alternatively an absolute prefixed with @ to allow
         * overriding of argv[0]. */

        honour_argv0 = rvalue[0] == '@';

        if (rvalue[honour_argv0 ? 1 : 0] != '/') {
                log_error("[%s:%u] Invalid executable path in command line: %s", filename, line, rvalue);
                return -EINVAL;
        }

392
393
394
395
        k = 0;
        FOREACH_WORD_QUOTED(w, l, rvalue, state)
                k++;

396
        if (!(n = new(char*, k + (honour_argv0 ? 0 : 1))))
397
398
                return -ENOMEM;

Lennart Poettering's avatar
Lennart Poettering committed
399
        k = 0;
400
401
402
403
404
405
406
407
408
409
410
        write_to_path = honour_argv0;
        FOREACH_WORD_QUOTED(w, l, rvalue, state) {
                if (write_to_path) {
                        if (!(path = strndup(w+1, l-1)))
                                goto fail;
                        write_to_path = false;
                } else {
                        if (!(n[k++] = strndup(w, l)))
                                goto fail;
                }
        }
411
412
413

        n[k] = NULL;

414
415
        if (!n[0]) {
                log_error("[%s:%u] Invalid command line: %s", filename, line, rvalue);
416
417
418
419
                strv_free(n);
                return -EINVAL;
        }

420
421
422
423
424
425
        if (!path)
                if (!(path = strdup(n[0])))
                        goto fail;

        assert(path_is_absolute(path));

426
427
428
429
        if (!(nce = new0(ExecCommand, 1)))
                goto fail;

        nce->argv = n;
430
        nce->path = path;
431

432
433
        path_kill_slashes(nce->path);

434
        exec_command_append_list(e, nce);
435
436
437
438

        return 0;

fail:
439
440
441
        n[k] = NULL;
        strv_free(n);
        free(path);
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
        free(nce);

        return -ENOMEM;
}

static int config_parse_usec(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        usec_t *usec = data;
        int r;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

464
        if ((r = parse_usec(rvalue, usec)) < 0) {
465
466
467
468
469
470
471
                log_error("[%s:%u] Failed to parse time value: %s", filename, line, rvalue);
                return r;
        }

        return 0;
}

472
473
static DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type");
static DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier");
474

475
static int config_parse_bindtodevice(
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        Socket *s = data;
        char *n;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        if (rvalue[0] && !streq(rvalue, "*")) {
                if (!(n = strdup(rvalue)))
                        return -ENOMEM;
        } else
                n = NULL;

        free(s->bind_to_device);
        s->bind_to_device = n;

        return 0;
}

504
505
static DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier");
static DEFINE_CONFIG_PARSE_ENUM(config_parse_input, exec_input, ExecInput, "Failed to parse input specifier");
Lennart Poettering's avatar
Lennart Poettering committed
506

507
static int config_parse_facility(
508
509
510
511
512
513
514
515
516
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {


517
        int *o = data, x;
518
519
520
521
522
523

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

524
525
526
527
        if ((x = log_facility_from_string(rvalue)) < 0) {
                log_error("[%s:%u] Failed to parse log facility: %s", filename, line, rvalue);
                return -EBADMSG;
        }
528
529

        *o = LOG_MAKEPRI(x, LOG_PRI(*o));
530
531
532
533

        return 0;
}

534
static int config_parse_level(
535
536
537
538
539
540
541
542
543
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {


544
        int *o = data, x;
545
546
547
548
549
550

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

551
552
553
554
        if ((x = log_level_from_string(rvalue)) < 0) {
                log_error("[%s:%u] Failed to parse log level: %s", filename, line, rvalue);
                return -EBADMSG;
        }
555

556
557
558
559
        *o = LOG_MAKEPRI(LOG_FAC(*o), x);
        return 0;
}

560
static int config_parse_io_class(
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        ExecContext *c = data;
        int x;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

577
578
579
580
        if ((x = ioprio_class_from_string(rvalue)) < 0) {
                log_error("[%s:%u] Failed to parse IO scheduling class: %s", filename, line, rvalue);
                return -EBADMSG;
        }
581
582
583
584
585
586
587

        c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio));
        c->ioprio_set = true;

        return 0;
}

588
static int config_parse_io_priority(
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        ExecContext *c = data;
        int i;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        if (safe_atoi(rvalue, &i) < 0 || i < 0 || i >= IOPRIO_BE_NR) {
                log_error("[%s:%u] Failed to parse io priority: %s", filename, line, rvalue);
                return -EBADMSG;
608
609
        }

610
611
612
        c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i);
        c->ioprio_set = true;

613
614
615
        return 0;
}

616
static int config_parse_cpu_sched_policy(
617
618
619
620
621
622
623
624
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

625
626
627
628
629
630
631
632
633

        ExecContext *c = data;
        int x;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

634
635
636
637
        if ((x = sched_policy_from_string(rvalue)) < 0) {
                log_error("[%s:%u] Failed to parse CPU scheduling policy: %s", filename, line, rvalue);
                return -EBADMSG;
        }
638
639
640
641
642
643
644

        c->cpu_sched_policy = x;
        c->cpu_sched_set = true;

        return 0;
}

645
static int config_parse_cpu_sched_prio(
646
647
648
649
650
651
652
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {
653
654
655
656
657
658
659
660
661

        ExecContext *c = data;
        int i;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

662
663
664
665
666
        /* On Linux RR/FIFO have the same range */
        if (safe_atoi(rvalue, &i) < 0 || i < sched_get_priority_min(SCHED_RR) || i > sched_get_priority_max(SCHED_RR)) {
                log_error("[%s:%u] Failed to parse CPU scheduling priority: %s", filename, line, rvalue);
                return -EBADMSG;
        }
667

668
669
670
671
672
673
        c->cpu_sched_priority = i;
        c->cpu_sched_set = true;

        return 0;
}

674
static int config_parse_cpu_affinity(
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        ExecContext *c = data;
        char *w;
        size_t l;
        char *state;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

693
        FOREACH_WORD(w, l, rvalue, state) {
694
695
696
697
698
699
700
                char *t;
                int r;
                unsigned cpu;

                if (!(t = strndup(w, l)))
                        return -ENOMEM;

701
702
703
                r = safe_atou(t, &cpu);
                free(t);

704
705
706
707
708
                if (!(c->cpuset))
                        if (!(c->cpuset = cpu_set_malloc(&c->cpuset_ncpus)))
                                return -ENOMEM;

                if (r < 0 || cpu >= c->cpuset_ncpus) {
709
710
                        log_error("[%s:%u] Failed to parse CPU affinity: %s", filename, line, rvalue);
                        return -EBADMSG;
711
                }
712

713
                CPU_SET_S(cpu, CPU_ALLOC_SIZE(c->cpuset_ncpus), c->cpuset);
714
715
        }

716
717
718
        return 0;
}

719
static int config_parse_capabilities(
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        ExecContext *c = data;
        cap_t cap;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        if (!(cap = cap_from_text(rvalue))) {
                if (errno == ENOMEM)
                        return -ENOMEM;

                log_error("[%s:%u] Failed to parse capabilities: %s", filename, line, rvalue);
                return -EBADMSG;
        }

        if (c->capabilities)
                cap_free(c->capabilities);
        c->capabilities = cap;

        return 0;
}

751
static int config_parse_secure_bits(
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        ExecContext *c = data;
        char *w;
        size_t l;
        char *state;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

770
        FOREACH_WORD(w, l, rvalue, state) {
771
772
773
774
775
776
777
778
779
780
781
782
                if (first_word(w, "keep-caps"))
                        c->secure_bits |= SECURE_KEEP_CAPS;
                else if (first_word(w, "keep-caps-locked"))
                        c->secure_bits |= SECURE_KEEP_CAPS_LOCKED;
                else if (first_word(w, "no-setuid-fixup"))
                        c->secure_bits |= SECURE_NO_SETUID_FIXUP;
                else if (first_word(w, "no-setuid-fixup-locked"))
                        c->secure_bits |= SECURE_NO_SETUID_FIXUP_LOCKED;
                else if (first_word(w, "noroot"))
                        c->secure_bits |= SECURE_NOROOT;
                else if (first_word(w, "noroot-locked"))
                        c->secure_bits |= SECURE_NOROOT_LOCKED;
783
                else {
784
                        log_error("[%s:%u] Failed to parse secure bits: %s", filename, line, rvalue);
785
786
787
788
                        return -EBADMSG;
                }
        }

789
790
791
        return 0;
}

792
static int config_parse_bounding_set(
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        ExecContext *c = data;
        char *w;
        size_t l;
        char *state;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

811
        FOREACH_WORD(w, l, rvalue, state) {
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
                char *t;
                int r;
                cap_value_t cap;

                if (!(t = strndup(w, l)))
                        return -ENOMEM;

                r = cap_from_name(t, &cap);
                free(t);

                if (r < 0) {
                        log_error("[%s:%u] Failed to parse capability bounding set: %s", filename, line, rvalue);
                        return -EBADMSG;
                }

                c->capability_bounding_set_drop |= 1 << cap;
        }
829
830
831
832

        return 0;
}

833
static int config_parse_timer_slack_nsec(
834
835
836
837
838
839
840
841
842
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        ExecContext *c = data;
843
844
        unsigned long u;
        int r;
845
846
847
848
849
850

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

851
852
853
        if ((r = safe_atolu(rvalue, &u)) < 0) {
                log_error("[%s:%u] Failed to parse time slack value: %s", filename, line, rvalue);
                return r;
854
855
        }

856
        c->timer_slack_nsec = u;
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886

        return 0;
}

static int config_parse_limit(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        struct rlimit **rl = data;
        unsigned long long u;
        int r;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        if ((r = safe_atollu(rvalue, &u)) < 0) {
                log_error("[%s:%u] Failed to parse resource value: %s", filename, line, rvalue);
                return r;
        }

        if (!*rl)
                if (!(*rl = new(struct rlimit, 1)))
                        return -ENOMEM;
887

888
        (*rl)->rlim_cur = (*rl)->rlim_max = (rlim_t) u;
889
890
891
        return 0;
}

892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
static int config_parse_cgroup(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        Unit *u = userdata;
        char *w;
        size_t l;
        char *state;

        FOREACH_WORD(w, l, rvalue, state) {
                char *t;
                int r;

                if (!(t = strndup(w, l)))
                        return -ENOMEM;

                r = unit_add_cgroup_from_text(u, t);
                free(t);

                if (r < 0)
                        return r;
        }

        return 0;
}

923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
static int config_parse_sysv_priority(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        int *priority = data;
        int r, i;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        if ((r = safe_atoi(rvalue, &i)) < 0 || i < 0) {
                log_error("[%s:%u] Failed to parse SysV start priority: %s", filename, line, rvalue);
                return r;
        }

        *priority = (int) i;
        return 0;
}

949
static DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode");
950

951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
static int config_parse_mount_flags(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        ExecContext *c = data;
        char *w;
        size_t l;
        char *state;
        unsigned long flags = 0;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        FOREACH_WORD(w, l, rvalue, state) {
                if (strncmp(w, "shared", l) == 0)
                        flags |= MS_SHARED;
                else if (strncmp(w, "slave", l) == 0)
                        flags |= MS_SLAVE;
                else if (strncmp(w, "private", l) == 0)
                        flags |= MS_PRIVATE;
                else {
                        log_error("[%s:%u] Failed to parse mount flags: %s", filename, line, rvalue);
                        return -EINVAL;
                }
        }

        c->mount_flags = flags;
        return 0;
}

988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
static int config_parse_timer(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        Timer *t = data;
        usec_t u;
        int r;
        TimerValue *v;
        TimerBase b;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        if ((b = timer_base_from_string(lvalue)) < 0) {
                log_error("[%s:%u] Failed to parse timer base: %s", filename, line, lvalue);
                return -EINVAL;
        }

        if ((r = parse_usec(rvalue, &u)) < 0) {
                log_error("[%s:%u] Failed to parse timer value: %s", filename, line, rvalue);
                return r;
        }

        if (!(v = new0(TimerValue, 1)))
                return -ENOMEM;

        v->base = b;
        v->value = u;

        LIST_PREPEND(TimerValue, value, t->values, v);

        return 0;
}

static int config_parse_timer_unit(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        Timer *t = data;
        int r;

        if (endswith(rvalue, ".timer")) {
                log_error("[%s:%u] Unit cannot be of type timer: %s", filename, line, rvalue);
                return -EINVAL;
        }

        if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &t->unit)) < 0) {
                log_error("[%s:%u] Failed to load unit: %s", filename, line, rvalue);
                return r;
        }

        return 0;
}

1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
static int config_parse_path_spec(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        Path *p = data;
        PathSpec *s;
        PathType b;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        if ((b = path_type_from_string(lvalue)) < 0) {
                log_error("[%s:%u] Failed to parse path type: %s", filename, line, lvalue);
                return -EINVAL;
        }

        if (!path_is_absolute(rvalue)) {
                log_error("[%s:%u] Path is not absolute: %s", filename, line, rvalue);
                return -EINVAL;
        }

        if (!(s = new0(PathSpec, 1)))
                return -ENOMEM;

        if (!(s->path = strdup(rvalue))) {
                free(s);
                return -ENOMEM;
        }

        path_kill_slashes(s->path);

        s->type = b;
        s->inotify_fd = -1;

        LIST_PREPEND(PathSpec, spec, p->specs, s);

        return 0;
}

static int config_parse_path_unit(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        Path *t = data;
        int r;

        if (endswith(rvalue, ".path")) {
                log_error("[%s:%u] Unit cannot be of type path: %s", filename, line, rvalue);
                return -EINVAL;
        }

        if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &t->unit)) < 0) {
                log_error("[%s:%u] Failed to load unit: %s", filename, line, rvalue);
                return r;
        }

        return 0;
}

1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
static int config_parse_env_file(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        FILE *f;
        int r;
        char ***env = data;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        if (!(f = fopen(rvalue, "re"))) {
                log_error("[%s:%u] Failed to open environment file '%s': %m", filename, line, rvalue);
                return -errno;
        }

        while (!feof(f)) {
                char l[LINE_MAX], *p;
                char **t;

                if (!fgets(l, sizeof(l), f)) {
                        if (feof(f))
                                break;

                        r = -errno;
                        log_error("[%s:%u] Failed to read environment file '%s': %m", filename, line, rvalue);
                        goto finish;
                }

                p = strstrip(l);

                if (!*p)
                        continue;

                if (strchr(COMMENTS, *p))
                        continue;

                t = strv_env_set(*env, p);
                strv_free(*env);
                *env = t;
        }

        r = 0;

finish:
        if (f)
                fclose(f);

        return r;
}

1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
static int config_parse_ip_tos(
                const char *filename,
                unsigned line,
                const char *section,
                const char *lvalue,
                const char *rvalue,
                void *data,
                void *userdata) {

        int *ip_tos = data, x;
        int r;

        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);

        if ((x = ip_tos_from_string(rvalue)) < 0)
                if ((r = safe_atoi(rvalue, &x)) < 0) {
                        log_error("[%s:%u] Failed to parse IP TOS value: %s", filename, line, rvalue);
                        return r;
                }

        *ip_tos = x;
        return 0;
}

1210
static DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier");
1211

1212
#define FOLLOW_MAX 8
Lennart Poettering's avatar
Lennart Poettering committed
1213

1214
static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
1215
        unsigned c = 0;
Lennart Poettering's avatar
Lennart Poettering committed
1216
1217
        int fd, r;
        FILE *f;
1218
        char *id = NULL;
Lennart Poettering's avatar
Lennart Poettering committed
1219
1220
1221
1222
1223
1224

        assert(filename);
        assert(*filename);
        assert(_f);
        assert(names);

1225
1226
        /* This will update the filename pointer if the loaded file is
         * reached by a symlink. The old string will be freed. */
Lennart Poettering's avatar
Lennart Poettering committed
1227

1228
        for (;;) {
1229
                char *target, *name;
Lennart Poettering's avatar
Lennart Poettering committed
1230

1231
1232
1233
                if (c++ >= FOLLOW_MAX)
                        return -ELOOP;

Lennart Poettering's avatar
Lennart Poettering committed
1234
1235
                path_kill_slashes(*filename);

Lennart Poettering's avatar
Lennart Poettering committed
1236
1237
                /* Add the file name we are currently looking at to
                 * the names of this unit */
1238
1239
                name = file_name_from_path(*filename);
                if (!(id = set_get(names, name))) {
Lennart Poettering's avatar
Lennart Poettering committed
1240

1241
1242
                        if (!(id = strdup(name)))
                                return -ENOMEM;
Lennart Poettering's avatar
Lennart Poettering committed
1243

1244
1245
1246
                        if ((r = set_put(names, id)) < 0) {
                                free(id);
                                return r;
Lennart Poettering's avatar
Lennart Poettering committed
1247
1248
1249
                        }
                }

1250
1251
                /* Try to open the file name, but don't if its a symlink */
                if ((fd = open(*filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW)) >= 0)
Lennart Poettering's avatar
Lennart Poettering committed
1252
1253
                        break;

1254
1255
1256
                if (errno != ELOOP)
                        return -errno;

Lennart Poettering's avatar
Lennart Poettering committed
1257
                /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
1258
                if ((r = readlink_and_make_absolute(*filename, &target)) < 0)
1259
                        return r;
Lennart Poettering's avatar
Lennart Poettering committed
1260

1261
                free(*filename);
1262
                *filename = target;
Lennart Poettering's avatar
Lennart Poettering committed
1263
1264
1265
1266
        }

        if (!(f = fdopen(fd, "r"))) {
                r = -errno;
1267
                close_nointr_nofail(fd);
1268
                return r;
Lennart Poettering's avatar
Lennart Poettering committed
1269
1270
1271
        }

        *_f = f;
1272
        *_final = id;
1273
        return 0;
Lennart Poettering's avatar
Lennart Poettering committed
1274
1275
}

1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
static int merge_by_names(Unit **u, Set *names, const char *id) {
        char *k;
        int r;

        assert(u);
        assert(*u);
        assert(names);

        /* Let's try to add in all symlink names we found */
        while ((k = set_steal_first(names))) {

                /* First try to merge in the other name into our
                 * unit */
                if ((r = unit_merge_by_name(*u, k)) < 0) {
                        Unit *other;

                        /* Hmm, we couldn't merge the other unit into
                         * ours? Then let's try it the other way
                         * round */

                        other = manager_get_unit((*u)->meta.manager, k);
                        free(k);

                        if (other)
                                if ((r = unit_merge(other, *u)) >= 0) {
                                        *u = other;
                                        return merge_by_names(u, names, NULL);
                                }

                        return r;
                }

                if (id == k)
                        unit_choose_id(*u, id);

                free(k);
        }

        return 0;
}

1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
static void dump_items(FILE *f, const ConfigItem *items) {
        const ConfigItem *i;
        const char *prev_section = NULL;
        bool not_first = false;

        struct {
                ConfigParserCallback callback;
                const char *rvalue;
        } table[] = {
                { config_parse_int,              "INTEGER" },
                { config_parse_unsigned,         "UNSIGNED" },
                { config_parse_size,             "SIZE" },
                { config_parse_bool,             "BOOLEAN" },
                { config_parse_string,           "STRING" },
                { config_parse_path,             "PATH" },
                { config_parse_strv,             "STRING [...]" },
                { config_parse_nice,             "NICE" },
                { config_parse_oom_adjust,       "OOMADJUST" },
                { config_parse_io_class,         "IOCLASS" },
                { config_parse_io_priority,      "IOPRIORITY" },
                { config_parse_cpu_sched_policy, "CPUSCHEDPOLICY" },
                { config_parse_cpu_sched_prio,   "CPUSCHEDPRIO" },
                { config_parse_cpu_affinity,     "CPUAFFINITY" },
                { config_parse_mode,             "MODE" },
1341
                { config_parse_env_file,         "FILE" },
1342
1343
1344
1345
1346
1347
1348
                { config_parse_output,           "OUTPUT" },
                { config_parse_input,            "INPUT" },
                { config_parse_facility,         "FACILITY" },
                { config_parse_level,            "LEVEL" },
                { config_parse_capabilities,     "CAPABILITIES" },
                { config_parse_secure_bits,      "SECUREBITS" },
                { config_parse_bounding_set,     "BOUNDINGSET" },
1349
                { config_parse_timer_slack_nsec, "TIMERSLACK" },
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
                { config_parse_limit,            "LIMIT" },
                { config_parse_cgroup,           "CGROUP [...]" },
                { config_parse_deps,             "UNIT [...]" },
                { config_parse_names,            "UNIT [...]" },
                { config_parse_exec,             "PATH [ARGUMENT [...]]" },
                { config_parse_service_type,     "SERVICETYPE" },
                { config_parse_service_restart,  "SERVICERESTART" },
                { config_parse_sysv_priority,    "SYSVPRIORITY" },
                { config_parse_kill_mode,        "KILLMODE" },
                { config_parse_listen,           "SOCKET [...]" },
                { config_parse_socket_bind,      "SOCKETBIND" },
1361
1362
1363
                { config_parse_bindtodevice,     "NETWORKINTERFACE" },
                { config_parse_usec,             "SECONDS" },
                { config_parse_path_strv,        "PATH [...]" },
1364
                { config_parse_mount_flags,      "MOUNTFLAG [...]" },
1365
                { config_parse_string_printf,    "STRING" },
1366
1367
                { config_parse_timer,            "TIMER" },
                { config_parse_timer_unit,       "NAME" },
1368
1369
                { config_parse_path_spec,        "PATH" },
                { config_parse_path_unit,        "UNIT" },
1370
1371
                { config_parse_notify_access,    "ACCESS" },
                { config_parse_ip_tos,           "TOS" },
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
        };

        assert(f);
        assert(items);

        for (i = items; i->lvalue; i++) {
                unsigned j;
                const char *rvalue = "OTHER";

                if (!streq_ptr(i->section, prev_section)) {
                        if (!not_first)
                                not_first = true;
                        else
                                fputc('\n', f);

                        fprintf(f, "[%s]\n", i->section);
                        prev_section = i->section;
                }

                for (j = 0; j < ELEMENTSOF(table); j++)
                        if (i->parse == table[j].callback) {
                                rvalue = table[j].rvalue;
                                break;
                        }

                fprintf(f, "%s=%s\n", i->lvalue, rvalue);
        }
}

static int load_from_path(Unit *u, const char *path) {
Lennart Poettering's avatar
Lennart Poettering committed
1402
1403
1404
1405
1406
1407
1408
1409
1410

        static const char* const section_table[_UNIT_TYPE_MAX] = {
                [UNIT_SERVICE]   = "Service",
                [UNIT_TIMER]     = "Timer",
                [UNIT_SOCKET]    = "Socket",
                [UNIT_TARGET]    = "Target",
                [UNIT_DEVICE]    = "Device",
                [UNIT_MOUNT]     = "Mount",
                [UNIT_AUTOMOUNT] = "Automount",
Maarten Lankhorst's avatar
Maarten Lankhorst committed
1411
                [UNIT_SNAPSHOT]  = "Snapshot",
1412
1413
                [UNIT_SWAP]      = "Swap",
                [UNIT_PATH]      = "Path"
1414
1415
        };

1416
#define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \
1417
1418
                { "WorkingDirectory",       config_parse_path,            &(context).working_directory,                    section   }, \
                { "RootDirectory",          config_parse_path,            &(context).root_directory,                       section   }, \
1419
1420
                { "User",                   config_parse_string_printf,   &(context).user,                                 section   }, \
                { "Group",                  config_parse_string_printf,   &(context).group,                                section   }, \
1421
                { "SupplementaryGroups",    config_parse_strv,            &(context).supplementary_groups,                 section   }, \
1422
1423
                { "Nice",                   config_parse_nice,            &(context),                                      section   }, \
                { "OOMAdjust",              config_parse_oom_adjust,      &(context),                                      section   }, \
1424
                { "IOSchedulingClass",      config_parse_io_class,        &(context),                                      section   }, \
1425
1426
1427
                { "IOSchedulingPriority",   config_parse_io_priority,     &(context),                                      section   }, \
                { "CPUSchedulingPolicy",    config_parse_cpu_sched_policy,&(context),                                      section   }, \
                { "CPUSchedulingPriority",  config_parse_cpu_sched_prio,  &(context),                                      section   }, \
1428
                { "CPUSchedulingResetOnFork", config_parse_bool,          &(context).cpu_sched_reset_on_fork,              section   }, \
1429
                { "CPUAffinity",            config_parse_cpu_affinity,    &(context),                                      section   }, \
1430
                { "UMask",                  config_parse_mode,            &(context).umask,                                section   }, \
1431
                { "Environment",            config_parse_strv,            &(context).environment,                          section   }, \
1432
                { "EnvironmentFile",        config_parse_env_file,        &(context).environment,                          section   }, \
Lennart Poettering's avatar
Lennart Poettering committed
1433
1434
                { "StandardInput",          config_parse_input,           &(context).std_input,                            section   }, \
                { "StandardOutput",         config_parse_output,          &(context).std_output,                           section   }, \
1435
                { "StandardError",          config_parse_output,          &(context).std_error,                            section   }, \
Lennart Poettering's avatar
Lennart Poettering committed
1436
                { "TTYPath",                config_parse_path,            &(context).tty_path,                             section   }, \
1437
                { "SyslogIdentifier",       config_parse_string_printf,   &(context).syslog_identifier,                    section   }, \
1438
                { "SyslogFacility",         config_parse_facility,        &(context).syslog_priority,                      section   }, \
1439
                { "SyslogLevel",            config_parse_level,           &(context).syslog_priority,                      section   }, \
1440
                { "SyslogLevelPrefix",      config_parse_bool,            &(context).syslog_level_prefix,                  section   }, \
1441
1442
1443
                { "Capabilities",           config_parse_capabilities,    &(context),                                      section   }, \
                { "SecureBits",             config_parse_secure_bits,     &(context),                                      section   }, \
                { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context),                                      section   }, \
1444
                { "TimerSlackNSec",         config_parse_timer_slack_nsec,&(context),                                      section   }, \
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
                { "LimitCPU",               config_parse_limit,           &(context).rlimit[RLIMIT_CPU],                   section   }, \
                { "LimitFSIZE",             config_parse_limit,           &(context).rlimit[RLIMIT_FSIZE],                 section   }, \
                { "LimitDATA",              config_parse_limit,           &(context).rlimit[RLIMIT_DATA],                  section   }, \
                { "LimitSTACK",             config_parse_limit,           &(context).rlimit[RLIMIT_STACK],                 section   }, \
                { "LimitCORE",              config_parse_limit,           &(context).rlimit[RLIMIT_CORE],                  section   }, \
                { "LimitRSS",               config_parse_limit,           &(context).rlimit[RLIMIT_RSS],                   section   }, \
                { "LimitNOFILE",            config_parse_limit,           &(context).rlimit[RLIMIT_NOFILE],                section   }, \
                { "LimitAS",                config_parse_limit,           &(context).rlimit[RLIMIT_AS],                    section   }, \
                { "LimitNPROC",             config_parse_limit,           &(context).rlimit[RLIMIT_NPROC],                 section   }, \
                { "LimitMEMLOCK",           config_parse_limit,           &(context).rlimit[RLIMIT_MEMLOCK],               section   }, \
                { "LimitLOCKS",             config_parse_limit,           &(context).rlimit[RLIMIT_LOCKS],                 section   }, \
                { "LimitSIGPENDING",        config_parse_limit,           &(context).rlimit[RLIMIT_SIGPENDING],            section   }, \
                { "LimitMSGQUEUE",          config_parse_limit,           &(context).rlimit[RLIMIT_MSGQUEUE],              section   }, \
                { "LimitNICE",              config_parse_limit,           &(context).rlimit[RLIMIT_NICE],                  section   }, \
                { "LimitRTPRIO",            config_parse_limit,           &(context).rlimit[RLIMIT_RTPRIO],                section   }, \
1460
                { "LimitRTTIME",            config_parse_limit,           &(context).rlimit[RLIMIT_RTTIME],                section   }, \
1461
1462
1463
1464
1465
                { "ControlGroup",           config_parse_cgroup,          u,                                               section   }, \
                { "ReadWriteDirectories",   config_parse_path_strv,       &(context).read_write_dirs,                      section   }, \
                { "ReadOnlyDirectories",    config_parse_path_strv,       &(context).read_only_dirs,                       section   }, \
                { "InaccessibleDirectories",config_parse_path_strv,       &(context).inaccessible_dirs,                    section   }, \
                { "PrivateTmp",             config_parse_bool,            &(context).private_tmp,                          section   }, \
1466
                { "MountFlags",             config_parse_mount_flags,     &(context),                                      section   }, \
1467
1468
                { "TCPWrapName",            config_parse_string_printf,   &(context).tcpwrap_name,                         section   }, \
                { "PAMName",                config_parse_string_printf,   &(context).pam_name,                             section   }
1469

1470
        const ConfigItem items[] = {
1471
                { "Names",                  config_parse_names,           u,                                               "Unit"    },
1472
                { "Description",            config_parse_string_printf,   &u->meta.description,                            "Unit"    },
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
                { "Requires",               config_parse_deps,            UINT_TO_PTR(UNIT_REQUIRES),                      "Unit"    },
                { "RequiresOverridable",    config_parse_deps,            UINT_TO_PTR(UNIT_REQUIRES_OVERRIDABLE),          "Unit"    },
                { "Requisite",              config_parse_deps,            UINT_TO_PTR(UNIT_REQUISITE),                     "Unit"    },
                { "RequisiteOverridable",   config_parse_deps,            UINT_TO_PTR(UNIT_REQUISITE_OVERRIDABLE),         "Unit"    },
                { "Wants",                  config_parse_deps,            UINT_TO_PTR(UNIT_WANTS),                         "Unit"    },
                { "Conflicts",              config_parse_deps,            UINT_TO_PTR(UNIT_CONFLICTS),                     "Unit"    },
                { "Before",                 config_parse_deps,            UINT_TO_PTR(UNIT_BEFORE),                        "Unit"    },
                { "After",                  config_parse_deps,            UINT_TO_PTR(UNIT_AFTER),                         "Unit"    },
                { "RecursiveStop",          config_parse_bool,            &u->meta.recursive_stop,                         "Unit"    },
                { "StopWhenUnneeded",       config_parse_bool,            &u->meta.stop_when_unneeded,                     "Unit"    },
1483
                { "OnlyByDependency",       config_parse_bool,            &u->meta.only_by_dependency,                     "Unit"    },
1484
                { "DefaultDependencies",    config_parse_bool,            &u->meta.default_dependencies,                   "Unit"    },
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494

                { "PIDFile",                config_parse_path,            &u->service.pid_file,                            "Service" },
                { "ExecStartPre",           config_parse_exec,            u->service.exec_command+SERVICE_EXEC_START_PRE,  "Service" },
                { "ExecStart",              config_parse_exec,            u->service.exec_command+SERVICE_EXEC_START,      "Service" },
                { "ExecStartPost",          config_parse_exec,            u->service.exec_command+SERVICE_EXEC_START_POST, "Service" },
                { "ExecReload",             config_parse_exec,            u->service.exec_command+SERVICE_EXEC_RELOAD,     "Service" },
                { "ExecStop",               config_parse_exec,            u->service.exec_command+SERVICE_EXEC_STOP,       "Service" },
                { "ExecStopPost",           config_parse_exec,            u->service.exec_command+SERVICE_EXEC_STOP_POST,  "Service" },
                { "RestartSec",             config_parse_usec,            &u->service.restart_usec,                        "Service" },
                { "TimeoutSec",             config_parse_usec,            &u->service.timeout_usec,                        "Service" },
1495
1496
                { "Type",                   config_parse_service_type,    &u->service.type,                                "Service" },
                { "Restart",                config_parse_service_restart, &u->service.restart,                             "Service" },
1497
1498
                { "PermissionsStartOnly",   config_parse_bool,            &u->service.permissions_start_only,              "Service" },
                { "RootDirectoryStartOnly", config_parse_bool,            &u->service.root_directory_start_only,           "Service" },
1499
                { "ValidNoProcess",         config_parse_bool,            &u->service.valid_no_process,                    "Service" },
1500
                { "SysVStartPriority",      config_parse_sysv_priority,   &u->service.sysv_start_priority,                 "Service" },
1501
                { "KillMode",               config_parse_kill_mode,       &u->service.kill_mode,                           "Service" },
1502
                { "NonBlocking",            config_parse_bool,            &u->service.exec_context.non_blocking,           "Service" },
1503
                { "BusName",                config_parse_string_printf,   &u->service.bus_name,                            "Service" },
1504
                { "NotifyAccess",           config_parse_notify_access,   &u->service.notify_access,                       "Service" },
Lennart Poettering's avatar
Lennart Poettering committed
1505
1506
                EXEC_CONTEXT_CONFIG_ITEMS(u->service.exec_context, "Service"),

1507
1508
1509
1510
1511
1512
                { "ListenStream",           config_parse_listen,          &u->socket,                                      "Socket"  },
                { "ListenDatagram",         config_parse_listen,          &u->socket,                                      "Socket"  },
                { "ListenSequentialPacket", config_parse_listen,          &u->socket,                                      "Socket"  },
                { "ListenFIFO",             config_parse_listen,          &u->socket,                                      "Socket"  },
                { "BindIPv6Only",           config_parse_socket_bind,     &u->socket,                                      "Socket"  },
                { "Backlog",                config_parse_unsigned,        &u->socket.backlog,                              "Socket"  },
1513
                { "BindToDevice",           config_parse_bindtodevice,    &u->socket,                                      "Socket"  },
1514
1515
1516
1517
                { "ExecStartPre",           config_parse_exec,            u->socket.exec_command+SOCKET_EXEC_START_PRE,    "Socket"  },
                { "ExecStartPost",          config_parse_exec,            u->socket.exec_command+SOCKET_EXEC_START_POST,   "Socket"  },
                { "ExecStopPre",            config_parse_exec,            u->socket.exec_command+SOCKET_EXEC_STOP_PRE,     "Socket"  },
                { "ExecStopPost",           config_parse_exec,            u->socket.exec_command+SOCKET_EXEC_STOP_POST,    "Socket"  },
1518
                { "TimeoutSec",             config_parse_usec,            &u->socket.timeout_usec,                         "Socket"  },
1519
1520
                { "DirectoryMode",          config_parse_mode,            &u->socket.directory_mode,                       "Socket"  },
                { "SocketMode",             config_parse_mode,            &u->socket.socket_mode,                          "Socket"  },
1521
                { "KillMode",               config_parse_kill_mode,       &u->socket.kill_mode,                            "Socket"  },
1522
                { "Accept",                 config_parse_bool,            &u->socket.accept,                               "Socket"  },
1523
                { "MaxConnections",         config_parse_unsigned,        &u->socket.max_connections,                      "Socket"  },
1524
1525
1526
1527
1528
1529
1530
1531
1532
                { "KeepAlive",              config_parse_bool,            &u->socket.keep_alive,                           "Socket"  },
                { "Priority",               config_parse_int,             &u->socket.priority,                             "Socket"  },
                { "ReceiveBuffer",          config_parse_size,            &u->socket.receive_buffer,                       "Socket"  },
                { "SendBuffer",             config_parse_size,            &u->socket.send_buffer,                          "Socket"  },
                { "IPTOS",                  config_parse_ip_tos,          &u->socket.ip_tos,                               "Socket"  },
                { "IPTTL",                  config_parse_int,             &u->socket.ip_ttl,                               "Socket"  },
                { "Mark",                   config_parse_int,             &u->socket.mark,                                 "Socket"  },
                { "PipeSize",               config_parse_size,            &u->socket.pipe_size,                            "Socket"  },
                { "FreeBind",               config_parse_bool,            &u->socket.free_bind,                            "Socket"  },
Lennart Poettering's avatar
Lennart Poettering committed
1533
1534
                EXEC_CONTEXT_CONFIG_ITEMS(u->socket.exec_context, "Socket"),

1535
1536
1537
1538
1539
1540
                { "What",                   config_parse_string,          &u->mount.parameters_fragment.what,              "Mount"   },
                { "Where",                  config_parse_path,            &u->mount.where,                                 "Mount"   },
                { "Options",                config_parse_string,          &u->mount.parameters_fragment.options,           "Mount"   },
                { "Type",                   config_parse_string,          &u->mount.parameters_fragment.fstype,            "Mount"   },
                { "TimeoutSec",             config_parse_usec,            &u->mount.timeout_usec,                          "Mount"   },
                { "KillMode",               config_parse_kill_mode,       &u->mount.kill_mode,                             "Mount"   },
1541
                { "DirectoryMode",          config_parse_mode,            &u->mount.directory_mode,                        "Mount"   },
1542
                EXEC_CONTEXT_CONFIG_ITEMS(u->mount.exec_context, "Mount"),