summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2016-09-10 13:29:56 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2016-09-10 13:29:56 +0000
commitdfa16e4a89158f3d3198db71e2eba3bda9330078 (patch)
treecfa8399e5348c35eae05f59aa0ea8e2e20bd14ba /src
parentdfc83dd740beaa46b637b87b5a804abf1cff7bee (diff)
downloads6-linux-init-dfa16e4a89158f3d3198db71e2eba3bda9330078.tar.xz
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.
Diffstat (limited to 'src')
-rw-r--r--src/init/deps-exe/s6-halt1
-rw-r--r--src/init/deps-exe/s6-poweroff1
-rw-r--r--src/init/deps-exe/s6-reboot1
-rw-r--r--src/init/hpr.c44
-rw-r--r--src/init/s6-halt.c7
-rw-r--r--src/init/s6-linux-init-maker.c43
-rw-r--r--src/init/s6-poweroff.c7
-rw-r--r--src/init/s6-reboot.c7
8 files changed, 87 insertions, 24 deletions
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 <unistd.h>
+#include <signal.h>
+#include <sys/reboot.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/sgetopt.h>
+
+#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 <sys/stat.h>
#include <unistd.h>
#include <errno.h>
-#include <pwd.h>
-#include <skalibs/config.h>
#include <skalibs/uint64.h>
#include <skalibs/uint.h>
#include <skalibs/gidstuff.h>
@@ -13,12 +11,13 @@
#include <skalibs/allreadwrite.h>
#include <skalibs/buffer.h>
#include <skalibs/strerr2.h>
+#include <skalibs/env.h>
#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>
#include <skalibs/sgetopt.h>
#include <skalibs/skamisc.h>
-#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"