summaryrefslogtreecommitdiff
path: root/src/supervision/s6-svscan.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-09-09 04:35:20 +0000
committerLaurent Bercot <ska@appnovation.com>2023-09-09 04:35:20 +0000
commit1f592173a28907dadfb75132e1eb25dfe4fb3a94 (patch)
tree1759ad59cf444b3c151aa2af185a96b1891ae477 /src/supervision/s6-svscan.c
parent8f0980665c368c06adb46a1fddb6790e945c7c51 (diff)
downloads6-1f592173a28907dadfb75132e1eb25dfe4fb3a94.tar.xz
Adapt to skalibs-2.14
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/supervision/s6-svscan.c')
-rw-r--r--src/supervision/s6-svscan.c54
1 files changed, 29 insertions, 25 deletions
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) ;