summaryrefslogtreecommitdiff
path: root/src/tls/s6-tlsc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tls/s6-tlsc.c')
-rw-r--r--src/tls/s6-tlsc.c38
1 files changed, 9 insertions, 29 deletions
diff --git a/src/tls/s6-tlsc.c b/src/tls/s6-tlsc.c
index 26703ba..dddb093 100644
--- a/src/tls/s6-tlsc.c
+++ b/src/tls/s6-tlsc.c
@@ -4,44 +4,27 @@
#include <unistd.h>
#include <fcntl.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-tlsc [ -S | -s ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -k servername ] [ -Z | -z ] [ -6 fdr ] [ -7 fdw ] prog..."
#define dieusage() strerr_dieusage(100, USAGE)
-static void child (int const [4][2], uint32_t, unsigned int, unsigned int, char const *) gccattr_noreturn ;
-static void child (int const p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout, char const *servername)
-{
- char const *newargv[S6TLS_PREP_IO_ARGC] ;
- char buf[S6TLS_PREP_IO_BUFLEN] ;
- PROG = "s6-tlsc (child)" ;
- close(p[2][0]) ;
- close(p[0][1]) ;
- close(p[1][0]) ;
- if (fd_move(0, p[3][0]) == -1 || fd_move(1, p[3][1]) == -1)
- strerr_diefu1sys(111, "move network fds to stdin/stdout") ;
- s6tls_prep_tlscio(newargv, buf, p[0][0], p[1][1], p[2][1], options, verbosity, kimeout, servername) ;
- xexec(newargv) ;
-}
-
int main (int argc, char const *const *argv)
{
unsigned int verbosity = 1 ;
unsigned int kimeout = 0 ;
- int p[4][2] = { [3] = { 6, 7 } } ;
+ int p[4][2] = { [3] = { [0] = 6, [1] = 7 } } ;
uint32_t coptions = 0 ;
uint32_t poptions = 1 ;
pid_t pid ;
char const *servername = 0 ;
-
+ char const *newargv[S6TLS_PREP_IO_ARGC] ;
+ char buf[S6TLS_PREP_IO_BUFLEN] ;
PROG = "s6-tlsc" ;
{
subgetopt l = SUBGETOPT_ZERO ;
@@ -80,18 +63,15 @@ int main (int argc, char const *const *argv)
argc -= l.ind ; argv += l.ind ;
}
if (!argc) dieusage() ;
+
fd_sanitize() ;
- if (fcntl(p[3][0], F_GETFD) < 0 || fcntl(p[3][1], F_GETFD) < 0)
+ if (fcntl(p[3][0], F_GETFD) == -1 || fcntl(p[3][1], F_GETFD) == -1)
strerr_diefu1sys(111, "check network fds") ;
- if (pipe(p[0]) < 0 || pipe(p[1]) < 0 || pipe(p[2]) < 0)
+ if (pipe(p[0]) == -1 || pipe(p[1]) == -1 || pipe(p[2]) == -1)
strerr_diefu1sys(111, "pipe") ;
- pid = fork() ;
- switch (pid)
- {
- case -1 : strerr_diefu1sys(111, "fork") ;
- case 0 : child(p, coptions, verbosity, kimeout, servername) ;
- default : break ;
- }
+ s6tls_prep_tlscio(newargv, buf, p, coptions, verbosity, kimeout, servername) ;
+ pid = s6tls_io_spawn(newargv, p) ;
+ if (!pid) strerr_diefu2sys(111, "spawn ", newargv[0]) ;
s6tls_sync_and_exec_app(argv, p, pid, poptions) ;
}