diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-06-07 13:03:49 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-06-07 13:03:49 +0000 |
commit | d6e214a83b361ff000d0d28952f836639896cd85 (patch) | |
tree | c13b90687c14563855e51935b95a3ad9d6c5b5f1 /src | |
parent | 2a4e570485e8dee285843ca46f6dd6155972c437 (diff) | |
download | s6-linux-init-d6e214a83b361ff000d0d28952f836639896cd85.tar.xz |
Add verbosity setting, prepare for 1.1.2.0
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/init/s6-linux-init-maker.c | 38 | ||||
-rw-r--r-- | src/init/s6-linux-init.c | 37 |
2 files changed, 43 insertions, 32 deletions
diff --git a/src/init/s6-linux-init-maker.c b/src/init/s6-linux-init-maker.c index d3b921d..584b0b7 100644 --- a/src/init/s6-linux-init-maker.c +++ b/src/init/s6-linux-init-maker.c @@ -26,7 +26,7 @@ #include "defaults.h" #include "initctl.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 ] [ -D initdefault ] [ -n | -N ] [ -f skeldir ] [ -R resourcelimits ] [ -C ] [ -B ] [ -S ] dir" +#define USAGE "s6-linux-init-maker [ -V boot_verbosity ] [ -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 ] [ -n | -N ] [ -f skeldir ] [ -R resourcelimits ] [ -C ] [ -B ] [ -S ] dir" #define dieusage() strerr_dieusage(100, USAGE) #define dienomem() strerr_diefu1sys(111, "stralloc_catb") ; @@ -43,6 +43,7 @@ static char const *skeldir = S6_LINUX_INIT_SKELDIR ; static unsigned int initial_umask = 0022 ; static unsigned int timestamp_style = 1 ; static unsigned int finalsleep = 3000 ; +static unsigned int boot_verbosity = 1 ; static int mounttype = 1 ; static int console = 0 ; static int logouthookd = 0 ; @@ -239,47 +240,47 @@ static int sig_script (buffer *b, char const *option) static inline int stage1_script (buffer *b, char const *data) { size_t sabase = satmp.len ; + char fmt[UINT_OFMT] ; if (!put_shebang_options(b, "-S0")) return 0 ; if (ressa.len) { if (buffer_puts(b, S6_EXTBINPREFIX "s6-softlimit -H ") < 0 || buffer_put(b, ressa.s, ressa.len) < 0) goto err ; } - if (buffer_puts(b, S6_LINUX_INIT_EXTBINPREFIX "s6-linux-init -c ") < 0 - || !string_quote(&satmp, robase, strlen(robase))) return 0 ; - if (buffer_put(b, satmp.s + sabase, satmp.len - sabase) < 0) goto err ; + if (buffer_puts(b, S6_LINUX_INIT_EXTBINPREFIX "s6-linux-init -v ") < 0 + || buffer_put(b, fmt, uint_fmt(fmt, boot_verbosity)) < 0 + || buffer_puts(b, " -m 00") < 0 + || buffer_put(b, fmt, uint_ofmt(fmt, initial_umask)) < 0 + || buffer_puts(b, " -c ") < 0 + || !string_quote(&satmp, robase, strlen(robase)) + || buffer_put(b, satmp.s + sabase, satmp.len - sabase) < 0) goto err ; satmp.len = sabase ; - { - char fmt[UINT_OFMT] ; - if (buffer_puts(b, " -m 00") < 0 - || buffer_put(b, fmt, uint_ofmt(fmt, initial_umask)) < 0) return 0 ; - } if (initial_path) { if (buffer_puts(b, " -p ") < 0 - || !string_quote(&satmp, initial_path, strlen(initial_path))) return 0 ; - if (buffer_put(b, satmp.s + sabase, satmp.len - sabase) < 0) goto err ; + || !string_quote(&satmp, initial_path, strlen(initial_path)) + || buffer_put(b, satmp.s + sabase, satmp.len - sabase) < 0) goto err ; satmp.len = sabase ; } if (env_store) { if (buffer_puts(b, " -s ") < 0 - || !string_quote(&satmp, env_store, strlen(env_store))) return 0 ; - if (buffer_put(b, satmp.s + sabase, satmp.len - sabase) < 0) goto err ; + || !string_quote(&satmp, env_store, strlen(env_store)) + || buffer_put(b, satmp.s + sabase, satmp.len - sabase) < 0) goto err ; satmp.len = sabase ; } if (slashdev) { if (buffer_puts(b, " -d ") < 0 - || !string_quote(&satmp, slashdev, strlen(slashdev))) return 0 ; - if (buffer_put(b, satmp.s + sabase, satmp.len - sabase) < 0) goto err ; + || !string_quote(&satmp, slashdev, strlen(slashdev)) + || buffer_put(b, satmp.s + sabase, satmp.len - 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_put(b, satmp.s + sabase, satmp.len - sabase) < 0) goto err ; + || !string_quote(&satmp, initdefault, strlen(initdefault)) + || buffer_put(b, satmp.s + sabase, satmp.len - sabase) < 0) goto err ; satmp.len = sabase ; } if (mounttype == 2) @@ -663,10 +664,11 @@ int main (int argc, char const *const *argv, char const *const *envp) subgetopt l = SUBGETOPT_ZERO ; for (;;) { - int opt = subgetopt_r(argc, argv, "c:u:G:1Lp:m:t:d:s:e:E:q:D:nNf:R:CBS", &l) ; + int opt = subgetopt_r(argc, argv, "V:c:u:G:1Lp:m:t:d:s:e:E:q:D:nNf:R:CBS", &l) ; if (opt == -1) break ; switch (opt) { + case 'V' : if (!uint0_scan(l.arg, &boot_verbosity)) dieusage() ; break ; case 'c' : robase = l.arg ; break ; case 'u' : log_user = l.arg ; break ; case 'G' : early_getty = l.arg ; break ; diff --git a/src/init/s6-linux-init.c b/src/init/s6-linux-init.c index 3c160bf..a8d2b9b 100644 --- a/src/init/s6-linux-init.c +++ b/src/init/s6-linux-init.c @@ -30,7 +30,7 @@ #include "defaults.h" #include "initctl.h" -#define USAGE "s6-linux-init [ -c basedir ] [ -p initpath ] [ -s envdumpdir ] [ -m umask ] [ -d devtmpfs ] [ -D initdefault ] [ -n | -N ] [ -C ] [ -B ]" +#define USAGE "s6-linux-init [ -v verbosity ] [ -c basedir ] [ -p initpath ] [ -s envdumpdir ] [ -m umask ] [ -d devtmpfs ] [ -D initdefault ] [ -n | -N ] [ -C ] [ -B ]" #define dieusage() strerr_dieusage(100, USAGE) #define BANNER "\n s6-linux-init version " S6_LINUX_INIT_VERSION "\n\n" @@ -38,6 +38,7 @@ static int inns = 0 ; static int nologger = 0 ; static int notifpipe[2] ; +static unsigned int verbosity = 1 ; static inline char const *scan_cmdline (char const *initdefault, char const *const *argv, unsigned int argc) { @@ -60,7 +61,7 @@ static inline void wait_for_notif (int fd) if (r < 0) strerr_diefu1sys(111, "read from notification pipe") ; if (!r) { - strerr_warnw1x("s6-svscan failed to send a notification byte!") ; + if (verbosity) strerr_warnw1x("s6-svscan failed to send a notification byte!") ; break ; } if (memchr(buf, '\n', r)) break ; @@ -74,17 +75,23 @@ static void kbspecials (void) if (inns) return ; fd = open("/dev/tty0", O_RDONLY | O_NOCTTY) ; if (fd < 0) - strerr_warnwu2sys("open /dev/", "tty0 (kbrequest will not be handled)") ; + { + if (errno == ENOENT) + { + if (verbosity >= 2) strerr_warni1x("headless system detected") ; + } + else if (verbosity) strerr_warnwu2sys("open", " tty0 (kbrequest will not be handled)") ; + } else { if (ioctl(fd, KDSIGACCEPT, SIGWINCH) < 0) - strerr_warnwu2sys("ioctl KDSIGACCEPT on ", "tty0 (kbrequest will not be handled)") ; + if (verbosity) strerr_warnwu2sys("ioctl KDSIGACCEPT on", " tty0 (kbrequest will not be handled)") ; close(fd) ; } sig_block(SIGINT) ; /* don't panic on early cad before s6-svscan catches it */ if (reboot(RB_DISABLE_CAD) == -1) - strerr_warnwu1sys("trap ctrl-alt-del") ; + if (verbosity) strerr_warnwu1sys("trap ctrl-alt-del") ; } static void opendevnull (void) @@ -92,7 +99,7 @@ static void opendevnull (void) if (open("/dev/null", O_RDONLY)) { /* ghetto /dev/null to the rescue */ int p[2] ; - strerr_warnwu1sys("open /dev/null") ; + if (verbosity) strerr_warnwu1sys("open /dev/null") ; if (pipe(p) < 0) strerr_diefu1sys(111, "pipe") ; close(p[1]) ; if (fd_move(0, p[0]) < 0) strerr_diefu1sys(111, "fd_move to stdin") ; @@ -118,7 +125,7 @@ static inline void run_stage2 (char const *basedir, char const **argv, unsigned close(0) ; if (openb_read(tty)) { - strerr_warnwu2sys("open ", tty) ; + if (verbosity) strerr_warnwu2sys("open ", tty) ; opendevnull() ; } } @@ -170,10 +177,11 @@ int main (int argc, char const **argv, char const *const *envp) subgetopt l = SUBGETOPT_ZERO ; for (;;) { - int opt = subgetopt_r(argc, argv, "c:p:s:m:d:D:nNCB", &l) ; + int opt = subgetopt_r(argc, argv, "v:c:p:s:m:d:D:nNCB", &l) ; if (opt == -1) break ; switch (opt) { + case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; case 'c' : basedir = l.arg ; break ; case 'p' : path = l.arg ; break ; case 's' : envdumpdir = l.arg ; break ; @@ -201,13 +209,13 @@ int main (int argc, char const **argv, char const *const *envp) } else { - if (r) strerr_warnw1x("parent wrote to fd 3!") ; + if (r) if (verbosity) strerr_warnw1x("parent wrote to fd 3!") ; close(3) ; } if (!slashdev && hasconsole && isatty(2 - nologger)) { tty = ttyname(2 - nologger) ; - if (!tty) strerr_warnwu2sys("ttyname std", nologger ? "err" : "out") ; + if (!tty) if (verbosity) strerr_warnwu2sys("ttyname std", nologger ? "err" : "out") ; } } else if (hasconsole) allwrite(1, BANNER, sizeof(BANNER) - 1) ; @@ -253,7 +261,7 @@ int main (int argc, char const **argv, char const *const *envp) if (umount(S6_LINUX_INIT_TMPFS) == -1) { if (errno != EINVAL) - strerr_warnwu1sys("umount " S6_LINUX_INIT_TMPFS) ; + if (verbosity) strerr_warnwu1sys("umount " S6_LINUX_INIT_TMPFS) ; } if (mount("tmpfs", S6_LINUX_INIT_TMPFS, "tmpfs", MS_NODEV | MS_NOSUID, "mode=0755") == -1) strerr_diefu1sys(111, "mount tmpfs on " S6_LINUX_INIT_TMPFS) ; @@ -270,10 +278,10 @@ int main (int argc, char const **argv, char const *const *envp) strerr_diefu3sys(111, "copy ", fn, " to " S6_LINUX_INIT_TMPFS) ; memcpy(fn + dirlen + 1, ENVSTAGE1, sizeof(ENVSTAGE1)) ; if (envdir_internal(fn, &envmodifs, SKALIBS_ENVDIR_VERBATIM | SKALIBS_ENVDIR_NOCLAMP, '\n') == -1) - strerr_warnwu2sys("envdir ", fn) ; + if (verbosity) strerr_warnwu2sys("envdir ", fn) ; } if (envdumpdir && !env_dump(envdumpdir, 0700, envp)) - strerr_warnwu2sys("dump kernel environment to ", envdumpdir) ; + if (verbosity) strerr_warnwu2sys("dump kernel environment to ", envdumpdir) ; if (!nologger) { @@ -300,7 +308,8 @@ int main (int argc, char const **argv, char const *const *envp) newenvp[0] = pathvar ; } if (nologger && pipe(notifpipe) < 0) strerr_diefu1sys(111, "pipe") ; - if (tty && !slashdev && ioctl(2 - nologger, TIOCNOTTY) == -1) strerr_warnwu1sys("relinquish control terminal") ; + if (tty && !slashdev && ioctl(2 - nologger, TIOCNOTTY) == -1) + if (verbosity) strerr_warnwu1sys("relinquish control terminal") ; pid = fork() ; if (pid == -1) strerr_diefu1sys(111, "fork") ; |