summaryrefslogtreecommitdiff
path: root/src/tls/s6tls_exec_tlsdio.c
blob: b00adb2e3f3a68ea0859446b49aab5fcbf036be6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* ISC license. */

#include <skalibs/posixplz.h>
#include <skalibs/types.h>
#include <skalibs/djbunix.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)
{
  char const *newargv[13] ;
  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-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 ;
  }
  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 ;
  xpathexec_run(newargv[0], newargv, (char const *const *)environ) ;
}