about summary refs log tree commit diff
path: root/src/supervision/s6-svdir-unlink.c
blob: 0e8699e0bbcf9af1a7dc5eb4f6899542b1d44df2 (plain) (blame)
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
/* ISC license. */

#include <stdint.h>

#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>

#include <s6/s6-supervise.h>

#define USAGE "s6-svdir-unlink [ -d ] [ -x ] scandir servicename"
#define dieusage() strerr_dieusage(100, USAGE)

int main (int argc, char const *const *argv)
{
  uint32_t options = 0 ;
  PROG = "s6-svdir-link" ;
  {
    subgetopt l = SUBGETOPT_ZERO ;
    for (;;)
    {
      int opt = subgetopt_r(argc, argv, "dx", &l) ;
      if (opt == -1) break ;
      switch (opt)
      {
        case 'd' : options = 3 ; break ;
        case 'x' : options = 1 ; break ;
        default : dieusage() ;
      }
    }
    argc -= l.ind ; argv += l.ind ;
  }
  if (argc < 2) dieusage() ;

  if (!argv[1][0] || argv[1][0] == '.' || argv[1][0] == '/')
    strerr_dief1x(100, "invalid service name") ;
  s6_supervise_unlink(argv[0], argv[1], options) ;
  return 0 ;
}