summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-09-11 08:37:33 +0000
committerLaurent Bercot <ska@appnovation.com>2023-09-11 08:37:33 +0000
commitde03e80a55ec78c93a749f41dfc69e806e655b0e (patch)
tree1519a9baf41eb2c1bbb489219f102687ed5908dc
parentbc3863eaf3e4ae92eac8cd3ce0ca9dcb8915fc36 (diff)
downloads6-de03e80a55ec78c93a749f41dfc69e806e655b0e.tar.xz
Defork s6-sudod
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r--package/deps.mak4
-rw-r--r--src/conn-tools/deps-exe/s6-ipcserverd1
-rw-r--r--src/conn-tools/deps-exe/s6-sudod1
-rw-r--r--src/conn-tools/s6-sudod.c47
4 files changed, 15 insertions, 38 deletions
diff --git a/package/deps.mak b/package/deps.mak
index a42c027..751b052 100644
--- 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
index 19869b2..fad0b6f 100644
--- 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
index 720fe7d..e0884d6 100644
--- 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
index 060628d..c455c32 100644
--- 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]) ;