From fdd1f0c0ec33575a78b589b46d095c3a4a0d8510 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 8 Sep 2023 19:38:35 +0000 Subject: Fully defork s6-tlsc and s6-tlsd Signed-off-by: Laurent Bercot --- src/tls/s6-ucspitlsc.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/tls/s6-ucspitlsc.c') diff --git a/src/tls/s6-ucspitlsc.c b/src/tls/s6-ucspitlsc.c index 2d728b5..4f284b7 100644 --- a/src/tls/s6-ucspitlsc.c +++ b/src/tls/s6-ucspitlsc.c @@ -21,17 +21,16 @@ static inline void child (int [4][2], uint32_t, unsigned int, unsigned int, char const *, pid_t) gccattr_noreturn ; static inline void child (int p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout, char const *servername, pid_t pid) { + ssize_t r ; char const *newargv[S6TLS_PREP_IO_ARGC] ; char buf[S6TLS_PREP_IO_BUFLEN] ; - ssize_t r ; char c ; PROG = "s6-ucspitlsc" ; close(p[2][0]) ; - close(p[0][1]) ; close(p[1][0]) ; + close(p[0][1]) ; 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) ; r = read(p[2][1], &c, 1) ; if (r < 0) strerr_diefu1sys(111, "read from control socket") ; if (!r) @@ -48,7 +47,7 @@ static inline void child (int p[4][2], uint32_t options, unsigned int verbosity, { case 'y' : close(p[2][1]) ; - p[2][1] = 0 ; /* we know 0 is open so it's a correct invalid value */ + p[2][1] = 0 ; /* we know 0 is open so it's a suitable invalid value */ break ; case 'Y' : fd_shutdown(p[2][1], 0) ; @@ -56,6 +55,7 @@ static inline void child (int p[4][2], uint32_t options, unsigned int verbosity, default : strerr_dief1x(100, "unrecognized command on control socket") ; } + s6tls_prep_tlscio(newargv, buf, p, options, verbosity, kimeout, servername) ; if (verbosity >= 2) { char fmt[PID_FMT] ; @@ -69,7 +69,7 @@ int main (int argc, char const *const *argv, char const *const *envp) { 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 ; char const *servername = 0 ; @@ -114,12 +114,13 @@ int main (int argc, char const *const *argv, char const *const *envp) } 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 (ipc_pair_b(p[2]) < 0) strerr_diefu1sys(111, "ipc_pair") ; - if (pipe(p[0]) < 0 || pipe(p[1]) < 0) strerr_diefu1sys(111, "pipe") ; + if (ipc_pair_b(p[2]) == -1) strerr_diefu1sys(111, "ipc_pair") ; + if (pipe(p[0]) == -1 || pipe(p[1]) == -1) strerr_diefu1sys(111, "pipe") ; pid = getpid() ; + switch (fork()) { case -1 : strerr_diefu1sys(111, "fork") ; -- cgit v1.2.3