diff options
Diffstat (limited to 'src/supervision')
-rw-r--r-- | src/supervision/s6-notifyoncheck.c | 3 | ||||
-rw-r--r-- | src/supervision/s6-svlisten.c | 4 | ||||
-rw-r--r-- | src/supervision/s6-svlisten1.c | 4 | ||||
-rw-r--r-- | src/supervision/s6-svscan.c | 54 |
4 files changed, 35 insertions, 30 deletions
diff --git a/src/supervision/s6-notifyoncheck.c b/src/supervision/s6-notifyoncheck.c index 592502c..8c139af 100644 --- a/src/supervision/s6-notifyoncheck.c +++ b/src/supervision/s6-notifyoncheck.c @@ -13,6 +13,7 @@ #include <skalibs/sgetopt.h> #include <skalibs/strerr.h> #include <skalibs/tai.h> +#include <skalibs/cspawn.h> #include <skalibs/djbunix.h> #include <skalibs/selfpipe.h> #include <skalibs/iopause.h> @@ -230,7 +231,7 @@ int main (int argc, char const *const *argv, char const *const *envp) if (handle_event(&a, id, 0)) return 2 ; } - pid = child_spawn0(childargv[0], childargv, envp) ; + pid = cspawn(childargv[0], childargv, envp, CSPAWN_FLAGS_SELFPIPE_FINISH, 0, 0) ; if (!pid) { strerr_warnwu2sys("spawn ", childargv[0]) ; diff --git a/src/supervision/s6-svlisten.c b/src/supervision/s6-svlisten.c index 2ab1d9b..0774ef2 100644 --- a/src/supervision/s6-svlisten.c +++ b/src/supervision/s6-svlisten.c @@ -7,7 +7,7 @@ #include <skalibs/bitarray.h> #include <skalibs/tai.h> #include <skalibs/strerr.h> -#include <skalibs/djbunix.h> +#include <skalibs/cspawn.h> #include <skalibs/selfpipe.h> #include <skalibs/exec.h> @@ -71,7 +71,7 @@ int main (int argc, char const **argv, char const *const *envp) unsigned char upstate[bitarray_div8(argc1)] ; unsigned char readystate[bitarray_div8(argc1)] ; s6_svlisten_init(argc1, argv, &foo, ids, upstate, readystate, &deadline) ; - pid = child_spawn0(argv[argc1 + 1], argv + argc1 + 1, envp) ; + pid = cspawn(argv[argc1 + 1], argv + argc1 + 1, envp, CSPAWN_FLAGS_SELFPIPE_FINISH, 0, 0) ; if (!pid) strerr_diefu2sys(111, "spawn ", argv[argc1 + 1]) ; if (wantup == 2) { diff --git a/src/supervision/s6-svlisten1.c b/src/supervision/s6-svlisten1.c index ab4f44c..4289e8c 100644 --- a/src/supervision/s6-svlisten1.c +++ b/src/supervision/s6-svlisten1.c @@ -6,7 +6,7 @@ #include <skalibs/types.h> #include <skalibs/tai.h> #include <skalibs/strerr.h> -#include <skalibs/djbunix.h> +#include <skalibs/cspawn.h> #include <skalibs/selfpipe.h> #include "s6-svlisten.h" @@ -50,7 +50,7 @@ int main (int argc, char const *const *argv, char const *const *envp) tain_add_g(&deadline, &tto) ; s6_svlisten_selfpipe_init() ; s6_svlisten_init(1, argv, &foo, &id, &upstate, &readystate, &deadline) ; - pid = child_spawn0(argv[1], argv + 1, envp) ; + pid = cspawn(argv[1], argv + 1, envp, CSPAWN_FLAGS_SELFPIPE_FINISH, 0, 0) ; if (!pid) strerr_diefu2sys(111, "spawn ", argv[1]) ; if (wantrestart) if (s6_svlisten_loop(&foo, 0, 1, 1, &deadline, selfpipe_fd(), &s6_svlisten_signal_handler)) diff --git a/src/supervision/s6-svscan.c b/src/supervision/s6-svscan.c index b2edc93..92f4d7a 100644 --- a/src/supervision/s6-svscan.c +++ b/src/supervision/s6-svscan.c @@ -17,6 +17,7 @@ #include <skalibs/tai.h> #include <skalibs/iopause.h> #include <skalibs/devino.h> +#include <skalibs/cspawn.h> #include <skalibs/djbunix.h> #include <skalibs/direntry.h> #include <skalibs/sig.h> @@ -242,7 +243,8 @@ static void handle_signals (unsigned int *what) memcpy(fn + SIGNAL_PROG_LEN, name, len + 1) ; if (access(newargv[0], X_OK) == 0) /* avoids a fork, don't care about the toctou */ { - if (child_spawn0(newargv[0], newargv, (char const **)environ)) usebuiltin = 0 ; + if (cspawn(newargv[0], newargv, (char const **)environ, CSPAWN_FLAGS_SELFPIPE_FINISH, 0, 0)) + usebuiltin = 0 ; else if (errno != ENOENT) strerr_warnwu2sys("spawn ", newargv[0]) ; } if (usebuiltin) switch (sig) @@ -530,34 +532,36 @@ static int start_iter (void *data, void *aux) { service *sv = data ; uint32_t i = sv - SERVICE(0) ; + char const *const cargv[3] = { "s6-supervise", NAME(i), 0 } ; + cspawn_fileaction fa[2] = + { + [0] = { .type = CSPAWN_FA_MOVE }, + [1] = { .type = CSPAWN_FA_MOVE } + } ; + size_t j = 0 ; + if (!bitarray_peek(active, i) || sv->pid || tain_future(&sv->start)) return 1 ; - sv->pid = fork() ; - switch (sv->pid) + if (sv->peer < max) { - case -1 : - sv->pid = 0 ; - strerr_warnwu2sys("fork", NAME(i)) ; - tain_addsec_g(&start_deadline, 10) ; - return 0 ; - case 0 : - { - char const *cargv[3] = { "s6-supervise", NAME(i), 0 } ; - PROG = "s6-svscan (child)" ; - if (sv->peer < max) - { - if (fd_move(!is_logger(i), sv->p) == -1) - strerr_diefu2sys(111, "dup2 pipe for ", NAME(i)) ; - } - if (consoleholder && i == special) - { - if (fd_move(2, consoleholder) == -1) - strerr_diefu2sys(111, "restore console fd for service ", NAME(i)) ; - } - selfpipe_finish() ; - xexec_a(S6_BINPREFIX "s6-supervise", cargv) ; - } + fa[j].x.fd2[0] = !is_logger(i) ; + fa[j].x.fd2[1] = sv->p ; + j++ ; + } + if (consoleholder && i == special) + { + fa[j].x.fd2[0] = 2 ; + fa[j].x.fd2[1] = consoleholder ; + j++ ; + } + + sv->pid = cspawn(S6_BINPREFIX "s6-supervise", cargv, (char const *const *)environ, CSPAWN_FLAGS_SELFPIPE_FINISH, fa, j) ; + if (!sv->pid) + { + strerr_warnwu2sys("spawn s6-supervise for ", NAME(i)) ; + tain_addsec_g(&start_deadline, 10) ; + return 0 ; } avltreen_insert(by_pid, i) ; tain_addsec_g(&sv->start, 1) ; |