1
0
Fork 0
mirror of https://github.com/pygos/init.git synced 2024-12-22 15:20:49 +01:00

Allow aggregating command lines in blocks

Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
David Oberhollenzer 2018-04-11 23:01:35 +02:00
parent 20e08db1a5
commit 38ad6f1b2f
7 changed files with 66 additions and 29 deletions

View file

@ -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:

View file

@ -4,5 +4,7 @@ target boot
before sysinit
after hwclock hostname vfs
exec "@SBINPATH@/ip" addr add 127.0.0.1/8 dev lo brd +
exec "@SBINPATH@/ip" link set lo up
exec {
"@SBINPATH@/ip" addr add 127.0.0.1/8 dev lo brd +
"@SBINPATH@/ip" link set lo up
}

View file

@ -3,5 +3,7 @@ type wait
target boot
before vfs
exec "@SBINPATH@/mount" -t proc proc /proc
exec "@SCRIPTDIR@/trymount.sh" "/proc/sys/fs/binfmt_misc" "binfmt_misc" "nodev,noexec,nosuid"
exec {
"@SBINPATH@/mount" -t proc proc /proc
"@SCRIPTDIR@/trymount.sh" /proc/sys/fs/binfmt_misc binfmt_misc nodev,noexec,nosuid
}

View file

@ -1,6 +1,9 @@
description send SIGTERM to all processes
exec "@SCRIPTDIR@/killall5" 15
exec "@BINPATH@/sleep" 5
type wait
target %0
before sigkill sync reboot shutdown
exec {
"@SCRIPTDIR@/killall5" 15
"@BINPATH@/sleep" 5
}

View file

@ -4,8 +4,10 @@ target boot
after procfs
before vfs
exec "@SBINPATH@/mount" -t sysfs sysfs /sys
exec "@SCRIPTDIR@/trymount.sh" "/sys/kernel/security" "securityfs" "nodev,noexec,nosuid"
exec "@SCRIPTDIR@/trymount.sh" "/sys/kernel/config" "configfs" "nodev,noexec,nosuid"
exec "@SCRIPTDIR@/trymount.sh" "/sys/fs/fuse/connections" "fusectl" "nodev,noexec,nosuid"
exec "@SCRIPTDIR@/trymount.sh" "/sys/firmware/efi/efivars" "efivarfs" "ro"
exec {
"@SBINPATH@/mount" -t sysfs sysfs /sys
"@SCRIPTDIR@/trymount.sh" /sys/kernel/security securityfs nodev,noexec,nosuid
"@SCRIPTDIR@/trymount.sh" /sys/kernel/config configfs nodev,noexec,nosuid
"@SCRIPTDIR@/trymount.sh" /sys/fs/fuse/connections fusectl nodev,noexec,nosuid
"@SCRIPTDIR@/trymount.sh" /sys/firmware/efi/efivars efivarfs ro
}

View file

@ -3,7 +3,9 @@ type wait
target boot
before vfs
after tmpfsvar
exec "@SBINPATH@/mount" -t tmpfs none /run
exec "@BINPATH@/mkdir" /run/lock -m 0755
exec "@BINPATH@/ln" -s /run /var/run
exec "@BINPATH@/ln" -s /run/lock /var/lock
exec {
"@SBINPATH@/mount" -t tmpfs none /run
"@BINPATH@/mkdir" /run/lock -m 0755
"@BINPATH@/ln" -s /run /var/run
"@BINPATH@/ln" -s /run/lock /var/lock
}

View file

@ -2,9 +2,11 @@ description "mount /var"
type wait
target boot
before vfs
exec "@SBINPATH@/mount" -t tmpfs none /var
exec "@BINPATH@/mkdir" /var/log -m 0755
exec "@BINPATH@/mkdir" /var/spool -m 0755
exec "@BINPATH@/mkdir" /var/lib -m 0755
exec "@BINPATH@/mkdir" /var/tmp -m 0755
exec "@SCRIPTDIR@/overlay.sh" var_lib /var/lib
exec {
"@SBINPATH@/mount" -t tmpfs none /var
"@BINPATH@/mkdir" /var/log -m 0755
"@BINPATH@/mkdir" /var/spool -m 0755
"@BINPATH@/mkdir" /var/lib -m 0755
"@BINPATH@/mkdir" /var/tmp -m 0755
"@SCRIPTDIR@/overlay.sh" var_lib /var/lib
}