diff options
author | David Oberhollenzer <david.oberhollenzer@tele2.at> | 2018-04-11 23:01:35 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@tele2.at> | 2018-04-11 23:01:35 +0200 |
commit | 38ad6f1b2f8137226382a2a029ba37f1a173807a (patch) | |
tree | e1a479b9db60d79b5a99d26921a1a5d47e94a6e2 /lib/src | |
parent | 20e08db1a5d8d43ed5faaa1063c60eca62715ec5 (diff) |
Allow aggregating command lines in blocks
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
Diffstat (limited to 'lib/src')
-rw-r--r-- | lib/src/rdsvc.c | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/lib/src/rdsvc.c b/lib/src/rdsvc.c index 2b09c3f..1f859b7 100644 --- a/lib/src/rdsvc.c +++ b/lib/src/rdsvc.c @@ -202,15 +202,17 @@ static int svc_target(service_t *svc, char *arg, rdline_t *rd) static const struct svc_param { const char *key; + unsigned int allow_block : 1; + int (*handle)(service_t *svc, char *arg, rdline_t *rd); } svc_params[] = { - { "description", svc_desc }, - { "exec", svc_exec }, - { "type", svc_type }, - { "target", svc_target }, - { "tty", svc_tty }, - { "before", svc_before }, - { "after", svc_after }, + { "description", 0, svc_desc }, + { "exec", 1, svc_exec }, + { "type", 0, svc_type }, + { "target", 0, svc_target }, + { "tty", 0, svc_tty }, + { "before", 0, svc_before }, + { "after", 0, svc_after }, }; static int splitkv(rdline_t *rd, char **k, char **v) @@ -297,8 +299,27 @@ service_t *rdsvc(int dirfd, const char *filename) if (p == NULL) goto fail; - if (p->handle(svc, value, &rd)) + if (p->allow_block && *value == '{') { + for (++value; *value == ' '; ++value) + ; + if (*value != '\0' && p->handle(svc, value, &rd)) + goto fail; + + while ((ret = rdline(&rd)) == 0) { + if (strcmp(rd.buffer, "}") == 0) + break; + + if (p->handle(svc, rd.buffer, &rd)) + goto fail; + } + + if (ret < 0) + goto fail; + if (ret > 0) + goto fail_bra; + } else if (p->handle(svc, value, &rd)) { goto fail; + } } if (ret < 0) @@ -306,6 +327,9 @@ service_t *rdsvc(int dirfd, const char *filename) close(fd); return svc; +fail_bra: + fprintf(stderr, "%s: missing '}' before end-of-file\n", filename); + goto fail; fail_oom: fputs("out of memory\n", stderr); fail: |