diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2019-04-20 05:58:37 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2019-04-20 05:58:37 +0000 |
commit | 9e6d0f168bf59df9cd829d6ebe63fb08ea9ae01e (patch) | |
tree | 77f5afd89846e1dd1b7020498426905f6ef7b5cb /src/init/s6-linux-init.c | |
parent | cb5b1af6dee0ff41e73a3bc0661ba7aa7b1d1b94 (diff) | |
download | s6-linux-init-9e6d0f168bf59df9cd829d6ebe63fb08ea9ae01e.tar.xz |
Add skel files; add initdefault; remove env-stage2
Diffstat (limited to 'src/init/s6-linux-init.c')
-rw-r--r-- | src/init/s6-linux-init.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/init/s6-linux-init.c b/src/init/s6-linux-init.c index aeddbac..94a2054 100644 --- a/src/init/s6-linux-init.c +++ b/src/init/s6-linux-init.c @@ -23,28 +23,35 @@ #include "defaults.h" #include "initctl.h" -#define USAGE "s6-linux-init [ -c basedir ] [ -p initpath ] [ -s envdumpdir ] [ -m umask ] [ -d devtmpfs ]" +#define USAGE "s6-linux-init [ -c basedir ] [ -p initpath ] [ -s envdumpdir ] [ -m umask ] [ -d devtmpfs ] [ -D initdefault ]" #define dieusage() strerr_dieusage(100, USAGE) #define BANNER "\n s6-linux-init version " S6_LINUX_INIT_VERSION "\n\n" -static inline void run_stage2 (char const *basedir, char const **argv, unsigned int argc, char const *const *envp, size_t envlen, stralloc *envmodifs) +static inline char const *scan_cmdline (char const *initdefault, char const *const *argv, unsigned int argc) +{ + static char const *valid[] = { "default", "2", "3", "4", "5", 0 } ; + for (unsigned int i = 0 ; i < argc ; i++) + for (char const *const *p = valid ; *p ; p++) + if (!strcmp(argv[i], *p)) return argv[i] ; + return initdefault ; +} + +static inline void run_stage2 (char const *basedir, char const **argv, unsigned int argc, char const *const *envp, size_t envlen, stralloc *envmodifs, char const *initdefault) { size_t dirlen = strlen(basedir) ; - char const *childargv[argc + 2] ; - char fn[dirlen + 1 + (sizeof(ENVSTAGE2) > sizeof(STAGE2) ? sizeof(ENVSTAGE2) : sizeof(STAGE2))] ; + char const *childargv[argc + 3] ; + char fn[dirlen + 1 + sizeof(STAGE2)] ; PROG = "s6-linux-init (child)" ; argv[0] = PROG ; memcpy(fn, basedir, dirlen) ; fn[dirlen] = '/' ; - memcpy(fn + dirlen + 1, ENVSTAGE2, sizeof(ENVSTAGE2)) ; - if (envdir(fn, envmodifs) == -1) - strerr_warnwu2sys("envdir ", fn) ; memcpy(fn + dirlen + 1, STAGE2, sizeof(STAGE2)) ; childargv[0] = fn ; + childargv[1] = scan_cmdline(initdefault, argv + 1, argc - 1) ; for (unsigned int i = 0 ; i < argc ; i++) - childargv[i+1] = argv[i] ; - childargv[argc + 1] = 0 ; + childargv[i+2] = argv[i] ; + childargv[argc + 2] = 0 ; setsid() ; fd_close(1) ; if (open(LOGFIFO, O_WRONLY) != 1) /* blocks until catch-all logger is up */ @@ -61,6 +68,7 @@ int main (int argc, char const **argv, char const *const *envp) char const *path = INITPATH ; char const *slashdev = 0 ; char const *envdumpdir = 0 ; + char const *initdefault = "default" ; stralloc envmodifs = STRALLOC_ZERO ; PROG = "s6-linux-init" ; @@ -75,7 +83,7 @@ int main (int argc, char const **argv, char const *const *envp) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - int opt = subgetopt_r(argc, argv, "c:p:s:m:d:", &l) ; + int opt = subgetopt_r(argc, argv, "c:p:s:m:d:D:", &l) ; if (opt == -1) break ; switch (opt) { @@ -84,6 +92,7 @@ int main (int argc, char const **argv, char const *const *envp) case 's' : envdumpdir = l.arg ; break ; case 'm' : if (!uint0_oscan(l.arg, &mask)) dieusage() ; break ; case 'd' : slashdev = l.arg ; break ; + case 'D' : initdefault = l.arg ; break ; default : dieusage() ; } } @@ -158,7 +167,7 @@ int main (int argc, char const **argv, char const *const *envp) } pid = fork() ; if (pid == -1) strerr_diefu1sys(111, "fork") ; - if (!pid) run_stage2(basedir, argv, argc, newenvp, !!path, &envmodifs) ; + if (!pid) run_stage2(basedir, argv, argc, newenvp, !!path, &envmodifs, initdefault) ; if (fd_copy(2, 1) == -1) strerr_diefu1sys(111, "redirect output file descriptor") ; xpathexec_r(newargv, newenvp, !!path, envmodifs.s, envmodifs.len) ; |