diff options
Diffstat (limited to 'src/s6')
| -rw-r--r-- | src/s6/deps-exe/s6 | 1 | ||||
| -rw-r--r-- | src/s6/s6-internal.h | 1 | ||||
| -rw-r--r-- | src/s6/s6.c | 3 | ||||
| -rw-r--r-- | src/s6/service_start.c | 79 |
4 files changed, 78 insertions, 6 deletions
diff --git a/src/s6/deps-exe/s6 b/src/s6/deps-exe/s6 index e3cd3b7..1d03ef1 100644 --- a/src/s6/deps-exe/s6 +++ b/src/s6/deps-exe/s6 @@ -11,5 +11,6 @@ service_start.o service_status.o service_stop.o libs6f.a.xyzzy +-ls6rc -ls6 -lskarnet diff --git a/src/s6/s6-internal.h b/src/s6/s6-internal.h index 34a9c16..6ee3939 100644 --- a/src/s6/s6-internal.h +++ b/src/s6/s6-internal.h @@ -70,6 +70,7 @@ struct global_s .live = S6_FRONTEND_LIVEDIR, \ .repo = S6_FRONTEND_REPODIR, \ .boot = S6_FRONTEND_BOOTDIR, \ + .stmp = S6_FRONTEND_STMPDIR, \ }, \ .userstorage = STRALLOC_ZERO, \ .isuser = 0, \ diff --git a/src/s6/s6.c b/src/s6/s6.c index 8d5295c..2467f3c 100644 --- a/src/s6/s6.c +++ b/src/s6/s6.c @@ -42,6 +42,7 @@ enum main_gola_e MAIN_GOLA_LIVEDIR, MAIN_GOLA_REPODIR, MAIN_GOLA_BOOTDIR, + MAIN_GOLA_STMPDIR, MAIN_GOLA_VERBOSITY, MAIN_GOLA_COLOR, MAIN_GOLA_N @@ -60,6 +61,7 @@ static gol_arg const main_gola[MAIN_GOLA_N] = { .so = 'l', .lo = "livedir", .i = MAIN_GOLA_LIVEDIR }, { .so = 'r', .lo = "repodir", .i = MAIN_GOLA_REPODIR }, { .so = 'b', .lo = "bootdir", .i = MAIN_GOLA_BOOTDIR }, + { .so = 0, .lo = "stmpdir", .i = MAIN_GOLA_STMPDIR }, { .so = 'v', .lo = "verbosity", .i = MAIN_GOLA_VERBOSITY }, { .so = 0, .lo = "color", .i = MAIN_GOLA_COLOR } } ; @@ -98,6 +100,7 @@ int main (int argc, char const *const *argv, char const *const *envp) if (gola[MAIN_GOLA_LIVEDIR]) g->dirs.live = gola[MAIN_GOLA_LIVEDIR] ; if (gola[MAIN_GOLA_REPODIR]) g->dirs.repo = gola[MAIN_GOLA_REPODIR] ; if (gola[MAIN_GOLA_BOOTDIR]) g->dirs.boot = gola[MAIN_GOLA_BOOTDIR] ; + if (gola[MAIN_GOLA_STMPDIR]) g->dirs.stmp = gola[MAIN_GOLA_STMPDIR] ; { int force_color = 0 ; diff --git a/src/s6/service_start.c b/src/s6/service_start.c index 8e876ea..90a3087 100644 --- a/src/s6/service_start.c +++ b/src/s6/service_start.c @@ -1,11 +1,19 @@ /* ISC license. */ +#include <string.h> +#include <sys/wait.h> + +#include <skalibs/posixplz.h> #include <skalibs/uint64.h> +#include <skalibs/types.h> #include <skalibs/strerr.h> #include <skalibs/gol.h> #include <skalibs/env.h> +#include <skalibs/cspawn.h> +#include <skalibs/djbunix.h> #include <s6-rc/config.h> +#include <s6-rc/s6rc-utils.h> #include "s6-internal.h" @@ -19,6 +27,12 @@ enum service_start_golb_e SERVICE_START_GOLB_N } ; +enum service_start_gola_e +{ + SERVICE_START_GOLA_TIMEOUT, + SERVICE_START_GOLA_N +} ; + static gol_bool const service_start_golb[3] = { { .so = 'n', .lo = "dryrun", .set = 1, .mask = 1 << SERVICE_START_GOLB_DRYRUN }, @@ -26,30 +40,83 @@ static gol_bool const service_start_golb[3] = { .so = 'w', .lo = "wait", .set = 1, .mask = 1 << SERVICE_START_GOLB_WAIT } } ; +static gol_arg const service_start_gola[SERVICE_START_GOLA_N] = +{ + { .so = 't', .lo = "timeout", .i = SERVICE_START_GOLA_TIMEOUT } +} ; + int service_start (char const *const *argv) { - size_t argc = env_len(argv) ; + char const *gola[SERVICE_START_GOLA_N] = { 0 } ; uint64_t golb = 0 ; + unsigned int t = 0 ; + size_t argc = env_len(argv) ; + pid_t pid ; + int wstat ; + uint32_t nlong, nshort, n ; + int livelock, compiledlock ; + size_t livelen = strlen(g->dirs.live) ; PROG = "s6 service start" ; - argv += gol_argv(argv, service_start_golb, 0, 0, 0, &golb, 0) ; - if (!argv) dieusage() ; + argv += gol_argv(argv, service_start_golb, 3, service_start_gola, SERVICE_START_GOLA_N, &golb, gola) ; + if (!*argv) dieusage() ; + + if (gola[SERVICE_START_GOLA_TIMEOUT]) + { + if (!uint0_scan(gola[SERVICE_START_GOLA_TIMEOUT], &t)) + strerr_dief1x(100, "timeout must be an integer (milliseconds)") ; + } + s6f_lock(g->dirs.stmp, 0) ; /* leaks, it's fine */ + char dbfn[livelen + 10] ; + memcpy(dbfn, g->dirs.live, livelen) ; + memcpy(dbfn + livelen, "/compiled", 10) ; + if (!s6rc_lock(g->dirs.live, 2, &livelock, dbfn, 1, &compiledlock, 1)) + strerr_diefu2sys(111, "take lock in ", g->dirs.live) ; + if (!s6rc_live_state_size(g->dirs.live, &nlong, &nshort)) + strerr_diefu2sys(111, "read state size in ", g->dirs.live) ; + n = nlong + nshort ; + unsigned char oldstate[n] ; + if (!s6rc_live_state_read(g->dirs.live, oldstate, n)) + strerr_diefu2sys(111, "read state in ", g->dirs.live) ; { size_t m = 0 ; - char const *newargv[10 + argc] ; + char const *newargv[13 + argc] ; char fmtv[UINT_FMT] ; + char fmtt[UINT_FMT] ; - newargv[m++] = S6RC_EXTBINPREFIX "s6-rc" ; + newargv[m++] = S6RC_EXTBINPREFIX "s6-rc" ; + newargv[m++] = "-X" ; /* we already took the locks */ newargv[m++] = "-v" ; newargv[m++] = fmtv ; fmtv[uint_fmt(fmtv, g->verbosity)] = 0 ; + if (t) + { + newargv[m++] = "-t" ; + newargv[m++] = fmtt ; + fmtt[uint_fmt(fmtt, t)] = 0 ; + } if (golb & 1 << SERVICE_START_GOLB_DRYRUN) { newargv[m++] = "-n" ; newargv[m++] = "1" ; } + newargv[m++] = "-l" ; + newargv[m++] = g->dirs.live ; newargv[m++] = "--" ; + newargv[m++] = "start" ; + while (*argv) newargv[m++] = *argv++ ; + newargv[m++] = 0 ; + pid = cspawn(newargv[0], newargv, (char const *const *)environ, CSPAWN_FLAGS_SIGBLOCKNONE, 0, 0) ; + if (!pid) strerr_diefu2sys(111, "spawn ", newargv[0]) ; } - return 0 ; + if (wait_pid(pid, &wstat) <= 0) strerr_diefu1sys(111, "wait for s6-rc") ; + if ((WIFEXITED(wstat) && !WEXITSTATUS(wstat)) || !g->verbosity) + return wait_estatus(wstat) ; + + unsigned char newstate[n] ; + if (!s6rc_live_state_read(g->dirs.live, newstate, n)) + strerr_diefu2sys(111, "read state in ", g->dirs.live) ; + s6f_report_state_change(n, oldstate, newstate, dbfn) ; + return wait_estatus(wstat) ; } |
