summaryrefslogtreecommitdiff
path: root/src/tls/s6tls_exec_tlscio.c
blob: e4e84f9144931fe8fc460a2950363f4c1675b9e4 (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
50
51
52
/* 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) ;
}