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 | |
parent | cb5b1af6dee0ff41e73a3bc0661ba7aa7b1d1b94 (diff) | |
download | s6-linux-init-9e6d0f168bf59df9cd829d6ebe63fb08ea9ae01e.tar.xz |
Add skel files; add initdefault; remove env-stage2
Diffstat (limited to 'src/init')
-rw-r--r-- | src/init/s6-linux-init-maker.c | 36 | ||||
-rw-r--r-- | src/init/s6-linux-init.c | 31 |
2 files changed, 40 insertions, 27 deletions
diff --git a/src/init/s6-linux-init-maker.c b/src/init/s6-linux-init-maker.c index 62f04da..82ab14f 100644 --- a/src/init/s6-linux-init-maker.c +++ b/src/init/s6-linux-init-maker.c @@ -28,12 +28,12 @@ #ifdef S6_LINUX_INIT_UTMPD_PATH # include <utmps/config.h> -# define USAGE "s6-linux-init-maker [ -c basedir ] [ -u log_user ] [ -G early_getty_cmd ] [ -1 ] [ -L ] [ -p initial_path ] [ -m initial_umask ] [ -t timestamp_style ] [ -d slashdev ] [ -s env_store ] [ -e initial_envvar ... ] [ -q default_grace_time ] [ -U utmp_user ]" -# define OPTION_STRING "c:u:G:1Lp:m:t:d:s:e:E:q:U:" +# define USAGE "s6-linux-init-maker [ -c basedir ] [ -u log_user ] [ -G early_getty_cmd ] [ -1 ] [ -L ] [ -p initial_path ] [ -m initial_umask ] [ -t timestamp_style ] [ -d slashdev ] [ -s env_store ] [ -e initial_envvar ... ] [ -q default_grace_time ] [ -D initdefault ] [ -U utmp_user ]" +# define OPTION_STRING "c:u:G:1Lp:m:t:d:s:e:E:q:U:D:" # define UTMPS_DIR "utmps" #else -# define USAGE "s6-linux-init-maker [ -c basedir ] [ -u log_user ] [ -G early_getty_cmd ] [ -1 ] [ -L ] [ -p initial_path ] [ -m initial_umask ] [ -t timestamp_style ] [ -d slashdev ] [ -s env_store ] [ -e initial_envvar ... ] [ -q default_grace_time ]" -# define OPTION_STRING "c:u:G:1Lp:m:t:d:s:e:E:q:" +# define USAGE "s6-linux-init-maker [ -c basedir ] [ -u log_user ] [ -G early_getty_cmd ] [ -1 ] [ -L ] [ -p initial_path ] [ -m initial_umask ] [ -t timestamp_style ] [ -d slashdev ] [ -s env_store ] [ -e initial_envvar ... ] [ -q default_grace_time ] [ -D initdefault ]" +# define OPTION_STRING "c:u:G:1Lp:m:t:d:s:e:E:q:D:" #endif #define dieusage() strerr_dieusage(100, USAGE) @@ -47,6 +47,7 @@ static char const *env_store = 0 ; static char const *early_getty = 0 ; static char const *slashdev = 0 ; static char const *log_user = "root" ; +static char const *initdefault = 0 ; static unsigned int initial_umask = 0022 ; static unsigned int timestamp_style = 1 ; static unsigned int finalsleep = 3000 ; @@ -226,6 +227,13 @@ static inline int stage1_script (buffer *b, char const *data) if (buffer_puts(b, satmp.s + sabase) < 0) goto err ; satmp.len = sabase ; } + if (initdefault) + { + if (buffer_puts(b, " -D ") < 0 + || !string_quote(&satmp, initdefault, strlen(initdefault))) return 0 ; + if (buffer_puts(b, satmp.s + sabase) < 0) goto err ; + satmp.len = sabase ; + } if (buffer_puts(b, "\n") < 0) return 0 ; (void)data ; return 1 ; @@ -404,15 +412,15 @@ static void getug (char const *s, uid_t *uid, gid_t *gid) static inline void auto_basedir (char const *base, char const *dir, uid_t uid, gid_t gid, unsigned int mode) { size_t n = strlen(dir) ; - char tmp[n+1] ; - for (size_t i = 0; i < n ; i++) + char tmp[n + 1] ; + for (size_t i = 0 ; i < n ; i++) { - if ((s[i] == '/') && i) + if ((dir[i] == '/') && i) { tmp[i] = 0 ; auto_dir_internal(base, tmp, uid, gid, mode, 0) ; } - tmp[i] = s[i] ; + tmp[i] = dir[i] ; } } @@ -542,8 +550,6 @@ static inline void make_bins (char const *base) int main (int argc, char const *const *argv, char const *const *envp) { - stralloc saenv1 = STRALLOC_ZERO ; - stralloc saenv2 = STRALLOC_ZERO ; PROG = "s6-linux-init-maker" ; { subgetopt_t l = SUBGETOPT_ZERO ; @@ -563,9 +569,9 @@ int main (int argc, char const *const *argv, char const *const *envp) case 't' : if (!uint0_scan(l.arg, ×tamp_style)) dieusage() ; break ; case 'd' : slashdev = l.arg ; break ; case 's' : env_store = l.arg ; break ; - case 'e' : if (!stralloc_catb(&saenv1, l.arg, strlen(l.arg) + 1)) dienomem() ; break ; - case 'E' : if (!stralloc_catb(&saenv2, l.arg, strlen(l.arg) + 1)) dienomem() ; break ; + case 'e' : if (!stralloc_catb(&satmp, l.arg, strlen(l.arg) + 1)) dienomem() ; break ; case 'q' : if (!uint0_scan(l.arg, &finalsleep)) dieusage() ; break ; + case 'D' : initdefault = l.arg ; break ; #ifdef S6_LINUX_INIT_UTMPD_PATH case 'U' : utmp_user = l.arg ; break ; #endif @@ -587,10 +593,8 @@ int main (int argc, char const *const *argv, char const *const *envp) if (mkdir(argv[0], 0755) < 0) strerr_diefu2sys(111, "mkdir ", argv[0]) ; - make_env(argv[0], ENVSTAGE2, saenv2.s, saenv2.len) ; - stralloc_free(&saenv2) ; - make_env(argv[0], ENVSTAGE1, saenv1.s, saenv1.len) ; - saenv1.len = 0 ; + make_env(argv[0], ENVSTAGE1, satmp.s, satmp.len) ; + satmp.len = 0 ; make_image(argv[0]) ; make_scripts(argv[0]) ; make_bins(argv[0]) ; 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) ; |