about summary refs log tree commit diff
path: root/src/skaembutils/s6-nuke.c
blob: df6916d4f3ecd892d263ab2d601ae2779d95a4c1 (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
39
40
41
42
43
44
45
46
47
48
49
/* ISC license. */

#include <signal.h>
#include <errno.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/sig.h>

#define USAGE "s6-nuke [ -h | -t | -k ]"

int main (int argc, char const *const *argv)
{
  int doterm = 0, dohangup = 0, dokill = 0 ;
  PROG = "s6-nuke" ;
  {
    subgetopt_t l = SUBGETOPT_ZERO ;
    for (;;)
    {
      int opt = subgetopt_r(argc, argv, "htk", &l) ;
      if (opt == -1) break ;
      switch (opt)
      {
        case 'h': dohangup = 1 ; break ;
        case 't': doterm = 1 ; break ;
        case 'k': dokill = 1 ; break ;
        default : strerr_dieusage(100, USAGE) ;
      }
    }
    argc -= l.ind ; argv += l.ind ;
  }

  if (dohangup)
  {
    sig_ignore(SIGHUP) ;
    kill(-1, SIGHUP) ;
  }

  if (doterm)
  {
    sig_ignore(SIGTERM) ;
    kill(-1, SIGTERM) ;
    kill(-1, SIGCONT) ;
  }

  if (dokill) kill(-1, SIGKILL) ;

  if (errno) strerr_diefu1sys(111, "kill") ;
  return 0 ;
}