diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2020-11-21 11:51:08 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2020-11-21 11:51:08 +0000 |
commit | 7f2cd05720e721c7e8131d4a4762d97a29fbf7b4 (patch) | |
tree | 0c9f5e4647b8e63c295a05f0439bd1c54c5bbbeb /src/conn-tools/s6-ucspitlsd.c | |
parent | 2269af1457817b7a3b9b51cc0512d5f29e1fc7a5 (diff) | |
download | s6-networking-7f2cd05720e721c7e8131d4a4762d97a29fbf7b4.tar.xz |
Add s6-ucspitlsc
Diffstat (limited to 'src/conn-tools/s6-ucspitlsd.c')
-rw-r--r-- | src/conn-tools/s6-ucspitlsd.c | 53 |
1 files changed, 14 insertions, 39 deletions
diff --git a/src/conn-tools/s6-ucspitlsd.c b/src/conn-tools/s6-ucspitlsd.c index 2ce24ba..4bfa253 100644 --- a/src/conn-tools/s6-ucspitlsd.c +++ b/src/conn-tools/s6-ucspitlsd.c @@ -1,15 +1,12 @@ /* ISC license. */ #include <stdint.h> -#include <string.h> #include <unistd.h> -#include <stdlib.h> #include <skalibs/gccattributes.h> #include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> -#include <skalibs/env.h> #include <skalibs/djbunix.h> #include <skalibs/webipc.h> @@ -19,8 +16,8 @@ #define USAGE "s6-ucspitlsd [ -S | -s ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -Z | -z ] prog..." #define dieusage() strerr_dieusage(100, USAGE) -static inline void child (int [3][2], uint32_t, unsigned int, unsigned int) gccattr_noreturn ; -static inline void child (int p[3][2], uint32_t options, unsigned int verbosity, unsigned int kimeout) +static inline void child (int [4][2], uint32_t, unsigned int, unsigned int) gccattr_noreturn ; +static inline void child (int p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout) { int fds[3] = { p[0][0], p[1][1], p[2][1] } ; ssize_t r ; @@ -48,11 +45,11 @@ static inline void child (int p[3][2], uint32_t options, unsigned int verbosity, int main (int argc, char const *const *argv, char const *const *envp) { - unsigned int kimeout = 0 ; unsigned int verbosity = 1 ; - uint32_t options = 0 ; - int cleanenv = 1 ; - int p[3][2] ; + unsigned int kimeout = 0 ; + int p[4][2] = { [3] = { 0, 1 } } ; + uint32_t coptions = 0 ; + uint32_t poptions = 1 ; PROG = "s6-ucspitlsd (parent)" ; { @@ -63,14 +60,14 @@ int main (int argc, char const *const *argv, char const *const *envp) if (opt == -1) break ; switch (opt) { - case 'S' : options |= 4 ; break ; - case 's' : options &= ~4 ; break ; - case 'Y' : options |= 1 ; options &= ~2 ; break ; - case 'y' : options |= 3 ; break ; + case 'S' : coptions |= 4 ; break ; + case 's' : coptions &= ~4 ; break ; + case 'Y' : coptions |= 1 ; coptions &= ~2 ; break ; + case 'y' : coptions |= 3 ; break ; case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; case 'K' : if (!uint0_scan(l.arg, &kimeout)) dieusage() ; break ; - case 'Z' : cleanenv = 0 ; break ; - case 'z' : cleanenv = 1 ; break ; + case 'Z' : poptions &= ~1 ; break ; + case 'z' : poptions |= 1 ; break ; default : dieusage() ; } } @@ -84,30 +81,8 @@ int main (int argc, char const *const *argv, char const *const *envp) switch (fork()) { case -1 : strerr_diefu1sys(111, "fork") ; - case 0 : child(p, options, verbosity, kimeout) ; + case 0 : child(p, coptions, verbosity, kimeout) ; default : break ; } - - { - size_t m = 0 ; - char modif[sizeof(s6tls_envvars) + 33 + 3 * UINT_FMT] ; - close(p[2][1]) ; - close(p[1][1]) ; - close(p[0][0]) ; - if (cleanenv) - { - memcpy(modif + m, s6tls_envvars, sizeof(s6tls_envvars)) ; - m += sizeof(s6tls_envvars) ; - } - memcpy(modif + m, "SSLCTLFD=", 9) ; m += 9 ; - m += uint_fmt(modif + m, p[2][0]) ; - modif[m++] = 0 ; - memcpy(modif + m, "SSLREADFD=", 10) ; m += 10 ; - m += uint_fmt(modif + m, p[1][0]) ; - modif[m++] = 0 ; - memcpy(modif + m, "SSLWRITEFD=", 11) ; m += 11 ; - m += uint_fmt(modif + m, p[0][1]) ; - modif[m++] = 0 ; - xpathexec_r(argv, envp, env_len(envp), modif, m) ; - } + s6tls_ucspi_exec_app(argv, p, poptions) ; } |