summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2019-04-16 20:37:01 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2019-04-16 20:37:01 +0000
commit73cff35173dd75b0254ae7cf9098c32822859de0 (patch)
treefd1bb09611b2b7064967ca8d8b2aef98514e616b /src
parent5199738f4e32773f4f752a94998593e18e3af36f (diff)
downloads6-linux-init-73cff35173dd75b0254ae7cf9098c32822859de0.tar.xz
It builds! Tomorrow: skeletons for stage2, stage3 and runlevel scripts.
Diffstat (limited to 'src')
-rw-r--r--src/include-local/defaults.h1
-rw-r--r--src/include-local/initctl.h4
-rw-r--r--src/init/deps-exe/s6-linux-init-telinit (renamed from src/state/deps-exe/s6-linux-init-single)0
-rw-r--r--src/init/s6-linux-init-maker.c148
-rw-r--r--src/init/s6-linux-init-telinit.c72
-rw-r--r--src/misc/deps-exe/s6-linux-init-echo1
-rw-r--r--src/misc/deps-exe/s6-linux-init-logouthookd (renamed from src/logout-hook/deps-exe/s6-linux-init-logouthookd)0
-rw-r--r--src/misc/deps-exe/s6-linux-init-umountall1
-rw-r--r--src/misc/s6-linux-init-echo.c39
-rw-r--r--src/misc/s6-linux-init-logouthookd.c (renamed from src/logout-hook/s6-linux-init-logouthookd.c)0
-rw-r--r--src/misc/s6-linux-init-umountall.c70
-rw-r--r--src/shutdown/deps-exe/s6-linux-init-halt (renamed from src/state/deps-exe/s6-linux-init-halt)0
-rw-r--r--src/shutdown/deps-exe/s6-linux-init-poweroff (renamed from src/state/deps-exe/s6-linux-init-poweroff)0
-rw-r--r--src/shutdown/deps-exe/s6-linux-init-reboot (renamed from src/state/deps-exe/s6-linux-init-reboot)0
-rw-r--r--src/shutdown/deps-exe/s6-linux-init-shutdown (renamed from src/state/deps-exe/s6-linux-init-shutdown)0
-rw-r--r--src/shutdown/deps-exe/s6-linux-init-shutdownd (renamed from src/state/deps-exe/s6-linux-init-shutdownd)0
-rw-r--r--src/shutdown/deps-lib/hpr2
-rw-r--r--src/shutdown/hpr.c (renamed from src/state/hpr.c)4
-rw-r--r--src/shutdown/hpr.h (renamed from src/state/hpr.h)4
-rw-r--r--src/shutdown/hpr_shutdown.c (renamed from src/state/hpr_shutdown.c)0
-rw-r--r--src/shutdown/hpr_wall.c (renamed from src/state/hpr_wall.c)0
-rw-r--r--src/shutdown/s6-linux-init-halt.c (renamed from src/state/s6-linux-init-halt.c)0
-rw-r--r--src/shutdown/s6-linux-init-poweroff.c (renamed from src/state/s6-linux-init-poweroff.c)0
-rw-r--r--src/shutdown/s6-linux-init-reboot.c (renamed from src/state/s6-linux-init-reboot.c)0
-rw-r--r--src/shutdown/s6-linux-init-shutdown.c (renamed from src/state/s6-linux-init-shutdown.c)2
-rw-r--r--src/shutdown/s6-linux-init-shutdownd.c (renamed from src/state/s6-linux-init-shutdownd.c)49
-rw-r--r--src/state/deps-exe/s6-linux-init-telinit2
-rw-r--r--src/state/deps-lib/hpr4
-rw-r--r--src/state/hpr_fmttime.c52
-rw-r--r--src/state/hpr_wall_seconds.c12
-rw-r--r--src/state/s6-linux-init-single.c54
-rw-r--r--src/state/s6-linux-init-telinit.c42
32 files changed, 291 insertions, 272 deletions
diff --git a/src/include-local/defaults.h b/src/include-local/defaults.h
index dc36e0f..a22693b 100644
--- a/src/include-local/defaults.h
+++ b/src/include-local/defaults.h
@@ -3,7 +3,6 @@
#ifndef S6_LINUX_INIT_DEFAULTS_H
#define S6_LINUX_INIT_DEFAULTS_H
-#define BINDIR "/bin"
#define BASEDIR "/etc/s6-linux-init"
#define INITPATH "/usr/bin:/bin"
diff --git a/src/include-local/initctl.h b/src/include-local/initctl.h
index 4102640..6610de8 100644
--- a/src/include-local/initctl.h
+++ b/src/include-local/initctl.h
@@ -11,6 +11,10 @@
#define SHUTDOWND_FIFO "fifo"
#define INITCTL S6_LINUX_INIT_TMPFS "/" SCANDIR "/" SHUTDOWND_SERVICEDIR "/" SHUTDOWND_FIFO
+#define RUNLEVELD_SERVICEDIR "s6-linux-init-runleveld"
+#define RUNLEVELD_SOCKET "s"
+#define RUNLEVELD_PATH S6_LINUX_INIT_TMPFS "/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/" RUNLEVELD_SOCKET
+
#define LOGOUTHOOKD_SERVICEDIR "s6-linux-init-logouthookd"
#define LOGOUTHOOKD_SOCKET "s"
#define LOGOUTHOOKD_PATH S6_LINUX_INIT_TMPFS "/" SCANDIR "/" LOGOUTHOOKD_SERVICEDIR "/" LOGOUTHOOKD_SOCKET
diff --git a/src/state/deps-exe/s6-linux-init-single b/src/init/deps-exe/s6-linux-init-telinit
index e7187fe..e7187fe 100644
--- a/src/state/deps-exe/s6-linux-init-single
+++ b/src/init/deps-exe/s6-linux-init-telinit
diff --git a/src/init/s6-linux-init-maker.c b/src/init/s6-linux-init-maker.c
index ede9a52..2470c4d 100644
--- a/src/init/s6-linux-init-maker.c
+++ b/src/init/s6-linux-init-maker.c
@@ -16,29 +16,21 @@
#include <skalibs/sgetopt.h>
#include <skalibs/skamisc.h>
+#include <execline/config.h>
+
#include <s6/config.h>
#include <s6-linux-init/config.h>
#include "defaults.h"
#include "initctl.h"
-#define USAGE "s6-linux-init-maker [ -c basedir ] [ -b execline_bindir ] [ -u log_uid -g log_gid | -U ] [ -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 ] dir"
+#define USAGE "s6-linux-init-maker [ -c basedir ] [ -u log_uid -g log_gid | -U ] [ -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 ] dir"
#define dieusage() strerr_dieusage(100, USAGE)
#define dienomem() strerr_diefu1sys(111, "stralloc_catb") ;
#define UNCAUGHT_DIR "uncaught-logs"
-#define EXITCODENAME "file\\ created\\ by\\ s6-linux-init,\\ storing\\ a\\ container's\\ exit\\ code"
-
-#define CRASH_SCRIPT \
-"redirfd -r 0 /dev/console\n" \
-"redirfd -w 1 /dev/console\n" \
-"fdmove -c 2 1\n" \
-"foreground { s6-echo -- " \
-"\"s6-svscan finished. Dropping to an interactive shell.\" }\n" \
-"/bin/sh -i\n"
static char const *robase = BASEDIR ;
-static char const *bindir = BINDIR ;
static char const *initial_path = INITPATH ;
static char const *env_store = 0 ;
static char const *early_getty = 0 ;
@@ -51,65 +43,59 @@ static unsigned int finalsleep = 3000 ;
static int console = 0 ;
static int logouthookd = 0 ;
-typedef int writetobuf_func_t (buffer *, void *) ;
+typedef int writetobuf_func_t (buffer *, char const *) ;
typedef writetobuf_func_t *writetobuf_func_t_ref ;
#define put_shebang(b) put_shebang_options((b), "-P")
-static int put_shebang_options (buffer *b, void *data)
+static int put_shebang_options (buffer *b, char const *options)
{
- char *options = data ;
- return buffer_puts(b, "#!") >= 0
- && buffer_puts(b, bindir) >= 0
- && buffer_puts(b, "/execlineb") >= 0
+ return buffer_puts(b, "#!" EXECLINE_SHEBANGPREFIX "/execlineb") >= 0
&& (!options || !options[0] || buffer_puts(b, " ") >= 0)
&& buffer_puts(b, options) >= 0
&& buffer_puts(b, "\n\n") >= 0 ;
}
-static int line_script (buffer *b, void *data)
+static int line_script (buffer *b, char const *line)
{
- char *line = data ;
return put_shebang(b)
&& buffer_puts(b, line) >= 0
&& buffer_put(b, "\n", 1) >= 0 ;
}
-static int linewithargs_script (buffer *b, void *data)
+static int linewithargs_script (buffer *b, char const *line)
{
- char *line = data ;
return put_shebang_options(b, "-S0")
&& buffer_puts(b, line) >= 0
&& buffer_puts(b, " $@\n") >= 0 ;
}
-static int death_script (buffer *b, void *data)
+static int death_script (buffer *b, char const *s)
{
- char *s = data ;
return put_shebang(b)
&& buffer_puts(b,
- "redirfd -r 0 /dev/console\n"
- "redirfd -w 1 /dev/console\n"
- "fdmove -c 2 1\n"
- "foreground { s6-echo -- \"s6-svscan ") >= 0
+ EXECLINE_EXTBINPREFIX "redirfd -r 0 /dev/console\n"
+ EXECLINE_EXTBINPREFIX "redirfd -w 1 /dev/console\n"
+ EXECLINE_EXTBINPREFIX "fdmove -c 2 1\n"
+ EXECLINE_EXTBINPREFIX "foreground { "
+ S6_LINUX_INIT_LIBEXECPREFIX "s6-linux-init-echo -- \"s6-svscan ") >= 0
&& buffer_puts(b, s) >= 0
&& buffer_puts(b,
". Dropping to an interactive shell.\" }\n"
- "/bin/sh -i\n") >= 0
+ "/bin/sh -i\n") >= 0 ;
}
-static int s6_svscan_log_script (buffer *b, void *data)
+static int s6_svscan_log_script (buffer *b, char const *data)
{
char fmt[UINT64_FMT] ;
- (void)data ;
if (!put_shebang(b)
|| buffer_puts(b,
- "redirfd -w 2 /dev/console\n"
- "redirfd -w 1 /dev/") < 0
+ EXECLINE_EXTBINPREFIX "redirfd -w 2 /dev/console\n"
+ EXECLINE_EXTBINPREFIX "redirfd -w 1 /dev/") < 0
|| buffer_puts(b, console ? "console" : "null") < 0
|| buffer_puts(b, "\n"
- "redirfd -rnb 0 " LOGGER_FIFO "\n"
- "s6-applyuidgid -u ") < 0
+ EXECLINE_EXTBINPREFIX "redirfd -rnb 0 " LOGGER_FIFO "\n"
+ S6_EXTBINPREFIX "s6-applyuidgid -u ") < 0
|| buffer_put(b, fmt, uid_fmt(fmt, uncaught_logs_uid)) < 0
|| buffer_puts(b, " -g ") < 0
|| buffer_put(b, fmt, gid_fmt(fmt, uncaught_logs_gid)) < 0
@@ -126,33 +112,30 @@ static int s6_svscan_log_script (buffer *b, void *data)
|| timestamp_style & 2 && buffer_puts(b, "T ") < 0
|| buffer_puts(b, S6_LINUX_INIT_TMPFS "/" UNCAUGHT_DIR "\n") < 0)
return 0 ;
+ (void)data ;
return 1 ;
}
-static int logouthookd_script (buffer *b, void *data)
+static int logouthookd_script (buffer *b, char const *data)
{
(void)data ;
return put_shebang(b)
&& buffer_puts(b,
S6_EXTBINPREFIX "s6-ipcserver -1 -l0 -- " LOGOUTHOOKD_SOCKET "\n"
- S6_LINUX_INIT_BINPREFIX "s6-linux-init-logouthookd\n") >= 0 ;
+ S6_LINUX_INIT_LIBEXECPREFIX "s6-linux-init-logouthookd\n") >= 0 ;
}
-static int shutdownd_script (buffer *b, void *data)
+static int shutdownd_script (buffer *b, char const *data)
{
size_t sabase = satmp.len ;
char fmt[UINT_FMT] ;
if (!put_shebang(b)
- || buffer_puts(b, S6_LINUX_INIT_BINPREFIX "s6-linux-init-shutdownd -b ") < 0)
- || !string_quote(&satmp, bindir, strlen(bindir))) return 0 ;
- if (buffer_puts(b, satmp.s + sabase) < 0) goto err ;
- satmp.len = sabase ;
- if (buffer_puts(b, " -c ") < 0
+ || buffer_puts(b, S6_LINUX_INIT_LIBEXECPREFIX "s6-linux-init-shutdownd -c ") < 0
|| !string_quote(&satmp, robase, strlen(robase))) return 0 ;
if (buffer_puts(b, satmp.s + sabase) < 0) goto err ;
satmp.len = sabase ;
if (buffer_puts(b, " -g ") < 0
- || buffer_puts(b, fmt, uint_fmt(fmt, finalsleep)) < 0
+ || buffer_put(b, fmt, uint_fmt(fmt, finalsleep)) < 0
|| buffer_puts(b, "\n") < 0) return 0 ;
(void)data ;
return 1 ;
@@ -162,25 +145,42 @@ static int shutdownd_script (buffer *b, void *data)
return 0 ;
}
-static int sig_script (buffer *b, void *data)
+static int runleveld_script (buffer *b, char const *data)
{
- char *option = data ;
- return put_shebang(b)
- && buffer_puts(b, S6_LINUX_INIT_BINPREFIX "s6-linux-init-shutdown -a ") >= 0
- && buffer_puts(b, option) >= 0
- && buffer_puts(" -- now\n") >= 0 ;
+ size_t sabase = satmp.len ;
+ if (!put_shebang(b)
+ || buffer_puts(b,
+ EXECLINE_EXTBINPREFIX "fdmove -c 2 1\n"
+ EXECLINE_EXTBINPREFIX "fdmove 1 3\n"
+ S6_EXTBINPREFIX "s6-ipcserver-socketbinder -- " RUNLEVELD_SOCKET "\n"
+ S6_EXTBINPREFIX "s6-ipcserverd -1 -c1 --\n"
+ S6_EXTBINPREFIX "s6-ipcserver-access -v0 -E -l0 -i data/rules --\n"
+ S6_EXTBINPREFIX "s6-sudod -0 -1 -2 -t 30000 --\n") < 0
+ || !string_quote(&satmp, robase, strlen(robase))) return 0 ;
+ if (buffer_puts(b, satmp.s + sabase) < 0) goto err ;
+ satmp.len = sabase ;
+ if (buffer_puts(b, "/scripts/runlevel\n") < 0) return 0 ;
+ (void)data ;
+ return 1 ;
+
+ err:
+ satmp.len = sabase ;
+ return 0 ;
}
-static int stage4_script (buffer *b, void *data)
+static int sig_script (buffer *b, char const *option)
{
- (void)data ;
+ return put_shebang(b)
+ && buffer_puts(b, S6_LINUX_INIT_LIBEXECPREFIX "s6-linux-init-shutdown -a ") >= 0
+ && buffer_puts(b, option) >= 0
+ && buffer_puts(b, " -- now\n") >= 0 ;
}
-static inline int stage1_script (buffer *b)
+static inline int stage1_script (buffer *b, char const *data)
{
size_t sabase = satmp.len ;
if (!put_shebang_options(b, "-S0")
- || buffer_puts(b, S6_LINUX_INIT_EXTBINPREFIX "s6-linux-init -c ") < 0
+ || buffer_puts(b, S6_LINUX_INIT_LIBEXECPREFIX "s6-linux-init -c ") < 0
|| !string_quote(&satmp, robase, strlen(robase))) return 0 ;
if (buffer_puts(b, satmp.s + sabase) < 0) goto err ;
satmp.len = sabase ;
@@ -211,6 +211,7 @@ static inline int stage1_script (buffer *b)
satmp.len = sabase ;
}
if (buffer_puts(b, "\n") < 0) return 0 ;
+ (void)data ;
return 1 ;
err:
@@ -250,7 +251,7 @@ static void auto_file (char const *base, char const *file, char const *s, unsign
fn[clen] = '/' ;
memcpy(fn + clen + 1, file, flen + 1) ;
if (!openwritenclose_unsafe(fn, s, n)
- || chmod(fn, executable ? 0755 : 0644) == -1))
+ || chmod(fn, executable ? 0755 : 0644) == -1)
{
cleanup(base) ;
strerr_diefu2sys(111, "write to ", fn) ;
@@ -284,7 +285,7 @@ static void auto_fifo (char const *base, char const *fifo)
}
}
-static void auto_script (char const *base, char const *file, writetobuf_func_t_ref scriptf, void *data)
+static void auto_script (char const *base, char const *file, writetobuf_func_t_ref scriptf, char const *data)
{
char buf[4096] ;
buffer b ;
@@ -312,11 +313,12 @@ static void auto_script (char const *base, char const *file, writetobuf_func_t_r
static void auto_exec (char const *base, char const *name, char const *target)
{
- if (S6_LINUX_INIT_BINPREFIX[0] == '/')
+ if (S6_LINUX_INIT_LIBEXECPREFIX[0] == '/')
{
size_t len = strlen(target) ;
- char fn[sizeof(S6_LINUX_INIT_BINPREFIX) + len] = S6_LINUX_INIT_BINPREFIX ;
- memcpy(fn + sizeof(S6_LINUX_INIT_BINPREFIX - 1, len + 1, target)) ;
+ char fn[sizeof(S6_LINUX_INIT_LIBEXECPREFIX) + len] ;
+ memcpy(fn, S6_LINUX_INIT_LIBEXECPREFIX, sizeof(S6_LINUX_INIT_LIBEXECPREFIX) - 1) ;
+ memcpy(fn + sizeof(S6_LINUX_INIT_LIBEXECPREFIX) - 1, target, len + 1) ;
auto_symlink(base, name, fn) ;
}
else
@@ -358,19 +360,35 @@ static inline void make_image (char const *base)
auto_script(base, "run-image/" SCANDIR "/.s6-svscan/SIGINT", &sig_script, "-r") ;
auto_script(base, "run-image/" SCANDIR "/.s6-svscan/SIGUSR1", &sig_script, "-p") ;
auto_script(base, "run-image/" SCANDIR "/.s6-svscan/SIGUSR2", &sig_script, "-h") ;
+
auto_dir(base, "run-image/" SCANDIR "/" LOGGER_SERVICEDIR, 0, 0, 0755) ;
auto_fifo(base, "run-image/" SCANDIR "/" LOGGER_SERVICEDIR "/" LOGGER_FIFO) ;
auto_file(base, "run-image/" SCANDIR "/" LOGGER_SERVICEDIR "/notification-fd", "3\n", 2, 0) ;
- auto_script(base, "run-image/" SCANDIR "/" LOGGER_SERVICEDIR "/run, &s6_svscan_log_script, 0) ;
+ auto_script(base, "run-image/" SCANDIR "/" LOGGER_SERVICEDIR "/run", &s6_svscan_log_script, 0) ;
+
auto_dir(base, "run-image/" SCANDIR "/" SHUTDOWND_SERVICEDIR, 0, 0, 0755) ;
auto_fifo(base, "run-image/" SCANDIR "/" SHUTDOWND_SERVICEDIR "/" SHUTDOWND_FIFO) ;
auto_script(base, "run-image/" SCANDIR "/" SHUTDOWND_SERVICEDIR "/run", &shutdownd_script, 0) ;
+
+ auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR, 0, 0, 0755) ;
+ auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data", 0, 0, 0755) ;
+ auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules", 0, 0, 0755) ;
+ auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/gid", 0, 0, 0755) ;
+ auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/gid/0", 0, 0, 0755) ;
+ auto_file(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/gid/0/allow", "", 0, 0) ;
+ auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/uid", 0, 0, 0755) ;
+ auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/uid/0", 0, 0, 0755) ;
+ auto_file(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/uid/0/allow", "", 0, 0) ;
+ auto_file(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/notification-fd", "3\n", 2, 0) ;
+ auto_script(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/run", &runleveld_script, 0) ;
+
if (logouthookd)
{
auto_dir(base, "run-image/" SCANDIR "/" LOGOUTHOOKD_SERVICEDIR, 0, 0, 0755) ;
auto_file(base, "run-image/" SCANDIR "/" LOGOUTHOOKD_SERVICEDIR "/notification-fd", "1\n", 2, 0) ;
auto_script(base, "run-image/" SCANDIR "/" LOGOUTHOOKD_SERVICEDIR "/run", &logouthookd_script, 0) ;
}
+
if (early_getty)
{
auto_dir(base, "run-image/" SCANDIR "/" EARLYGETTY_SERVICEDIR, 0, 0, 0755) ;
@@ -395,7 +413,6 @@ static inline void make_bins (char const *base)
auto_exec(base, "bin/shutdown", "s6-linux-init-shutdown") ;
auto_exec(base, "bin/telinit", "s6-linux-init-telinit") ;
auto_script(base, "bin/init", &stage1_script, 0) ;
- auto_script(base, "bin/" STAGE4, &stage4_script, 0) ;
}
int main (int argc, char const *const *argv, char const *const *envp)
@@ -407,12 +424,11 @@ int main (int argc, char const *const *argv, char const *const *envp)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "c:b:u:g:UG:1Lp:m:t:d:s:e:E:q:", &l) ;
+ int opt = subgetopt_r(argc, argv, "c:u:g:UG:1Lp:m:t:d:s:e:E:q:", &l) ;
if (opt == -1) break ;
switch (opt)
{
case 'c' : robase = l.arg ; break ;
- case 'b' : bindir = 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' :
@@ -444,12 +460,6 @@ int main (int argc, char const *const *argv, char const *const *envp)
if (robase[0] != '/')
strerr_dief3x(100, "base directory ", robase, " is not absolute") ;
- if (bindir[0] != '/')
- strerr_dief3x(100, "initial location for binaries ", bindir, " is not absolute") ;
- if (init_script[0] != '/')
- strerr_dief3x(100, "stage 2 script location ", init_script, " is not absolute") ;
- if (tini_script[0] != '/')
- strerr_dief3x(100, "shutdown script location ", tini_script, " is not absolute") ;
if (slashdev && slashdev[0] != '/')
strerr_dief3x(100, "devtmpfs mounting location ", slashdev, " is not absolute") ;
if (timestamp_style > 3)
@@ -463,7 +473,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
stralloc_free(&saenv2) ;
make_env(argv[0], ENVSTAGE1, saenv1.s, saenv1.len) ;
saenv1.len = 0 ;
- make_image(argv[0], &saenv1) ;
+ make_image(argv[0]) ;
make_scripts(argv[0]) ;
make_bins(argv[0]) ;
return 0 ;
diff --git a/src/init/s6-linux-init-telinit.c b/src/init/s6-linux-init-telinit.c
new file mode 100644
index 0000000..8678709
--- /dev/null
+++ b/src/init/s6-linux-init-telinit.c
@@ -0,0 +1,72 @@
+/* ISC license. */
+
+#include <string.h>
+#include <sys/wait.h>
+
+#include <skalibs/types.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/djbunix.h>
+
+#include <s6/config.h>
+
+#include <s6-linux-init/config.h>
+#include "initctl.h"
+
+#define USAGE "s6-linux-init-telinit runlevel"
+#define dieusage() strerr_dieusage(100, USAGE)
+
+int main (int argc, char const *const *argv, char const *const *envp)
+{
+ char const *newargv[8] = { S6_EXTBINPREFIX "s6-sudo", "-e", "-T", "3600000", "--", RUNLEVELD_PATH, 0, 0 } ;
+ PROG = "s6-linux-init-telinit" ;
+ {
+ subgetopt_t l = SUBGETOPT_ZERO ;
+ for (;;)
+ {
+ int opt = subgetopt_r(argc, argv, "c:p:s:m:d:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'c' : /* s6-linux-init may be called with these options, don't choke on them */
+ case 'p' :
+ case 's' :
+ case 'm' :
+ case 'd' : break ;
+ default : dieusage() ;
+ }
+ }
+ argc -= l.ind ; argv += l.ind ;
+ }
+
+ if (!argc) dieusage() ;
+ newargv[6] = argv[0] ;
+
+
+ /* specialcase 0 and 6: fork runlevel call then exec shutdown, instead of execing runlevel call */
+
+ if (!strcmp(argv[0], "0") || !strcmp(argv[0], "6"))
+ {
+ int wstat ;
+ pid_t pid = child_spawn0(newargv[0], newargv, envp) ;
+ if (!pid) strerr_diefu2sys(111, "spawn ", newargv[0]) ;
+ if (wait_pid(pid, &wstat) < 0) strerr_diefu1sys(111, "wait_pid") ;
+ if (WIFSIGNALED(wstat))
+ {
+ char fmt[UINT_FMT] ;
+ fmt[uint_fmt(fmt, WTERMSIG(wstat))] = 0 ;
+ strerr_dief3x(wait_estatus(wstat), newargv[0], " crashed with signal ", fmt) ;
+ }
+ else if (WEXITSTATUS(wstat))
+ {
+ char fmt[UINT_FMT] ;
+ fmt[uint_fmt(fmt, WEXITSTATUS(wstat))] = 0 ;
+ strerr_dief3x(wait_estatus(wstat), newargv[0], " died with exitcode ", fmt) ;
+ }
+
+ newargv[0] = argv[0][0] == '6' ? S6_LINUX_INIT_BINPREFIX "reboot" : S6_LINUX_INIT_BINPREFIX "poweroff" ;
+ newargv[1] = 0 ;
+ }
+
+ xpathexec_run(newargv[0], newargv, envp) ;
+}
diff --git a/src/misc/deps-exe/s6-linux-init-echo b/src/misc/deps-exe/s6-linux-init-echo
new file mode 100644
index 0000000..e7187fe
--- /dev/null
+++ b/src/misc/deps-exe/s6-linux-init-echo
@@ -0,0 +1 @@
+-lskarnet
diff --git a/src/logout-hook/deps-exe/s6-linux-init-logouthookd b/src/misc/deps-exe/s6-linux-init-logouthookd
index 5a7d2fd..5a7d2fd 100644
--- a/src/logout-hook/deps-exe/s6-linux-init-logouthookd
+++ b/src/misc/deps-exe/s6-linux-init-logouthookd
diff --git a/src/misc/deps-exe/s6-linux-init-umountall b/src/misc/deps-exe/s6-linux-init-umountall
new file mode 100644
index 0000000..e7187fe
--- /dev/null
+++ b/src/misc/deps-exe/s6-linux-init-umountall
@@ -0,0 +1 @@
+-lskarnet
diff --git a/src/misc/s6-linux-init-echo.c b/src/misc/s6-linux-init-echo.c
new file mode 100644
index 0000000..d39e649
--- /dev/null
+++ b/src/misc/s6-linux-init-echo.c
@@ -0,0 +1,39 @@
+/* ISC license. */
+
+#include <skalibs/sgetopt.h>
+#include <skalibs/buffer.h>
+#include <skalibs/strerr2.h>
+
+#define USAGE "s6-linux-init-echo [ -n ] [ -s sep ] args..."
+
+int main (int argc, char const *const *argv)
+{
+ char sep = ' ' ;
+ char donl = 1 ;
+ PROG = "s6-echo" ;
+ {
+ subgetopt_t l = SUBGETOPT_ZERO ;
+ for (;;)
+ {
+ int opt = subgetopt_r(argc, argv, "ns:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'n': donl = 0 ; break ;
+ case 's': sep = *l.arg ; break ;
+ default : strerr_dieusage(100, USAGE) ;
+ }
+ }
+ argc -= l.ind ; argv += l.ind ;
+ }
+ for ( ; *argv ; argv++)
+ if ((buffer_puts(buffer_1small, *argv) < 0)
+ || (argv[1] && (buffer_put(buffer_1small, &sep, 1) < 0)))
+ goto err ;
+ if (donl && (buffer_put(buffer_1small, "\n", 1) < 0)) goto err ;
+ if (!buffer_flush(buffer_1small)) goto err ;
+ return 0 ;
+
+ err:
+ strerr_diefu1sys(111, "write to stdout") ;
+}
diff --git a/src/logout-hook/s6-linux-init-logouthookd.c b/src/misc/s6-linux-init-logouthookd.c
index cc542ba..cc542ba 100644
--- a/src/logout-hook/s6-linux-init-logouthookd.c
+++ b/src/misc/s6-linux-init-logouthookd.c
diff --git a/src/misc/s6-linux-init-umountall.c b/src/misc/s6-linux-init-umountall.c
new file mode 100644
index 0000000..24b22fc
--- /dev/null
+++ b/src/misc/s6-linux-init-umountall.c
@@ -0,0 +1,70 @@
+/* ISC license. */
+
+#include <string.h>
+#include <sys/mount.h>
+
+#include <skalibs/bytestr.h>
+#include <skalibs/buffer.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/skamisc.h>
+
+#define BUFSIZE 4096
+#define MAXLINES 512
+
+int main (int argc, char const *const *argv)
+{
+ stralloc mountpoints[MAXLINES] ;
+ char buf[BUFSIZE] ;
+ buffer b ;
+ stralloc sa = STRALLOC_ZERO ;
+ unsigned int line = 0 ;
+ int e = 0 ;
+ int r ;
+ int fd ;
+
+ PROG = "s6-linux-init-umountall" ;
+
+
+ /*
+ We need to go through /proc/mounts *in reverse order*, because later mounts
+ may depend on earlier mounts.
+ The getmntent() family of functions has obviously not been designed for that
+ use case at all, and it is actually more difficult to use it than to do the
+ /proc/mounts parsing by hand. So, we do it by hand with skalibs functions.
+ That's how you can tell a good API from a terrible one.
+ */
+
+ fd = open_readb("/proc/mounts") ;
+ if (fd < 0) strerr_diefu1sys(111, "open /proc/mounts") ;
+ memset(mountpoints, 0, sizeof(mountpoints)) ;
+ buffer_init(&b, &buffer_read, fd, buf, BUFSIZE) ;
+ for (;;)
+ {
+ size_t n, p ;
+ if (line >= MAXLINES) strerr_dief1x(111, "/proc/mounts too big") ;
+ sa.len = 0 ;
+ r = skagetln(&b, &sa, '\n') ;
+ if (r <= 0) break ;
+ p = byte_chr(sa.s, sa.len, ' ') ;
+ if (p >= sa.len) strerr_dief1x(111, "bad /proc/mounts format") ;
+ p++ ;
+ n = byte_chr(sa.s + p, sa.len - p, ' ') ;
+ if (n == sa.len - p) strerr_dief1x(111, "bad /proc/mounts format") ;
+ if (!stralloc_catb(&mountpoints[line], sa.s + p, n) || !stralloc_0(&mountpoints[line]))
+ strerr_diefu1sys(111, "store mount point") ;
+ line++ ;
+ }
+ fd_close(fd) ;
+ stralloc_free(&sa) ;
+ if (r < 0) strerr_diefu1sys(111, "read /proc/mounts") ;
+
+ while (line--)
+ if (umount(mountpoints[line].s) == -1)
+ {
+ e++ ;
+ strerr_warnwu2sys("umount ", mountpoints[line].s) ;
+ }
+ return e ;
+}
diff --git a/src/state/deps-exe/s6-linux-init-halt b/src/shutdown/deps-exe/s6-linux-init-halt
index 0c4376c..0c4376c 100644
--- a/src/state/deps-exe/s6-linux-init-halt
+++ b/src/shutdown/deps-exe/s6-linux-init-halt
diff --git a/src/state/deps-exe/s6-linux-init-poweroff b/src/shutdown/deps-exe/s6-linux-init-poweroff
index 0c4376c..0c4376c 100644
--- a/src/state/deps-exe/s6-linux-init-poweroff
+++ b/src/shutdown/deps-exe/s6-linux-init-poweroff
diff --git a/src/state/deps-exe/s6-linux-init-reboot b/src/shutdown/deps-exe/s6-linux-init-reboot
index 0c4376c..0c4376c 100644
--- a/src/state/deps-exe/s6-linux-init-reboot
+++ b/src/shutdown/deps-exe/s6-linux-init-reboot
diff --git a/src/state/deps-exe/s6-linux-init-shutdown b/src/shutdown/deps-exe/s6-linux-init-shutdown
index 0c4376c..0c4376c 100644
--- a/src/state/deps-exe/s6-linux-init-shutdown
+++ b/src/shutdown/deps-exe/s6-linux-init-shutdown
diff --git a/src/state/deps-exe/s6-linux-init-shutdownd b/src/shutdown/deps-exe/s6-linux-init-shutdownd
index 5a7d2fd..5a7d2fd 100644
--- a/src/state/deps-exe/s6-linux-init-shutdownd
+++ b/src/shutdown/deps-exe/s6-linux-init-shutdownd
diff --git a/src/shutdown/deps-lib/hpr b/src/shutdown/deps-lib/hpr
new file mode 100644
index 0000000..9e1493d
--- /dev/null
+++ b/src/shutdown/deps-lib/hpr
@@ -0,0 +1,2 @@
+hpr_shutdown.o
+hpr_wall.o
diff --git a/src/state/hpr.c b/src/shutdown/hpr.c
index 401cc97..a769c8c 100644
--- a/src/state/hpr.c
+++ b/src/shutdown/hpr.c
@@ -1,5 +1,7 @@
/* ISC license. */
+#include <skalibs/nonposix.h>
+
#include <unistd.h>
#include <signal.h>
#include <errno.h>
@@ -92,7 +94,7 @@ int main (int argc, char const *const *argv)
strerr_warnwu1sys("timeval_from_tain") ;
updwtmpx(_PATH_WTMP, &utx) ;
}
- if (dowall) hpr_wall_seconds(0) ;
+ if (dowall) hpr_wall(HPR_WALL_BANNER) ;
if (dowtmp < 2)
{
if (!hpr_shutdown(what, &STAMP, 0))
diff --git a/src/state/hpr.h b/src/shutdown/hpr.h
index 9deb6c4..993f5ab 100644
--- a/src/state/hpr.h
+++ b/src/shutdown/hpr.h
@@ -10,13 +10,11 @@
#include "initctl.h"
-#define HPR_WALL_BANNER "\n\n*** WARNING ***\nThe system is going down in "
+#define HPR_WALL_BANNER "\n\n*** WARNING ***\nThe system is going down NOW!\n"
#define hpr_send(s, n) openwritenclose_unsafe(INITCTL, (s), n)
#define hpr_cancel() hpr_send("c", 1)
extern int hpr_shutdown (unsigned int, tain_t const *, unsigned int) ;
-extern size_t hpr_fmttime (char *, size_t, unsigned int) ;
extern void hpr_wall (char const *) ;
-extern void hpr_wall_seconds (unsigned int) ;
#endif
diff --git a/src/state/hpr_shutdown.c b/src/shutdown/hpr_shutdown.c
index 9c9ff51..9c9ff51 100644
--- a/src/state/hpr_shutdown.c
+++ b/src/shutdown/hpr_shutdown.c
diff --git a/src/state/hpr_wall.c b/src/shutdown/hpr_wall.c
index cc6da5e..cc6da5e 100644
--- a/src/state/hpr_wall.c
+++ b/src/shutdown/hpr_wall.c
diff --git a/src/state/s6-linux-init-halt.c b/src/shutdown/s6-linux-init-halt.c
index 4ccca1d..4ccca1d 100644
--- a/src/state/s6-linux-init-halt.c
+++ b/src/shutdown/s6-linux-init-halt.c
diff --git a/src/state/s6-linux-init-poweroff.c b/src/shutdown/s6-linux-init-poweroff.c
index d25dbb6..d25dbb6 100644
--- a/src/state/s6-linux-init-poweroff.c
+++ b/src/shutdown/s6-linux-init-poweroff.c
diff --git a/src/state/s6-linux-init-reboot.c b/src/shutdown/s6-linux-init-reboot.c
index 3612684..3612684 100644
--- a/src/state/s6-linux-init-reboot.c
+++ b/src/shutdown/s6-linux-init-reboot.c
diff --git a/src/state/s6-linux-init-shutdown.c b/src/shutdown/s6-linux-init-shutdown.c
index bb0391d..f534944 100644
--- a/src/state/s6-linux-init-shutdown.c
+++ b/src/shutdown/s6-linux-init-shutdown.c
@@ -211,7 +211,7 @@ int main (int argc, char const *const *argv)
int doactl = 0 ;
int docancel = 0 ;
tain_t when ;
- PROG = "shutdown" ;
+ PROG = "s6-linux-init-shutdown" ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
diff --git a/src/state/s6-linux-init-shutdownd.c b/src/shutdown/s6-linux-init-shutdownd.c
index e330ac6..c6d6316 100644
--- a/src/state/s6-linux-init-shutdownd.c
+++ b/src/shutdown/s6-linux-init-shutdownd.c
@@ -17,20 +17,21 @@
#include <skalibs/buffer.h>
#include <skalibs/strerr2.h>
#include <skalibs/sgetopt.h>
-#include <skalibs/stralloc.h>
#include <skalibs/sig.h>
#include <skalibs/tai.h>
#include <skalibs/djbunix.h>
#include <skalibs/iopause.h>
#include <skalibs/skamisc.h>
+#include <execline/config.h>
+
#include "defaults.h"
#include "initctl.h"
#include "hpr.h"
#define STAGE4_FILE "stage 4"
-#define USAGE "s6-linux-init-shutdownd [ -b bindir ] [ -c basedir ] [ -g gracetime ]"
+#define USAGE "s6-linux-init-shutdownd [ -c basedir ] [ -g gracetime ]"
#define dieusage() strerr_dieusage(100, USAGE)
static char const *basedir = BASEDIR ;
@@ -77,58 +78,48 @@ static inline void handle_stdin (unsigned int *what, tain_t *deadline, unsigned
}
}
-static inline void prepare_stage4 (char const *bindir, char const *basedir, unsigned int what)
+static inline void prepare_stage4 (char const *basedir, unsigned int what)
{
static char const *table[3] = { "halt", "poweroff", "reboot" } ;
- stralloc sa = STRALLOC_ZERO ;
buffer b ;
- char buf[512] ;
int fd ;
+ char buf[512] ;
unlink_void(STAGE4_FILE ".new") ;
fd = open_excl(STAGE4_FILE ".new") ;
if (fd == -1) strerr_diefu3sys(111, "open ", STAGE4_FILE ".new", " for writing") ;
buffer_init(&b, &buffer_write, fd, buf, 512) ;
- if (buffer_puts(&b, "#!") == -1
- || buffer_puts(&b, bindir) == -1
- || buffer_puts(&b, "/execlineb -P\n\n") == -1)
- strerr_diefu2sys(111, "write to ", STAGE4_FILE ".new") ;
- if (!string_quote(&sa, basedir, strlen(basedir)))
- strerr_diefu1sys(111, "string_quote") ;
- if (buffer_put(&b, sa.s, sa.len) == -1
- || buffer_puts(&b, "/bin/" STAGE4 " ") == -1
- || buffer_puts(&b, table[what-1]) == -1
- || buffer_putsflush(&b, "\n") == -1)
+ if (buffer_puts(&b,
+ "#!" EXECLINE_SHEBANGPREFIX "/execlineb -P\n\n"
+ EXECLINE_EXTBINPREFIX "foreground { "
+ S6_LINUX_INIT_LIBEXECPREFIX "s6-linux-init-umountall }\n"
+ S6_LINUX_INIT_LIBEXECPREFIX "s6-linux-init-") < 0
+ || buffer_puts(&b, table[what-1]) < 0
+ || buffer_putsflush(&b, " -f\n") < 0)
strerr_diefu2sys(111, "write to ", STAGE4_FILE ".new") ;
- stralloc_free(&sa) ;
if (fchmod(fd, S_IRWXU) == -1)
strerr_diefu2sys(111, "fchmod ", STAGE4_FILE ".new") ;
- if (fsync(fd) == -1)
- strerr_diefu2sys(111, "fsync ", STAGE4_FILE ".new") ;
fd_close(fd) ;
if (rename(STAGE4_FILE ".new", STAGE4_FILE) == -1)
strerr_diefu4sys(111, "rename ", STAGE4_FILE ".new", " to ", STAGE4_FILE) ;
}
-int main (int argc, char const *const *argv)
+int main (int argc, char const *const *argv, char const *const *envp)
{
- char const *bindir = BINDIR ;
pid_t pid ;
tain_t deadline ;
unsigned int what = 0 ;
unsigned int grace_time = 3000 ;
- int notif = 0 ;
PROG = "s6-linux-init-shutdownd" ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "b:c:g:", &l) ;
+ int opt = subgetopt_r(argc, argv, "c:g:", &l) ;
if (opt == -1) break ;
switch (opt)
{
- case 'b' : bindir = l.arg ; break ;
case 'c' : basedir = l.arg ; break ;
case 'g' : if (!uint0_scan(l.arg, &grace_time)) dieusage() ; break ;
default : dieusage() ;
@@ -136,8 +127,6 @@ int main (int argc, char const *const *argv)
}
argc -= l.ind ; argv += l.ind ;
}
- if (bindir[0] != '/')
- strerr_dief2x(100, "bindir", " must be an absolute path") ;
if (basedir[0] != '/')
strerr_dief2x(100, "basedir", " must be an absolute path") ;
if (grace_time > 300000) grace_time = 300000 ;
@@ -145,7 +134,7 @@ int main (int argc, char const *const *argv)
/* if we're in stage 4, exec it immediately */
{
char const *stage4_argv[2] = { STAGE4_FILE, 0 } ;
- pathexec_run(stage4_argv[0], stage4_argv, (char const *const *)environ) ;
+ pathexec_run(stage4_argv[0], stage4_argv, envp) ;
if (errno != ENOENT)
strerr_warnwu2sys("exec ", stage4_argv[0]) ;
}
@@ -192,10 +181,7 @@ int main (int argc, char const *const *argv)
char const *stage3_argv[2] = { stage3, 0 } ;
memcpy(stage3, basedir, basedirlen) ;
memcpy(stage3 + basedirlen, "/" STAGE3, sizeof("/" STAGE3)) ;
- sig_block(SIGCHLD) ;
- pid = child_spawn0(stage3_argv[0], stage3_argv, (char const *const *)environ) ;
- if (!pid) strerr_warnwu2sys("spawn ", stage3) ;
- sig_unblock(SIGCHLD) ;
+ pid = child_spawn0(stage3_argv[0], stage3_argv, envp) ;
if (pid)
{
int wstat ;
@@ -219,12 +205,13 @@ int main (int argc, char const *const *argv)
strerr_warnw3x(stage3, " exited ", fmt) ;
}
}
+ else strerr_warnwu2sys("spawn ", stage3) ;
}
/* The end is coming! */
- prepare_stage4(bindir, basedir, what) ;
+ prepare_stage4(basedir, what) ;
if (fd_move(2, 1) == -1) strerr_warnwu1sys("fd_move") ;
sync() ;
if (sig_ignore(SIGTERM) == -1) strerr_warnwu1sys("sig_ignore SIGTERM") ;
diff --git a/src/state/deps-exe/s6-linux-init-telinit b/src/state/deps-exe/s6-linux-init-telinit
deleted file mode 100644
index aeb24a6..0000000
--- a/src/state/deps-exe/s6-linux-init-telinit
+++ /dev/null
@@ -1,2 +0,0 @@
-libhpr.a.xyzzy
--lskarnet
diff --git a/src/state/deps-lib/hpr b/src/state/deps-lib/hpr
deleted file mode 100644
index 066efd2..0000000
--- a/src/state/deps-lib/hpr
+++ /dev/null
@@ -1,4 +0,0 @@
-hpr_fmttime.o
-hpr_shutdown.o
-hpr_wall.o
-hpr_wall_seconds.o
diff --git a/src/state/hpr_fmttime.c b/src/state/hpr_fmttime.c
deleted file mode 100644
index 8038cfe..0000000
--- a/src/state/hpr_fmttime.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/* ISC license. */
-
-#include <string.h>
-
-#include <skalibs/types.h>
-
-#include "hpr.h"
-
-size_t hpr_fmttime (char *buf, size_t max, unsigned int seconds)
-{
- size_t m = 0 ;
- unsigned int minutes = 0 ;
- unsigned int hours = 0 ;
- if (seconds >= 60)
- {
- minutes = seconds / 60 ;
- seconds %= 60 ;
- if (minutes >= 60)
- {
- hours = minutes / 60 ;
- minutes %= 60 ;
- }
- }
- m = sizeof(HPR_WALL_BANNER) - 1 ;
- if (m > max) return 0 ;
- memcpy(buf, HPR_WALL_BANNER, m) ;
- if (hours)
- {
- if (m + UINT_FMT + 6 > max) return 0 ;
- m += uint_fmt(buf + m, hours) ;
- memcpy(buf + m, " hour", 5) ;
- m += 5 ;
- if (hours > 1) buf[m++] = 's' ;
- buf[m++] = ' ' ;
- }
- if (minutes)
- {
- if (m + UINT_FMT + 8 > max) return 0 ;
- m += uint_fmt(buf + m, minutes) ;
- memcpy(buf + m, " minute", 7) ;
- m += 7 ;
- if (minutes > 1) buf[m++] = 's' ;
- buf[m++] = ' ' ;
- }
- if (m + UINT_FMT + 8 > max) return 0 ;
- m += uint_fmt(buf + m, seconds) ;
- memcpy(buf + m, " second", 7) ;
- m += 7 ;
- if (seconds != 1) buf[m++] = 's' ;
- buf[m++] = ' ' ;
- return m ;
-}
diff --git a/src/state/hpr_wall_seconds.c b/src/state/hpr_wall_seconds.c
deleted file mode 100644
index 6c0363b..0000000
--- a/src/state/hpr_wall_seconds.c
+++ /dev/null
@@ -1,12 +0,0 @@
-/* ISC license. */
-
-#include "hpr.h"
-
-void hpr_wall_seconds (unsigned int secs)
-{
- char buf[300] = HPR_WALL_BANNER ;
- size_t n = sizeof(HPR_WALL_BANNER) - 1 ;
- n += hpr_fmttime(buf + n, 300 - n, secs) ;
- buf[n++] = 0 ;
- hpr_wall(buf) ;
-}
diff --git a/src/state/s6-linux-init-single.c b/src/state/s6-linux-init-single.c
deleted file mode 100644
index 4f23340..0000000
--- a/src/state/s6-linux-init-single.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/* ISC license. */
-
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include <skalibs/allreadwrite.h>
-#include <skalibs/strerr2.h>
-#include <skalibs/djbunix.h>
-
-#include "initctl.h"
-
-#define USAGE "s6-linux-init-single"
-#define dieusage() strerr_dieusage(100, USAGE)
-
-#define BANNER "Executing interactive root shell.\n"
-
-int main (void)
-{
- int fd ;
- PROG = "s6-linux-init-single" ;
- fd = open(EARLYGETTY, O_RDONLY) ;
- if (fd == -1)
- {
- if (errno != ENOENT)
- strerr_diefu2sys(111, "opendir ", EARLYGETTY) ;
- goto shell ;
- }
- if (faccessat(fd, "down", F_OK, 0) == 0)
- {
- fd_close(fd) ;
- goto shell ;
- }
- if (errno != ENOENT)
- strerr_diefu3sys(111, "access ", EARLYGETTY, "/down") ;
- return 0 ;
-
- shell:
-
- fd = open("/dev/console", O_RDONLY) ;
- if (fd == -1) strerr_diefu2sys(111, "open /dev/console for ", "reading") ;
- if (fd_move(0, fd) == -1) strerr_diefu1sys(111, "move /dev/console fd to 0") ;
- fd = open("/dev/console", O_WRONLY) ;
- if (fd == -1) strerr_diefu2sys(111, "open /dev/console for ", "writing") ;
- if (fd_move(1, fd) == -1) strerr_diefu1sys(111, "move /dev/console fd to 1") ;
- if (fd_copy(2, 1) == -1) strerr_diefu1sys(111, "dup2 1 to 2") ;
- if (allwrite(1, BANNER, sizeof(BANNER) - 1) < sizeof(BANNER) - 1)
- strerr_diefu1sys(111, "write banner") ;
- {
- char *argv[3] = { "/bin/sh", "-i", 0 } ;
- execv(argv[0], argv) ;
- strerr_dieexec(111, argv[0]) ;
- }
-}
diff --git a/src/state/s6-linux-init-telinit.c b/src/state/s6-linux-init-telinit.c
deleted file mode 100644
index 856e78b..0000000
--- a/src/state/s6-linux-init-telinit.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* ISC license. */
-
-#include <skalibs/sgetopt.h>
-#include <skalibs/types.h>
-#include <skalibs/strerr2.h>
-
-#include "defaults.h"
-#include "initctl.h"
-#include "hpr.h"
-
-#define USAGE "s6-linux-init-telinit runlevel"
-#define dieusage() strerr_dieusage(100, USAGE)
-
-int main (int argc, char const *const *argv, char const *const *envp)
-{
- PROG = "s6-linux-init-telinit" ;
- {
- subgetopt_t l = SUBGETOPT_ZERO ;
- for (;;)
- {
- int opt = subgetopt_r(argc, argv, "rc:p:s:m:d:", &l) ;
- if (opt == -1) break ;
- switch (opt)
- {
- case 'r' :
- case 'c' :
- case 'p' :
- case 's' :
- case 'm' :
- case 'd' : break ;
- default : dieusage() ;
- }
- }
- argc -= l.ind ; argv += l.ind ;
- }
-
- if (!argc) dieusage() ;
- if (!argv[0][0] || argv[0][1]) dieusage() ;
- if (argv[0][0] != 'S' && (argv[0][0] < '0' || argv[0][0] > '6')) dieusage() ;
- if (!hpr_send(argv[0], 1)) strerr_diefu2sys(111, "write to ", INITCTL) ;
- return 0 ;
-}