s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

commit de03e80a55ec78c93a749f41dfc69e806e655b0e
parent bc3863eaf3e4ae92eac8cd3ce0ca9dcb8915fc36
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Mon, 11 Sep 2023 08:37:33 +0000

 Defork s6-sudod

Signed-off-by: Laurent Bercot <ska@appnovation.com>

Diffstat:
Mpackage/deps.mak | 4++--
Msrc/conn-tools/deps-exe/s6-ipcserverd | 1+
Msrc/conn-tools/deps-exe/s6-sudod | 1+
Msrc/conn-tools/s6-sudod.c | 47+++++++++++------------------------------------
4 files changed, 15 insertions(+), 38 deletions(-)

diff --git a/package/deps.mak b/package/deps.mak @@ -161,13 +161,13 @@ s6-ipcserver-access: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} s6-ipcserver-access: src/conn-tools/s6-ipcserver-access.o ${LIBS6} s6-ipcserver-socketbinder: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} s6-ipcserver-socketbinder: src/conn-tools/s6-ipcserver-socketbinder.o -s6-ipcserverd: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} +s6-ipcserverd: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SPAWN_LIB} s6-ipcserverd: src/conn-tools/s6-ipcserverd.o s6-sudo: EXTRA_LIBS := -lskarnet s6-sudo: src/conn-tools/s6-sudo.o s6-sudoc: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} s6-sudoc: src/conn-tools/s6-sudoc.o -s6-sudod: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} +s6-sudod: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SPAWN_LIB} ${SYSCLOCK_LIB} s6-sudod: src/conn-tools/s6-sudod.o s6-applyuidgid: EXTRA_LIBS := -lskarnet s6-applyuidgid: src/daemontools-extras/s6-applyuidgid.o diff --git a/src/conn-tools/deps-exe/s6-ipcserverd b/src/conn-tools/deps-exe/s6-ipcserverd @@ -1,2 +1,3 @@ -lskarnet ${SOCKET_LIB} +${SPAWN_LIB} diff --git a/src/conn-tools/deps-exe/s6-sudod b/src/conn-tools/deps-exe/s6-sudod @@ -1,3 +1,4 @@ -lskarnet ${SOCKET_LIB} +${SPAWN_LIB} ${SYSCLOCK_LIB} diff --git a/src/conn-tools/s6-sudod.c b/src/conn-tools/s6-sudod.c @@ -18,7 +18,7 @@ #include <skalibs/iopause.h> #include <skalibs/selfpipe.h> #include <skalibs/env.h> -#include <skalibs/exec.h> +#include <skalibs/cspawn.h> #include <skalibs/djbunix.h> #include <skalibs/unix-timed.h> #include <skalibs/unixmessage.h> @@ -114,6 +114,7 @@ int main (int argc, char const *const *argv, char const *const *envp) strerr_dief1x(100, "wrong client argc/envlen") ; if ((cargc > 131072) || (cenvc > 131072)) strerr_dief1x(100, "too many args/envvars from client") ; + if (argc + cargc == 0) strerr_dief1x(100, "client and server args both empty") ; if (nullfds & 1) { @@ -134,9 +135,14 @@ int main (int argc, char const *const *argv, char const *const *envp) } { + cspawn_fileaction fa[3] = + { + [0] = { .type = CSPAWN_FA_MOVE, .x = { .fd2 = { [0] = 0, [1] = m.fds[0] } } }, + [1] = { .type = CSPAWN_FA_MOVE, .x = { .fd2 = { [0] = 1, [1] = m.fds[1] } } }, + [2] = { .type = CSPAWN_FA_MOVE, .x = { .fd2 = { [0] = 2, [1] = m.fds[2] } } } + } ; char const *targv[argc + 1 + cargc] ; char const *tenvp[envc + 1 + cenvc] ; - int p[2] ; unsigned int i = 0 ; for (; i < (unsigned int)argc ; i++) targv[i] = argv[i] ; for (i = 0 ; i <= envc ; i++) tenvp[i] = envp[i] ; @@ -177,40 +183,9 @@ int main (int argc, char const *const *argv, char const *const *envp) x[0].fd = selfpipe_init() ; if (x[0].fd < 0) strerr_diefu1sys(111, "selfpipe_init") ; if (!selfpipe_trap(SIGCHLD)) strerr_diefu1sys(111, "trap SIGCHLD") ; - if (pipecoe(p) < 0) strerr_diefu1sys(111, "pipe") ; - pid = fork() ; - if (pid < 0) strerr_diefu1sys(111, "fork") ; - if (!pid) - { - char c ; - PROG = "s6-sudod (child)" ; - if ((fd_move(2, m.fds[2]) < 0) - || (fd_move(1, m.fds[1]) < 0) - || (fd_move(0, m.fds[0]) < 0)) - { - char c = errno ; - fd_write(p[1], &c, 1) ; - strerr_diefu1sys(111, "move fds") ; - } - selfpipe_finish() ; - exec0_e(targv, tenvp) ; - c = errno ; - fd_write(p[1], &c, 1) ; - strerr_dieexec(c == ENOENT ? 127 : 126, targv[0]) ; - } - fd_close(p[1]) ; - { - char c ; - ssize_t r = fd_read(p[0], &c, 1) ; - if (r < 0) strerr_diefu1sys(111, "read from child") ; - if (r) - { - buffer_putnoflush(buffer_1small, &c, 1) ; - buffer_timed_flush_g(buffer_1small, &deadline) ; - return 111 ; - } - } - fd_close(p[0]) ; + + pid = cspawn(targv[0], targv, tenvp, CSPAWN_FLAGS_SELFPIPE_FINISH, fa, 3) ; + if (!pid) strerr_diefu2sys(111, "spawn ", targv[0]) ; } fd_close(m.fds[0]) ;