summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-09-08 08:38:06 +0000
committerLaurent Bercot <ska@appnovation.com>2023-09-08 08:38:06 +0000
commit7113c4cf792ec44ec04a54e9723fa31a97bee5a7 (patch)
treecb13b4316f0a164e83ffba5ca603dcf11c26045c /src
parent9efa646c7fb520747804acdc829b3cccea0dce63 (diff)
downloads6-networking-7113c4cf792ec44ec04a54e9723fa31a97bee5a7.tar.xz
Refactor s6-tls[cd] so they're ready to port to posix_spawn
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/tls/deps-lib/s6tls4
-rw-r--r--src/tls/s6-tlsc.c9
-rw-r--r--src/tls/s6-tlsd.c7
-rw-r--r--src/tls/s6-ucspitlsc.c9
-rw-r--r--src/tls/s6-ucspitlsd.c9
-rw-r--r--src/tls/s6tls-internal.h8
-rw-r--r--src/tls/s6tls_exec_tlscio.c52
-rw-r--r--src/tls/s6tls_exec_tlsdio.c55
-rw-r--r--src/tls/s6tls_prep_tlscio.c50
-rw-r--r--src/tls/s6tls_prep_tlsdio.c53
10 files changed, 134 insertions, 122 deletions
diff --git a/src/tls/deps-lib/s6tls b/src/tls/deps-lib/s6tls
index f2306ac..07ad2f2 100644
--- a/src/tls/deps-lib/s6tls
+++ b/src/tls/deps-lib/s6tls
@@ -1,6 +1,6 @@
s6tls_clean_and_exec.o
-s6tls_exec_tlscio.o
-s6tls_exec_tlsdio.o
+s6tls_prep_tlscio.o
+s6tls_prep_tlsdio.o
s6tls_sync_and_exec_app.o
s6tls_ucspi_exec_app.o
-lskarnet
diff --git a/src/tls/s6-tlsc.c b/src/tls/s6-tlsc.c
index 2cca21c..26703ba 100644
--- a/src/tls/s6-tlsc.c
+++ b/src/tls/s6-tlsc.c
@@ -10,6 +10,7 @@
#include <skalibs/strerr.h>
#include <skalibs/env.h>
#include <skalibs/djbunix.h>
+#include <skalibs/exec.h>
#include "s6tls-internal.h"
@@ -19,14 +20,16 @@
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)
{
- int fds[3] = { p[0][0], p[1][1], p[2][1] } ;
+ 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]) < 0 || fd_move(1, p[3][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_exec_tlscio(fds, options, verbosity, kimeout, servername) ;
+ 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)
diff --git a/src/tls/s6-tlsd.c b/src/tls/s6-tlsd.c
index 49c38c1..c9ef5d2 100644
--- a/src/tls/s6-tlsd.c
+++ b/src/tls/s6-tlsd.c
@@ -9,6 +9,7 @@
#include <skalibs/strerr.h>
#include <skalibs/env.h>
#include <skalibs/djbunix.h>
+#include <skalibs/exec.h>
#include "s6tls-internal.h"
@@ -18,12 +19,14 @@
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)
{
- int fds[3] = { p[0][0], p[1][1], p[2][1] } ;
+ 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_exec_tlsdio(fds, options, verbosity, kimeout, snilevel) ;
+ 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)
diff --git a/src/tls/s6-ucspitlsc.c b/src/tls/s6-ucspitlsc.c
index 521bb4d..2d728b5 100644
--- a/src/tls/s6-ucspitlsc.c
+++ b/src/tls/s6-ucspitlsc.c
@@ -10,6 +10,7 @@
#include <skalibs/strerr.h>
#include <skalibs/djbunix.h>
#include <skalibs/socket.h>
+#include <skalibs/exec.h>
#include <s6-networking/config.h>
#include "s6tls-internal.h"
@@ -20,15 +21,17 @@
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)
{
- int fds[3] = { p[0][0], p[1][1], p[2][1] } ;
+ 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]) ;
- if (fd_move(0, p[3][0]) < 0 || fd_move(1, p[3][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) ;
r = read(p[2][1], &c, 1) ;
if (r < 0) strerr_diefu1sys(111, "read from control socket") ;
if (!r)
@@ -59,7 +62,7 @@ static inline void child (int p[4][2], uint32_t options, unsigned int verbosity,
fmt[pid_fmt(fmt, pid)] = 0 ;
strerr_warni4x("pid ", fmt, " accepted", " opportunistic TLS") ;
}
- s6tls_exec_tlscio(fds, options, verbosity, kimeout, servername) ;
+ xexec(newargv) ;
}
int main (int argc, char const *const *argv, char const *const *envp)
diff --git a/src/tls/s6-ucspitlsd.c b/src/tls/s6-ucspitlsd.c
index 37ec435..ecce9d5 100644
--- a/src/tls/s6-ucspitlsd.c
+++ b/src/tls/s6-ucspitlsd.c
@@ -9,6 +9,7 @@
#include <skalibs/strerr.h>
#include <skalibs/djbunix.h>
#include <skalibs/socket.h>
+#include <skalibs/exec.h>
#include <s6-networking/config.h>
#include "s6tls-internal.h"
@@ -19,13 +20,15 @@
static inline void child (int [4][2], uint32_t, unsigned int, unsigned int, unsigned int, pid_t) gccattr_noreturn ;
static inline void child (int p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout, unsigned int snilevel, pid_t pid)
{
- int fds[3] = { p[0][0], p[1][1], p[2][1] } ;
+ char const *newargv[S6TLS_PREP_IO_ARGC] ;
+ char buf[S6TLS_PREP_IO_BUFLEN] ;
ssize_t r ;
char c ;
PROG = "s6-ucspitlsd" ;
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) ;
r = read(p[2][1], &c, 1) ;
if (r < 0) strerr_diefu1sys(111, "read from control socket") ;
if (!r)
@@ -42,7 +45,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,7 +59,7 @@ static inline void child (int p[4][2], uint32_t options, unsigned int verbosity,
fmt[pid_fmt(fmt, pid)] = 0 ;
strerr_warni4x("pid ", fmt, " accepted", " opportunistic TLS") ;
}
- s6tls_exec_tlsdio(fds, options, verbosity, kimeout, snilevel) ;
+ xexec(newargv) ;
}
int main (int argc, char const *const *argv)
diff --git a/src/tls/s6tls-internal.h b/src/tls/s6tls-internal.h
index d232266..cd96e87 100644
--- a/src/tls/s6tls-internal.h
+++ b/src/tls/s6tls-internal.h
@@ -7,9 +7,13 @@
#include <stdint.h>
#include <skalibs/gccattributes.h>
+#include <skalibs/types.h>
-extern void s6tls_exec_tlscio (int const *, uint32_t, unsigned int, unsigned int, char const *) gccattr_noreturn ;
-extern void s6tls_exec_tlsdio (int const *, uint32_t, unsigned int, unsigned int, unsigned int) gccattr_noreturn ;
+#define S6TLS_PREP_IO_ARGC 15
+#define S6TLS_PREP_IO_BUFLEN (5 * UINT_FMT)
+
+extern void s6tls_prep_tlscio (char const **, char *, int, int, int, uint32_t, unsigned int, unsigned int, char const *) ;
+extern void s6tls_prep_tlsdio (char const **, char *, int, int, int, uint32_t, unsigned int, unsigned int, unsigned int) ;
extern void s6tls_sync_and_exec_app (char const *const *, int const [4][2], pid_t, uint32_t) gccattr_noreturn ;
extern void s6tls_ucspi_exec_app (char const *const *, int const [4][2], uint32_t) gccattr_noreturn ;
extern void s6tls_clean_and_exec (char const *const *, uint32_t, char const *, size_t) gccattr_noreturn ;
diff --git a/src/tls/s6tls_exec_tlscio.c b/src/tls/s6tls_exec_tlscio.c
deleted file mode 100644
index e4e84f9..0000000
--- a/src/tls/s6tls_exec_tlscio.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/* ISC license. */
-
-#include <skalibs/types.h>
-#include <skalibs/exec.h>
-
-#include <s6-networking/config.h>
-#include "s6tls-internal.h"
-
-void s6tls_exec_tlscio (int const *fds, uint32_t options, unsigned int verbosity, unsigned int kimeout, char const *servername)
-{
- char const *newargv[15] ;
- unsigned int m = 0 ;
- char fmtv[UINT_FMT] ;
- char fmtd[UINT_FMT] ;
- char fmtk[UINT_FMT] ;
- char fmtr[UINT_FMT] ;
- char fmtw[UINT_FMT] ;
-
- newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tlsc-io" ;
- if (verbosity != 1)
- {
- newargv[m++] = "-v" ;
- newargv[m++] = fmtv ;
- fmtv[uint_fmt(fmtv, verbosity)] = 0 ;
- }
- if (fds[2])
- {
- newargv[m++] = "-d" ;
- newargv[m++] = fmtd ;
- fmtd[uint_fmt(fmtd, fds[2])] = 0 ;
- }
- newargv[m++] = options & 4 ? "-S" : "-s" ;
- newargv[m++] = options & 1 ? "-y" : "-Y" ;
- if (kimeout)
- {
- newargv[m++] = "-K" ;
- newargv[m++] = fmtk ;
- fmtk[uint_fmt(fmtk, kimeout)] = 0 ;
- }
- if (servername)
- {
- newargv[m++] = "-k" ;
- newargv[m++] = servername ;
- }
- newargv[m++] = "--" ;
- newargv[m++] = fmtr ;
- fmtr[uint_fmt(fmtr, fds[0])] = 0 ;
- newargv[m++] = fmtw ;
- fmtw[uint_fmt(fmtw, fds[1])] = 0 ;
- newargv[m++] = 0 ;
- xexec(newargv) ;
-}
diff --git a/src/tls/s6tls_exec_tlsdio.c b/src/tls/s6tls_exec_tlsdio.c
deleted file mode 100644
index f3bc999..0000000
--- a/src/tls/s6tls_exec_tlsdio.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* ISC license. */
-
-#include <skalibs/types.h>
-#include <skalibs/exec.h>
-
-#include <s6-networking/config.h>
-#include "s6tls-internal.h"
-
-void s6tls_exec_tlsdio (int const *fds, uint32_t options, unsigned int verbosity, unsigned int kimeout, unsigned int snilevel)
-{
- char const *newargv[15] ;
- unsigned int m = 0 ;
- char fmtv[UINT_FMT] ;
- char fmtd[UINT_FMT] ;
- char fmtk[UINT_FMT] ;
- char fmtr[UINT_FMT] ;
- char fmtw[UINT_FMT] ;
- char fmti[UINT_FMT] ;
-
- newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tlsd-io" ;
- if (verbosity != 1)
- {
- newargv[m++] = "-v" ;
- newargv[m++] = fmtv ;
- fmtv[uint_fmt(fmtv, verbosity)] = 0 ;
- }
- if (fds[2])
- {
- newargv[m++] = "-d" ;
- newargv[m++] = fmtd ;
- fmtd[uint_fmt(fmtd, fds[2])] = 0 ;
- }
- newargv[m++] = options & 4 ? "-S" : "-s" ;
- if (options & 1)
- newargv[m++] = options & 2 ? "-y" : "-Y" ;
- if (kimeout)
- {
- newargv[m++] = "-K" ;
- newargv[m++] = fmtk ;
- fmtk[uint_fmt(fmtk, kimeout)] = 0 ;
- }
- if (snilevel)
- {
- newargv[m++] = "-k" ;
- newargv[m++] = fmti ;
- fmti[uint_fmt(fmti, snilevel)] = 0 ;
- }
- newargv[m++] = "--" ;
- newargv[m++] = fmtr ;
- fmtr[uint_fmt(fmtr, fds[0])] = 0 ;
- newargv[m++] = fmtw ;
- fmtw[uint_fmt(fmtw, fds[1])] = 0 ;
- newargv[m++] = 0 ;
- xexec(newargv) ;
-}
diff --git a/src/tls/s6tls_prep_tlscio.c b/src/tls/s6tls_prep_tlscio.c
new file mode 100644
index 0000000..cf44511
--- /dev/null
+++ b/src/tls/s6tls_prep_tlscio.c
@@ -0,0 +1,50 @@
+/* ISC license. */
+
+#include <skalibs/types.h>
+
+#include <s6-networking/config.h>
+#include "s6tls-internal.h"
+
+void s6tls_prep_tlscio (char const **argv, char *buf, int fdr, int fdw, int fdnotif, uint32_t options, unsigned int verbosity, unsigned int kimeout, char const *servername)
+{
+ size_t m = 0 ;
+ size_t n = 0 ;
+
+ argv[m++] = S6_NETWORKING_BINPREFIX "s6-tlsc-io" ;
+ if (verbosity != 1)
+ {
+ argv[m++] = "-v" ;
+ argv[m++] = buf + n ;
+ n += uint_fmt(buf + n, verbosity) ;
+ buf[n++] = 0 ;
+ }
+ if (fdnotif)
+ {
+ argv[m++] = "-d" ;
+ argv[m++] = buf + n ;
+ n += uint_fmt(buf + n, fdnotif) ;
+ buf[n++] = 0 ;
+ }
+ argv[m++] = options & 4 ? "-S" : "-s" ;
+ argv[m++] = options & 1 ? "-y" : "-Y" ;
+ if (kimeout)
+ {
+ argv[m++] = "-K" ;
+ argv[m++] = buf + n ;
+ n += uint_fmt(buf + n, kimeout) ;
+ buf[n++] = 0 ;
+ }
+ if (servername)
+ {
+ argv[m++] = "-k" ;
+ argv[m++] = servername ;
+ }
+ argv[m++] = "--" ;
+ argv[m++] = buf + n ;
+ n += uint_fmt(buf + n, fdr) ;
+ buf[n++] = 0 ;
+ argv[m++] = buf + n ;
+ n += uint_fmt(buf + n, fdw) ;
+ buf[n++] = 0 ;
+ argv[m++] = 0 ;
+}
diff --git a/src/tls/s6tls_prep_tlsdio.c b/src/tls/s6tls_prep_tlsdio.c
new file mode 100644
index 0000000..942425b
--- /dev/null
+++ b/src/tls/s6tls_prep_tlsdio.c
@@ -0,0 +1,53 @@
+/* ISC license. */
+
+#include <skalibs/types.h>
+
+#include <s6-networking/config.h>
+#include "s6tls-internal.h"
+
+void s6tls_prep_tlsdio (char const **argv, char *buf, int fdr, int fdw, int fdnotif, uint32_t options, unsigned int verbosity, unsigned int kimeout, unsigned int snilevel)
+{
+ size_t m = 0 ;
+ size_t n = 0 ;
+
+ argv[m++] = S6_NETWORKING_BINPREFIX "s6-tlsd-io" ;
+ if (verbosity != 1)
+ {
+ argv[m++] = "-v" ;
+ argv[m++] = buf + n ;
+ n += uint_fmt(buf + n, verbosity) ;
+ buf[n++] = 0 ;
+ }
+ if (fdnotif)
+ {
+ argv[m++] = "-d" ;
+ argv[m++] = buf + n ;
+ n += uint_fmt(buf + n, fdnotif) ;
+ buf[n++] = 0 ;
+ }
+ argv[m++] = options & 4 ? "-S" : "-s" ;
+ if (options & 1)
+ argv[m++] = options & 2 ? "-y" : "-Y" ;
+ if (kimeout)
+ {
+ argv[m++] = "-K" ;
+ argv[m++] = buf + n ;
+ n += uint_fmt(buf + n, kimeout) ;
+ buf[n++] = 0 ;
+ }
+ if (snilevel)
+ {
+ argv[m++] = "-k" ;
+ argv[m++] = buf + n ;
+ n += uint_fmt(buf + n, snilevel) ;
+ buf[n++] = 0 ;
+ }
+ argv[m++] = "--" ;
+ argv[m++] = buf + n ;
+ n += uint_fmt(buf + n, fdr) ;
+ buf[n++] = 0 ;
+ argv[m++] = buf + n ;
+ n += uint_fmt(buf + n, fdw) ;
+ buf[n++] = 0 ;
+ argv[m++] = 0 ;
+}