From dfa16e4a89158f3d3198db71e2eba3bda9330078 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 10 Sep 2016 13:29:56 +0000 Subject: Make s6-linux-init a real init package. This means: - removing leaky options to s6-linux-init-maker. Default initial_path is now always /usr/bin:/bin; the uid and gid of the catch-all logger (used at boot time) can now be given numerically instead of relying on the (run-time) user db mapping. - moving s6-halt, s6-poweroff and s6-reboot over here, from s6-linux-utils - clarifying on the documentation a bit. --- doc/index.html | 6 ++- doc/quickstart.html | 11 ++++- doc/s6-halt.html | 55 +++++++++++++++++++++ doc/s6-linux-init-maker.html | 110 +++++++++++++++++++++++++---------------- doc/s6-poweroff.html | 55 +++++++++++++++++++++ doc/s6-reboot.html | 55 +++++++++++++++++++++ doc/upgrade.html | 7 +++ package/deps.mak | 10 ++++ package/modes | 3 ++ package/targets.mak | 5 +- src/init/deps-exe/s6-halt | 1 + src/init/deps-exe/s6-poweroff | 1 + src/init/deps-exe/s6-reboot | 1 + src/init/hpr.c | 44 +++++++++++++++++ src/init/s6-halt.c | 7 +++ src/init/s6-linux-init-maker.c | 43 +++++++--------- src/init/s6-poweroff.c | 7 +++ src/init/s6-reboot.c | 7 +++ 18 files changed, 359 insertions(+), 69 deletions(-) create mode 100644 doc/s6-halt.html create mode 100644 doc/s6-poweroff.html create mode 100644 doc/s6-reboot.html create mode 100644 src/init/deps-exe/s6-halt create mode 100644 src/init/deps-exe/s6-poweroff create mode 100644 src/init/deps-exe/s6-reboot create mode 100644 src/init/hpr.c create mode 100644 src/init/s6-halt.c create mode 100644 src/init/s6-poweroff.c create mode 100644 src/init/s6-reboot.c diff --git a/doc/index.html b/doc/index.html index 47226b4..5c39b78 100644 --- a/doc/index.html +++ b/doc/index.html @@ -64,7 +64,8 @@ a small FAQ.

When you build s6-linux-init, the s6-linux-init-maker tool -is created; then you run that tool to create an init script, +is created (as well as the shutdown commands); + then you run that tool to create an init script, and then you can boot your system on that init script.

@@ -122,6 +123,9 @@ the previous versions of s6-linux-init and the current one.

Related resources

diff --git a/doc/quickstart.html b/doc/quickstart.html index bd758b1..dac9779 100644 --- a/doc/quickstart.html +++ b/doc/quickstart.html @@ -20,7 +20,7 @@

Quickstart

-

The examples/ subdirectory of the s6-linux-init package @@ -251,11 +266,24 @@ launcher and the first few early commands before PATH can be set. found. It must be absolute. Default is /bin.

-

  • -u log_user : the catch-all -logger will not run as root, but as log_user. Default is -nobody.
  • +

  • -u log_uid : the catch-all +logger will run with the uid log_uid. Default is 0.
  • + +

  • -g log_gid : the catch-all +logger will run with the gid log_gid. Default is 0.
  • + +

  • -U : the correct log_uid and +log_gid values for the catch-all logger will be read from the +UID and GID environment variables that have been passed to +s6-linux-init-maker. This allows for invocations such as +s6-envuidgid nobody s6-linux-init-maker -U ... so that +the catch-all logger runs as the nobody user. Be aware that +this option is only safe when the user database on the +boot-time machine is the same as on the run-time +machine, else the catch-all logger may run with an unexpected uid +and gid.
  • -
  • -g early_getty : if this option +
  • -G early_getty : if this option is set, s6-linux-init-maker will define a service that will run very early, before stage2 is executed. This early service should be a getty, to allow logins even if stage2 fails. @@ -297,9 +325,7 @@ absolutely necessary for s6-portable-utils and s6-linux-utils binaries to be accessible via initial_path, else the machine -will not boot. Default is the value that has been compiled in -skalibs via the ---with-default-path configure option, i.e. by default +will not boot. Default is /usr/bin:/bin.
  • -m initial_umask : the value of diff --git a/doc/s6-poweroff.html b/doc/s6-poweroff.html new file mode 100644 index 0000000..9a268af --- /dev/null +++ b/doc/s6-poweroff.html @@ -0,0 +1,55 @@ + + + + + + s6-linux-init: the s6-poweroff program + + + + + + +

    +s6-linux-init
    +Software
    +skarnet.org +

    + +

    The s6-poweroff program

    + +

    +s6-poweroff sends a signal to process 1 in order to power off the machine; +or, with the -f option, it performs an immediate hard shutdown. +

    + +

    Interface

    + +
    +     s6-poweroff [ -h | -p | -r ] [ -f ]
    +
    + + + +

    Options

    + + + + + diff --git a/doc/s6-reboot.html b/doc/s6-reboot.html new file mode 100644 index 0000000..e116235 --- /dev/null +++ b/doc/s6-reboot.html @@ -0,0 +1,55 @@ + + + + + + s6-linux-init: the s6-reboot program + + + + + + +

    +s6-linux-init
    +Software
    +skarnet.org +

    + +

    The s6-reboot program

    + +

    +s6-reboot sends a signal to process 1 in order to reboot the machine; +or, with the -f option, it performs an immediate reboot. +

    + +

    Interface

    + +
    +     s6-reboot [ -h | -p | -r ] [ -f ]
    +
    + + + +

    Options

    + + + + + diff --git a/doc/upgrade.html b/doc/upgrade.html index 49dbb2e..bc2c722 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -31,6 +31,13 @@ dependency bumped to 2.1.0.0.
  • dependency bumped to 2.2.0.0.
  • s6 dependency bumped to 2.4.0.0.
  • +
  • s6-halt, + s6-poweroff and + s6-reboot moved from +s6-linux-utils +to s6-linux-init.
  • +
  • s6-linux-init-maker +options modified. (Read the documentation!)
  • in 0.1.0.0

    diff --git a/package/deps.mak b/package/deps.mak index f1fb7db..95fbd4b 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -2,7 +2,17 @@ # This file has been generated by tools/gen-deps.sh # +src/init/hpr.o src/init/hpr.lo: src/init/hpr.c +src/init/s6-halt.o src/init/s6-halt.lo: src/init/s6-halt.c src/init/s6-linux-init-maker.o src/init/s6-linux-init-maker.lo: src/init/s6-linux-init-maker.c +src/init/s6-poweroff.o src/init/s6-poweroff.lo: src/init/s6-poweroff.c +src/init/s6-reboot.o src/init/s6-reboot.lo: src/init/s6-reboot.c +s6-halt: EXTRA_LIBS := +s6-halt: src/init/s6-halt.o -lskarnet s6-linux-init-maker: EXTRA_LIBS := s6-linux-init-maker: src/init/s6-linux-init-maker.o -lskarnet +s6-poweroff: EXTRA_LIBS := +s6-poweroff: src/init/s6-poweroff.o -lskarnet +s6-reboot: EXTRA_LIBS := +s6-reboot: src/init/s6-reboot.o -lskarnet diff --git a/package/modes b/package/modes index 4b115b4..f2fafad 100644 --- a/package/modes +++ b/package/modes @@ -1 +1,4 @@ s6-linux-init-maker 0700 +s6-halt 0700 +s6-poweroff 0700 +s6-reboot 0700 diff --git a/package/targets.mak b/package/targets.mak index 2330c89..83ed8c5 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -1,6 +1,9 @@ BIN_TARGETS := SBIN_TARGETS := \ -s6-linux-init-maker +s6-linux-init-maker \ +s6-halt \ +s6-poweroff \ +s6-reboot LIBEXEC_TARGETS := diff --git a/src/init/deps-exe/s6-halt b/src/init/deps-exe/s6-halt new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/init/deps-exe/s6-halt @@ -0,0 +1 @@ +-lskarnet diff --git a/src/init/deps-exe/s6-poweroff b/src/init/deps-exe/s6-poweroff new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/init/deps-exe/s6-poweroff @@ -0,0 +1 @@ +-lskarnet diff --git a/src/init/deps-exe/s6-reboot b/src/init/deps-exe/s6-reboot new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/init/deps-exe/s6-reboot @@ -0,0 +1 @@ +-lskarnet diff --git a/src/init/hpr.c b/src/init/hpr.c new file mode 100644 index 0000000..0e1c27a --- /dev/null +++ b/src/init/hpr.c @@ -0,0 +1,44 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include + +#define USAGE PROGNAME " [ -h | -p | -r ] [ -f ]" + +int main (int argc, char const *const *argv) +{ + int what = WHATDEFAULT ; + int force = 0 ; + PROG = PROGNAME ; + + { + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + register int opt = subgetopt_r(argc, argv, "hprf", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'h' : what = 1 ; break ; + case 'p' : what = 2 ; break ; + case 'r' : what = 3 ; break ; + case 'f' : force = 1 ; break ; + default : strerr_dieusage(100, USAGE) ; + } + } + argc -= l.ind ; argv += l.ind ; + } + + if (force) + { + sync() ; + reboot(what == 3 ? RB_AUTOBOOT : what == 2 ? RB_POWER_OFF : RB_HALT_SYSTEM) ; + strerr_diefu1sys(111, "reboot()") ; + } + else if (kill(1, what == 3 ? SIGINT : what == 2 ? SIGUSR1 : SIGUSR2) < 0) + strerr_diefu1sys(111, "signal process 1") ; + return 0 ; +} diff --git a/src/init/s6-halt.c b/src/init/s6-halt.c new file mode 100644 index 0000000..d758030 --- /dev/null +++ b/src/init/s6-halt.c @@ -0,0 +1,7 @@ +/* ISC license. */ + +#undef PROGNAME +#define PROGNAME "s6-halt" +#undef WHATDEFAULT +#define WHATDEFAULT 1 +#include "hpr.c" diff --git a/src/init/s6-linux-init-maker.c b/src/init/s6-linux-init-maker.c index c37b67c..60c5353 100644 --- a/src/init/s6-linux-init-maker.c +++ b/src/init/s6-linux-init-maker.c @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include #include #include @@ -13,12 +11,13 @@ #include #include #include +#include #include #include #include #include -#define USAGE "s6-linux-init-maker [ -c basedir ] [ -l tmpfsdir ] [ -b execline_bindir ] [ -u log_user ] [ -g early_getty_cmd ] [ -2 stage2_script ] [ -r ] [ -Z finish_script ] [ -3 stage3_script ] [ -p initial_path ] [ -m initial_umask ] [ -t timestamp_style ] [ -d dev_style ] [ -s env_store ] [ -e initial_envvar ... ] dir" +#define USAGE "s6-linux-init-maker [ -c basedir ] [ -l tmpfsdir ] [ -b execline_bindir ] [ -u log_uid -g log_gid | -U ] [ -G early_getty_cmd ] [ -2 stage2_script ] [ -r ] [ -Z finish_script ] [ -3 stage3_script ] [ -p initial_path ] [ -m initial_umask ] [ -t timestamp_style ] [ -d dev_style ] [ -s env_store ] [ -e initial_envvar ... ] dir" #define dieusage() strerr_dieusage(100, USAGE) #define dienomem() strerr_diefu1sys(111, "stralloc_catb") ; @@ -38,11 +37,11 @@ static char const *init_script = "/etc/rc.init" ; static char const *tini_script = "/etc/rc.tini" ; static char const *shutdown_script = "/etc/rc.shutdown" ; static char const *bindir = "/bin" ; -static char const *initial_path = SKALIBS_DEFAULTPATH ; +static char const *initial_path = "/usr/bin:/bin" ; static char const *env_store = 0 ; static char const *early_getty = 0 ; -static uid_t uncaught_logs_uid ; -static gid_t uncaught_logs_gid ; +static uid_t uncaught_logs_uid = 0 ; +static gid_t uncaught_logs_gid = 0 ; static unsigned int initial_umask = 022 ; static unsigned int timestamp_style = 1 ; static unsigned int slashdev_style = 2 ; @@ -356,23 +355,32 @@ static inline void make_image (char const *base) auto_script(base, "init", &stage1_script) ; } -int main (int argc, char const *const *argv) +int main (int argc, char const *const *argv, char const *const *envp) { - char const *catchall_user = "nobody" ; PROG = "s6-linux-init-maker" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "c:l:b:u:g:2:rZ:3:p:m:t:d:s:e:", &l) ; + register int opt = subgetopt_r(argc, argv, "c:l:b:u:g:UG:2:rZ:3:p:m:t:d:s:e:", &l) ; if (opt == -1) break ; switch (opt) { case 'c' : robase = l.arg ; break ; case 'l' : slashrun = l.arg ; break ; case 'b' : bindir = l.arg ; break ; - case 'u' : catchall_user = l.arg ; break ; - case 'g' : early_getty = l.arg ; break ; + case 'u' : if (!uint0_scan(l.arg, &uncaught_logs_uid)) dieusage() ; break ; + case 'g' : if (!uint0_scan(l.arg, &uncaught_logs_gid)) dieusage() ; break ; + case 'U' : + { + char const *x = env_get2(envp, "UID") ; + if (!x) strerr_dienotset(100, "UID") ; + if (!uint0_scan(x, &uncaught_logs_uid)) strerr_dieinvalid(100, "UID") ; + x = env_get2(envp, "GID") ; + if (!x) strerr_dienotset(100, "GID") ; + if (!uint0_scan(x, &uncaught_logs_gid)) strerr_dieinvalid(100, "GID") ; + } + case 'G' : early_getty = l.arg ; break ; case '2' : init_script = l.arg ; break ; case 'r' : redirect_stage2 = 1 ; break ; case 'Z' : tini_script = l.arg ; break ; @@ -407,19 +415,6 @@ int main (int argc, char const *const *argv) if (slashdev_style > 2) strerr_dief1x(100, "-d dev_style must be 0, 1 or 2") ; - { - struct passwd *pw = getpwnam(catchall_user) ; - if (!pw) - { - if (errno) - strerr_diefu2sys(111, "getpwnam for ", catchall_user) ; - else - strerr_dief3x(100, "getpwnam for ", catchall_user, ": no such user") ; - } - uncaught_logs_uid = pw->pw_uid ; - uncaught_logs_gid = pw->pw_gid ; - } - if (mkdir(argv[0], 0755) < 0) strerr_diefu2sys(111, "mkdir ", argv[0]) ; diff --git a/src/init/s6-poweroff.c b/src/init/s6-poweroff.c new file mode 100644 index 0000000..f9f7747 --- /dev/null +++ b/src/init/s6-poweroff.c @@ -0,0 +1,7 @@ +/* ISC license. */ + +#undef PROGNAME +#define PROGNAME "s6-poweroff" +#undef WHATDEFAULT +#define WHATDEFAULT 2 +#include "hpr.c" diff --git a/src/init/s6-reboot.c b/src/init/s6-reboot.c new file mode 100644 index 0000000..0bf8785 --- /dev/null +++ b/src/init/s6-reboot.c @@ -0,0 +1,7 @@ +/* ISC license. */ + +#undef PROGNAME +#define PROGNAME "s6-reboot" +#undef WHATDEFAULT +#define WHATDEFAULT 3 +#include "hpr.c" -- cgit v1.3.1