summaryrefslogtreecommitdiff
path: root/src/supervision/s6-svok.c
blob: 4a615e9aa3ed2c66755fe2f3a95e8f620351f7c5 (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
/* ISC license. */

#include <errno.h>
#include <skalibs/bytestr.h>
#include <skalibs/strerr2.h>
#include <skalibs/djbunix.h>
#include <s6/s6-supervise.h>

#define USAGE "s6-svok servicedir"

int main (int argc, char const *const *argv)
{
  PROG = "s6-svok" ;
  if (argc < 2) strerr_dieusage(100, USAGE) ;
  argv++ ; argc-- ;
  {
    int fd ;
    unsigned int dirlen = str_len(*argv) ;
    char fn[dirlen + 9 + sizeof(S6_SUPERVISE_CTLDIR)] ;
    byte_copy(fn, dirlen, *argv) ;
    fn[dirlen] = '/' ;
    byte_copy(fn + dirlen + 1, sizeof(S6_SUPERVISE_CTLDIR) - 1, S6_SUPERVISE_CTLDIR) ;
    byte_copy(fn + dirlen + sizeof(S6_SUPERVISE_CTLDIR), 9, "/control") ;
    fd = open_write(fn) ;
    if (fd < 0)
    {
      if ((errno == ENXIO) || (errno == ENOENT)) return 1 ;
      else strerr_diefu2sys(111, "open_write ", fn) ;
    }
  }
  return 0 ;
}