summaryrefslogtreecommitdiff
path: root/src/tls/s6-tlsd.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-09-08 19:38:35 +0000
committerLaurent Bercot <ska@appnovation.com>2023-09-08 19:38:35 +0000
commitfdd1f0c0ec33575a78b589b46d095c3a4a0d8510 (patch)
tree231894189c8baf3833418afe1e9fc6587c19d091 /src/tls/s6-tlsd.c
parent7113c4cf792ec44ec04a54e9723fa31a97bee5a7 (diff)
downloads6-networking-fdd1f0c0ec33575a78b589b46d095c3a4a0d8510.tar.xz
Fully defork s6-tlsc and s6-tlsd
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/tls/s6-tlsd.c')
-rw-r--r--src/tls/s6-tlsd.c38
1 files changed, 9 insertions, 29 deletions
diff --git a/src/tls/s6-tlsd.c b/src/tls/s6-tlsd.c
index c9ef5d2..07716ea 100644
--- a/src/tls/s6-tlsd.c
+++ b/src/tls/s6-tlsd.c
@@ -3,43 +3,27 @@
#include <stdint.h>
#include <unistd.h>
-#include <skalibs/gccattributes.h>
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
-#include <skalibs/env.h>
-#include <skalibs/djbunix.h>
-#include <skalibs/exec.h>
#include "s6tls-internal.h"
#define USAGE "s6-tlsd [ -S | -s ] [ -Y | -y ] [ -k snilevel ] [ -v verbosity ] [ -K timeout ] [ -Z | -z ] prog..."
#define dieusage() strerr_dieusage(100, USAGE)
-static void child (int const [4][2], uint32_t, unsigned int, unsigned int, unsigned int) gccattr_noreturn ;
-static void child (int const p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout, unsigned int snilevel)
-{
- char const *newargv[S6TLS_PREP_IO_ARGC] ;
- char buf[S6TLS_PREP_IO_BUFLEN] ;
- PROG = "s6-tlsd (child)" ;
- close(p[2][0]) ;
- close(p[0][1]) ;
- close(p[1][0]) ;
- s6tls_prep_tlsdio(newargv, buf, p[0][0], p[1][1], p[2][1], options, verbosity, kimeout, snilevel) ;
- xexec(newargv) ;
-}
-
int main (int argc, char const *const *argv)
{
unsigned int verbosity = 1 ;
unsigned int kimeout = 0 ;
unsigned int snilevel = 0 ;
- int p[4][2] = { [3] = { 0, 1 } } ;
+ int p[4][2] = { [3] = { [0] = -1, [1] = -1 } } ;
uint32_t coptions = 0 ;
uint32_t poptions = 1 ;
pid_t pid ;
-
- PROG = "s6-tlsd (parent)" ;
+ char const *newargv[S6TLS_PREP_IO_ARGC] ;
+ char buf[S6TLS_PREP_IO_BUFLEN] ;
+ PROG = "s6-tlsd" ;
{
subgetopt l = SUBGETOPT_ZERO ;
for (;;)
@@ -64,14 +48,10 @@ int main (int argc, char const *const *argv)
}
if (!argc) dieusage() ;
- if (pipe(p[0]) < 0 || pipe(p[1]) < 0 || pipe(p[2]) < 0)
- strerr_diefu1sys(111, "pipe") ;
- pid = fork() ;
- switch (pid)
- {
- case -1 : strerr_diefu1sys(111, "fork") ;
- case 0 : child(p, coptions, verbosity, kimeout, snilevel) ;
- default : break ;
- }
+ if (pipe(p[0]) == -1 || pipe(p[1]) == -1 || pipe(p[2]) == -1)
+ strerr_diefu1sys(111, "create pipe") ;
+ s6tls_prep_tlsdio(newargv, buf, p, coptions, verbosity, kimeout, snilevel) ;
+ pid = s6tls_io_spawn(newargv, p) ;
+ if (!pid) strerr_diefu2sys(111, "spawn ", newargv[0]) ;
s6tls_sync_and_exec_app(argv, p, pid, poptions) ;
}