From 97ed22b1bb075cb539e78fae2169ec56d3e8557b Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Tue, 23 Dec 2025 09:43:56 +0000 Subject: Split live into live and system --- package/deps.mak | 9 +- src/s6-frontend/deps-exe/s6-frontend | 7 +- src/s6-frontend/live.c | 4 - src/s6-frontend/live_boot.c | 143 -------------------------------- src/s6-frontend/live_hpr.c | 62 -------------- src/s6-frontend/live_start_everything.c | 81 ++++++++++++++++++ src/s6-frontend/s6-frontend-internal.h | 25 ++++-- src/s6-frontend/s6-frontend.c | 1 + src/s6-frontend/system.c | 33 ++++++++ src/s6-frontend/system_boot.c | 95 +++++++++++++++++++++ src/s6-frontend/system_help.c | 18 ++++ src/s6-frontend/system_hpr.c | 62 ++++++++++++++ 12 files changed, 318 insertions(+), 222 deletions(-) delete mode 100644 src/s6-frontend/live_boot.c delete mode 100644 src/s6-frontend/live_hpr.c create mode 100644 src/s6-frontend/live_start_everything.c create mode 100644 src/s6-frontend/system.c create mode 100644 src/s6-frontend/system_boot.c create mode 100644 src/s6-frontend/system_help.c create mode 100644 src/s6-frontend/system_hpr.c diff --git a/package/deps.mak b/package/deps.mak index 2b5bbdb..e5affd7 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -11,10 +11,9 @@ src/libs6f/s6f_report_state_change.o src/libs6f/s6f_report_state_change.lo: src/ src/libs6f/s6f_user_get_confdirs.o src/libs6f/s6f_user_get_confdirs.lo: src/libs6f/s6f_user_get_confdirs.c src/include-local/s6f.h src/s6-frontend/help.o src/s6-frontend/help.lo: src/s6-frontend/help.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h src/s6-frontend/live.o src/s6-frontend/live.lo: src/s6-frontend/live.c src/s6-frontend/s6-frontend-internal.h -src/s6-frontend/live_boot.o src/s6-frontend/live_boot.lo: src/s6-frontend/live_boot.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h src/s6-frontend/live_help.o src/s6-frontend/live_help.lo: src/s6-frontend/live_help.c src/s6-frontend/s6-frontend-internal.h -src/s6-frontend/live_hpr.o src/s6-frontend/live_hpr.lo: src/s6-frontend/live_hpr.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h src/s6-frontend/live_install.o src/s6-frontend/live_install.lo: src/s6-frontend/live_install.c src/s6-frontend/s6-frontend-internal.h +src/s6-frontend/live_start_everything.o src/s6-frontend/live_start_everything.lo: src/s6-frontend/live_start_everything.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h src/s6-frontend/live_startstop.o src/s6-frontend/live_startstop.lo: src/s6-frontend/live_startstop.c src/s6-frontend/s6-frontend-internal.h src/s6-frontend/live_status.o src/s6-frontend/live_status.lo: src/s6-frontend/live_status.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h src/s6-frontend/live_stop_everything.o src/s6-frontend/live_stop_everything.lo: src/s6-frontend/live_stop_everything.c src/s6-frontend/s6-frontend-internal.h @@ -39,6 +38,10 @@ src/s6-frontend/set_copy.o src/s6-frontend/set_copy.lo: src/s6-frontend/set_copy src/s6-frontend/set_help.o src/s6-frontend/set_help.lo: src/s6-frontend/set_help.c src/s6-frontend/s6-frontend-internal.h src/s6-frontend/set_list.o src/s6-frontend/set_list.lo: src/s6-frontend/set_list.c src/s6-frontend/s6-frontend-internal.h src/s6-frontend/set_status.o src/s6-frontend/set_status.lo: src/s6-frontend/set_status.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h +src/s6-frontend/system.o src/s6-frontend/system.lo: src/s6-frontend/system.c src/s6-frontend/s6-frontend-internal.h +src/s6-frontend/system_boot.o src/s6-frontend/system_boot.lo: src/s6-frontend/system_boot.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h +src/s6-frontend/system_help.o src/s6-frontend/system_help.lo: src/s6-frontend/system_help.c src/s6-frontend/s6-frontend-internal.h +src/s6-frontend/system_hpr.o src/s6-frontend/system_hpr.lo: src/s6-frontend/system_hpr.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h s6-frontend-helper-kill: EXTRA_LIBS := s6-frontend-helper-kill: src/helpers/s6-frontend-helper-kill.o -lskarnet @@ -50,5 +53,5 @@ endif s6: EXTRA_LIBS := s6: src/s6-frontend/s6.o -lskarnet s6-frontend: EXTRA_LIBS := ${MAYBEPTHREAD_LIB} -s6-frontend: src/s6-frontend/s6-frontend.o src/s6-frontend/help.o src/s6-frontend/live.o src/s6-frontend/live_boot.o src/s6-frontend/live_help.o src/s6-frontend/live_hpr.o src/s6-frontend/live_install.o src/s6-frontend/live_startstop.o src/s6-frontend/live_status.o src/s6-frontend/live_stop_everything.o src/s6-frontend/process.o src/s6-frontend/process_help.o src/s6-frontend/process_kill.o src/s6-frontend/process_restart.o src/s6-frontend/process_startstop.o src/s6-frontend/process_status.o src/s6-frontend/repository.o src/s6-frontend/repository_help.o src/s6-frontend/repository_init.o src/s6-frontend/repository_list.o src/s6-frontend/repository_sync.o src/s6-frontend/set.o src/s6-frontend/set_change.o src/s6-frontend/set_check.o src/s6-frontend/set_commit.o src/s6-frontend/set_copy.o src/s6-frontend/set_help.o src/s6-frontend/set_list.o src/s6-frontend/set_status.o libs6f.a.xyzzy ${LIBNSSS} -ls6rc -ls6 -lskarnet +s6-frontend: src/s6-frontend/s6-frontend.o src/s6-frontend/help.o src/s6-frontend/live.o src/s6-frontend/live_help.o src/s6-frontend/live_install.o src/s6-frontend/live_startstop.o src/s6-frontend/live_status.o src/s6-frontend/live_start_everything.o src/s6-frontend/live_stop_everything.o src/s6-frontend/process.o src/s6-frontend/process_help.o src/s6-frontend/process_kill.o src/s6-frontend/process_restart.o src/s6-frontend/process_startstop.o src/s6-frontend/process_status.o src/s6-frontend/repository.o src/s6-frontend/repository_help.o src/s6-frontend/repository_init.o src/s6-frontend/repository_list.o src/s6-frontend/repository_sync.o src/s6-frontend/set.o src/s6-frontend/set_change.o src/s6-frontend/set_check.o src/s6-frontend/set_commit.o src/s6-frontend/set_copy.o src/s6-frontend/set_help.o src/s6-frontend/set_list.o src/s6-frontend/set_status.o src/s6-frontend/system.o src/s6-frontend/system_boot.o src/s6-frontend/system_help.o src/s6-frontend/system_hpr.o libs6f.a.xyzzy ${LIBNSSS} -ls6rc -ls6 -lskarnet INTERNAL_LIBS := libs6f.a.xyzzy diff --git a/src/s6-frontend/deps-exe/s6-frontend b/src/s6-frontend/deps-exe/s6-frontend index d322eb7..2e7af62 100644 --- a/src/s6-frontend/deps-exe/s6-frontend +++ b/src/s6-frontend/deps-exe/s6-frontend @@ -1,11 +1,10 @@ help.o live.o -live_boot.o live_help.o -live_hpr.o live_install.o live_startstop.o live_status.o +live_start_everything.o live_stop_everything.o process.o process_help.o @@ -26,6 +25,10 @@ set_copy.o set_help.o set_list.o set_status.o +system.o +system_boot.o +system_help.o +system_hpr.o libs6f.a.xyzzy ${LIBNSSS} -ls6rc diff --git a/src/s6-frontend/live.c b/src/s6-frontend/live.c index cd1f70a..13571b1 100644 --- a/src/s6-frontend/live.c +++ b/src/s6-frontend/live.c @@ -15,12 +15,8 @@ void live (char const *const *argv) { static struct command_s const commands[] = { - { .s = "boot", .f = &live_boot }, - { .s = "halt", .f = &live_halt }, { .s = "help", .f = &live_help }, { .s = "install", .f = &live_install }, - { .s = "poweroff", .f = &live_poweroff }, - { .s = "reboot", .f = &live_reboot }, { .s = "restart", .f = &live_restart }, { .s = "start", .f = &live_start }, { .s = "start-everything", .f = &live_start_everything }, diff --git a/src/s6-frontend/live_boot.c b/src/s6-frontend/live_boot.c deleted file mode 100644 index 00c90a3..0000000 --- a/src/s6-frontend/live_boot.c +++ /dev/null @@ -1,143 +0,0 @@ -/* ISC license. */ - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include "s6-frontend-internal.h" - -enum golb_e -{ - GOLB_DRYRUN = 0x01, -} ; - -enum gola_e -{ - GOLA_PREFIX, - GOLA_TIMEOUT, - GOLA_DEFBUNDLE, - GOLA_N -} ; - -static gol_bool const rgolb[] = -{ - { .so = 'n', .lo = "dry-run", .clear = 0, .set = GOLB_DRYRUN }, -} ; -static gol_arg const rgola[] = -{ - { .so = 'p', .lo = "prefix", .i = GOLA_PREFIX }, - { .so = 't', .lo = "timeout", .i = GOLA_TIMEOUT }, - { .so = 'D', .lo = "default-bundle", .i = GOLA_DEFBUNDLE }, -} ; - -static void live_init_fill (char const **argv, char const *prefix) -{ - unsigned int m = 0 ; - argv[m++] = S6RC_EXTBINPREFIX "s6-rc-init" ; - if (prefix) - { - argv[m++] = "-p" ; - argv[m++] = prefix ; - } - argv[m++] = "-l" ; - argv[m++] = g->dirs.live ; - argv[m++] = "-c" ; - argv[m++] = g->dirs.boot ; - argv[m++] = "-b" ; - argv[m++] = "--" ; - argv[m++] = g->dirs.scan ; - argv[m++] = 0 ; -} - -void live_init (char const *const *argv) -{ - char const *wgola[GOLA_N] = { 0 } ; - char const *newargv[13] ; - argv += gol_argv(argv, 0, 0, rgola, 1, 0, wgola) ; - live_init_fill(newargv, wgola[GOLA_PREFIX]) ; - xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ; -} - -static void live_init_spawn (char const *prefix) -{ - pid_t pid ; - int wstat ; - char const *newargv[13] ; - live_init_fill(newargv, prefix) ; - pid = xmspawn_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n, 0, 0, 0) ; - if (wait_pid(pid, &wstat) == -1) - strerr_diefu2sys(111, "wait for ", newargv[0]) ; - if (wait_estatus(wstat)) - strerr_dief2x(wait_estatus(wstat), newargv[0], " failed") ; -} - -static void exec_live_start_everything (unsigned int timeout, int dryrun, char const *defbundle) gccattr_noreturn ; -static void exec_live_start_everything (unsigned int timeout, int dryrun, char const *defbundle) -{ - unsigned int m = 0 ; - char const *argv[13] ; - char fmtv[UINT_FMT] ; - char fmtt[UINT_FMT] ; - - argv[m++] = S6RC_EXTBINPREFIX "s6-rc" ; - if (g->verbosity != 1) - { - fmtv[uint_fmt(fmtv, g->verbosity)] = 0 ; - argv[m++] = "-v" ; - argv[m++] = fmtv ; - } - if (timeout) - { - fmtt[uint_fmt(fmtt, timeout)] = 0 ; - argv[m++] = "-t" ; - argv[m++] = fmtt ; - } - if (dryrun) argv[m++] = "-n1" ; - argv[m++] = "-l" ; - argv[m++] = g->dirs.live ; - argv[m++] = "-b" ; - argv[m++] = "--" ; - argv[m++] = "start" ; - argv[m++] = defbundle ; - argv[m++] = 0 ; - xmexec_n(argv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ; -} - -void live_start_everything (char const *const *argv) -{ - uint64_t wgolb = 0 ; - char const *wgola[GOLA_N] = { 0 } ; - unsigned int timeout = 0 ; - - wgola[GOLA_DEFBUNDLE] = S6_FRONTEND_DEFBUNDLE ; - argv += gol_argv(argv, rgolb, 1, rgola + 1, 2, &wgolb, wgola) ; - if (wgola[GOLA_TIMEOUT]) - { - if (!uint0_scan(wgola[GOLA_TIMEOUT], &timeout)) - strerr_dief1x(100, "timeout must be an integer (milliseconds)") ; - } - exec_live_start_everything(timeout, !!(wgolb & GOLB_DRYRUN), wgola[GOLA_DEFBUNDLE]) ; -} - -void live_boot (char const *const *argv) -{ - uint64_t wgolb = 0 ; - char const *wgola[GOLA_N] = { 0 } ; - unsigned int timeout = 0 ; - - wgola[GOLA_DEFBUNDLE] = S6_FRONTEND_DEFBUNDLE ; - argv += GOL_argv(argv, rgolb, rgola, &wgolb, wgola) ; - if (wgola[GOLA_TIMEOUT]) - { - if (!uint0_scan(wgola[GOLA_TIMEOUT], &timeout)) - strerr_dief1x(100, "--timeout= argument must be an unsigned integer (in milliseconds)") ; - } - live_init_spawn(wgola[GOLA_PREFIX]) ; - exec_live_start_everything(timeout, !!(wgolb & GOLB_DRYRUN), wgola[GOLA_DEFBUNDLE]) ; -} diff --git a/src/s6-frontend/live_hpr.c b/src/s6-frontend/live_hpr.c deleted file mode 100644 index 54f50fc..0000000 --- a/src/s6-frontend/live_hpr.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ISC license. */ - -#include -#include "s6-frontend-internal.h" - -#ifdef S6_FRONTEND_USE_S6LI - -#include - -static void live_hpr (char const *arg) gccattr_noreturn ; -static void live_hpr (char const *arg) -{ - unsigned int m = 0 ; - char const *argv[4] ; - argv[m++] = S6_LINUX_INIT_EXTBINPREFIX "s6-linux-init-hpr" ; - argv[m++] = arg ; - argv[m++] = "--" ; - argv[m++] = 0 ; - xmexec_n(argv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ; -} - -void live_halt (char const *const *argv) -{ - live_hpr("-h") ; -} - -void live_poweroff (char const *const *argv) -{ - live_hpr("-p") ; -} - -void live_reboot (char const *const *argv) -{ - live_hpr("-r") ; -} - -#else - -#include - -static void live_hpr (char const *arg) gccattr_noreturn ; -static void live_hpr (char const *const *arg) -{ - strerr_dief3x(100, "s6 live ", arg, " needs s6-frontend to be built with s6-linux-init support") ; -} - -void live_halt (char const *const *argv) -{ - live_hpr("halt") ; -} - -void live_poweroff (char const *const *argv) -{ - live_hpr("poweroff") ; -} - -void live_reboot (char const *const *argv) -{ - live_hpr("reboot") ; -} - -#endif diff --git a/src/s6-frontend/live_start_everything.c b/src/s6-frontend/live_start_everything.c new file mode 100644 index 0000000..3c5e45b --- /dev/null +++ b/src/s6-frontend/live_start_everything.c @@ -0,0 +1,81 @@ +/* ISC license. */ + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include "s6-frontend-internal.h" + +enum golb_e +{ + GOLB_DRYRUN = 0x01, +} ; + +enum gola_e +{ + GOLA_TIMEOUT, + GOLA_DEFBUNDLE, + GOLA_N +} ; + +void exec_live_start_everything (unsigned int timeout, int dryrun, char const *defbundle) +{ + unsigned int m = 0 ; + char const *argv[13] ; + char fmtv[UINT_FMT] ; + char fmtt[UINT_FMT] ; + + argv[m++] = S6RC_EXTBINPREFIX "s6-rc" ; + if (g->verbosity != 1) + { + fmtv[uint_fmt(fmtv, g->verbosity)] = 0 ; + argv[m++] = "-v" ; + argv[m++] = fmtv ; + } + if (timeout) + { + fmtt[uint_fmt(fmtt, timeout)] = 0 ; + argv[m++] = "-t" ; + argv[m++] = fmtt ; + } + if (dryrun) argv[m++] = "-n1" ; + argv[m++] = "-l" ; + argv[m++] = g->dirs.live ; + argv[m++] = "-b" ; + argv[m++] = "--" ; + argv[m++] = "start" ; + argv[m++] = defbundle ; + argv[m++] = 0 ; + xmexec_n(argv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ; +} + +void live_start_everything (char const *const *argv) +{ + static gol_bool const rgolb[] = + { + { .so = 'n', .lo = "dry-run", .clear = 0, .set = GOLB_DRYRUN }, + } ; + static gol_arg const rgola[] = + { + { .so = 't', .lo = "timeout", .i = GOLA_TIMEOUT }, + { .so = 'D', .lo = "default-bundle", .i = GOLA_DEFBUNDLE }, + } ; + uint64_t wgolb = 0 ; + char const *wgola[GOLA_N] = { 0 } ; + unsigned int timeout = 0 ; + + wgola[GOLA_DEFBUNDLE] = S6_FRONTEND_DEFBUNDLE ; + argv += GOL_argv(argv, rgolb, rgola, &wgolb, wgola) ; + if (wgola[GOLA_TIMEOUT]) + { + if (!uint0_scan(wgola[GOLA_TIMEOUT], &timeout)) + strerr_dief1x(100, "timeout must be an integer (milliseconds)") ; + } + exec_live_start_everything(timeout, !!(wgolb & GOLB_DRYRUN), wgola[GOLA_DEFBUNDLE]) ; +} diff --git a/src/s6-frontend/s6-frontend-internal.h b/src/s6-frontend/s6-frontend-internal.h index a535e9e..0004646 100644 --- a/src/s6-frontend/s6-frontend-internal.h +++ b/src/s6-frontend/s6-frontend-internal.h @@ -27,21 +27,17 @@ extern void version (char const *const *) gccattr_noreturn ; /* live */ +extern void exec_live_start_everything (unsigned int, int, char const *) gccattr_noreturn ; + extern void live (char const *const *) gccattr_noreturn ; extern void live_help (char const *const *) gccattr_noreturn ; -extern void live_boot (char const *const *) gccattr_noreturn ; -extern void live_init (char const *const *) gccattr_noreturn ; -extern void live_start_everything (char const *const *) gccattr_noreturn ; - -extern void live_halt (char const *const *) gccattr_noreturn ; -extern void live_poweroff (char const *const *) gccattr_noreturn ; -extern void live_reboot (char const *const *) gccattr_noreturn ; - extern void live_restart (char const *const *) gccattr_noreturn ; extern void live_start (char const *const *) gccattr_noreturn ; extern void live_status (char const *const *) gccattr_noreturn ; extern void live_stop (char const *const *) gccattr_noreturn ; + +extern void live_start_everything (char const *const *) gccattr_noreturn ; extern void live_stop_everything (char const *const *) gccattr_noreturn ; extern void live_install (char const *const *) gccattr_noreturn ; @@ -94,6 +90,19 @@ extern void set_check (char const *const *) gccattr_noreturn ; extern void set_commit (char const *const *) gccattr_noreturn ; + /* system */ + +extern void s6system (char const *const *) gccattr_noreturn ; +extern void system_help (char const *const *) gccattr_noreturn ; + +extern void system_boot (char const *const *) gccattr_noreturn ; +extern void system_init (char const *const *) gccattr_noreturn ; + +extern void system_halt (char const *const *) gccattr_noreturn ; +extern void system_poweroff (char const *const *) gccattr_noreturn ; +extern void system_reboot (char const *const *) gccattr_noreturn ; + + /* main */ struct global_s diff --git a/src/s6-frontend/s6-frontend.c b/src/s6-frontend/s6-frontend.c index 9f550f5..30e6ef2 100644 --- a/src/s6-frontend/s6-frontend.c +++ b/src/s6-frontend/s6-frontend.c @@ -72,6 +72,7 @@ int main (int argc, char const *const *argv) { .s = "process", .f = &process }, { .s = "repository", .f = &repository }, { .s = "set", .f = &set }, + { .s = "system", .f = &s6system }, { .s = "version", .f = &version }, } ; diff --git a/src/s6-frontend/system.c b/src/s6-frontend/system.c new file mode 100644 index 0000000..ea184b8 --- /dev/null +++ b/src/s6-frontend/system.c @@ -0,0 +1,33 @@ +/* ISC license. */ + +#include + +#include + +#include + +#include "s6-frontend-internal.h" + +#define USAGE "s6 system subcommand [ subcommand options ] [ services... ] Type \"s6 system help\" for details." +#define dieusage() strerr_dieusage(100, USAGE) + +void s6system (char const *const *argv) +{ + static struct command_s const commands[] = + { + { .s = "boot", .f = &system_boot }, + { .s = "halt", .f = &system_halt }, + { .s = "help", .f = &system_help }, + { .s = "poweroff", .f = &system_poweroff }, + { .s = "reboot", .f = &system_reboot }, + { .s = "shutdown", .f = &system_poweroff }, + } ; + struct command_s *cmd ; + + argv += gol_argv(argv, 0, 0, 0, 0, 0, 0) ; + if (!*argv) dieusage() ; + cmd = BSEARCH(struct command_s, *argv, commands) ; + if (!cmd) dieusage() ; + (*cmd->f)(++argv) ; + _exit(101) ; +} diff --git a/src/s6-frontend/system_boot.c b/src/s6-frontend/system_boot.c new file mode 100644 index 0000000..109605a --- /dev/null +++ b/src/s6-frontend/system_boot.c @@ -0,0 +1,95 @@ +/* ISC license. */ + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include "s6-frontend-internal.h" + +enum golb_e +{ + GOLB_DRYRUN = 0x01, +} ; + +enum gola_e +{ + GOLA_PREFIX, + GOLA_TIMEOUT, + GOLA_DEFBUNDLE, + GOLA_N +} ; + +static gol_bool const rgolb[] = +{ + { .so = 'n', .lo = "dry-run", .clear = 0, .set = GOLB_DRYRUN }, +} ; +static gol_arg const rgola[] = +{ + { .so = 'p', .lo = "prefix", .i = GOLA_PREFIX }, + { .so = 't', .lo = "timeout", .i = GOLA_TIMEOUT }, + { .so = 'D', .lo = "default-bundle", .i = GOLA_DEFBUNDLE }, +} ; + +static void system_init_fill (char const **argv, char const *prefix) +{ + unsigned int m = 0 ; + argv[m++] = S6RC_EXTBINPREFIX "s6-rc-init" ; + if (prefix) + { + argv[m++] = "-p" ; + argv[m++] = prefix ; + } + argv[m++] = "-l" ; + argv[m++] = g->dirs.live ; + argv[m++] = "-c" ; + argv[m++] = g->dirs.boot ; + argv[m++] = "-b" ; + argv[m++] = "--" ; + argv[m++] = g->dirs.scan ; + argv[m++] = 0 ; +} + +void system_init (char const *const *argv) +{ + char const *wgola[GOLA_N] = { 0 } ; + char const *newargv[13] ; + argv += gol_argv(argv, 0, 0, rgola, 1, 0, wgola) ; + system_init_fill(newargv, wgola[GOLA_PREFIX]) ; + xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ; +} + +static void system_init_spawn (char const *prefix) +{ + pid_t pid ; + int wstat ; + char const *newargv[13] ; + system_init_fill(newargv, prefix) ; + pid = xmspawn_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n, 0, 0, 0) ; + if (wait_pid(pid, &wstat) == -1) + strerr_diefu2sys(111, "wait for ", newargv[0]) ; + if (wait_estatus(wstat)) + strerr_dief2x(wait_estatus(wstat), newargv[0], " failed") ; +} + +void system_boot (char const *const *argv) +{ + uint64_t wgolb = 0 ; + char const *wgola[GOLA_N] = { 0 } ; + unsigned int timeout = 0 ; + + wgola[GOLA_DEFBUNDLE] = S6_FRONTEND_DEFBUNDLE ; + argv += GOL_argv(argv, rgolb, rgola, &wgolb, wgola) ; + if (wgola[GOLA_TIMEOUT]) + { + if (!uint0_scan(wgola[GOLA_TIMEOUT], &timeout)) + strerr_dief1x(100, "timeout must be an unsigned integer (in milliseconds)") ; + } + system_init_spawn(wgola[GOLA_PREFIX]) ; + exec_live_start_everything(timeout, !!(wgolb & GOLB_DRYRUN), wgola[GOLA_DEFBUNDLE]) ; +} diff --git a/src/s6-frontend/system_help.c b/src/s6-frontend/system_help.c new file mode 100644 index 0000000..0c50f42 --- /dev/null +++ b/src/s6-frontend/system_help.c @@ -0,0 +1,18 @@ +/* ISC license. */ + +#include + +#include +#include + +#include "s6-frontend-internal.h" + +#define SYSTEM_HELP_MESSAGE "This is the system help message.\n" + +void system_help (char const *const *argv) +{ + (void)argv ; + if (!buffer_putsflush(buffer_1, SYSTEM_HELP_MESSAGE)) + strerr_diefu1sys(111, "write to stdout") ; + _exit(0) ; +} diff --git a/src/s6-frontend/system_hpr.c b/src/s6-frontend/system_hpr.c new file mode 100644 index 0000000..5d50d28 --- /dev/null +++ b/src/s6-frontend/system_hpr.c @@ -0,0 +1,62 @@ +/* ISC license. */ + +#include +#include "s6-frontend-internal.h" + +#ifdef S6_FRONTEND_USE_S6LI + +#include + +static void system_hpr (char const *arg) gccattr_noreturn ; +static void system_hpr (char const *arg) +{ + unsigned int m = 0 ; + char const *argv[4] ; + argv[m++] = S6_LINUX_INIT_EXTBINPREFIX "s6-linux-init-hpr" ; + argv[m++] = arg ; + argv[m++] = "--" ; + argv[m++] = 0 ; + xmexec_n(argv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ; +} + +void system_halt (char const *const *argv) +{ + system_hpr("-h") ; +} + +void system_poweroff (char const *const *argv) +{ + system_hpr("-p") ; +} + +void system_reboot (char const *const *argv) +{ + system_hpr("-r") ; +} + +#else + +#include + +static void system_hpr (char const *arg) gccattr_noreturn ; +static void system_hpr (char const *const *arg) +{ + strerr_dief3x(100, "s6 system ", arg, " needs s6-frontend to be built with s6-linux-init support") ; +} + +void system_halt (char const *const *argv) +{ + system_hpr("halt") ; +} + +void system_poweroff (char const *const *argv) +{ + system_hpr("poweroff") ; +} + +void system_reboot (char const *const *argv) +{ + system_hpr("reboot") ; +} + +#endif -- cgit v1.3.1