summaryrefslogtreecommitdiff
path: root/src/skaembutils/s6-nuke.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-09-19 02:53:32 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-09-19 02:53:32 +0000
commitbea0037dbdd979603fb0b5be8b43f5478c1f6fec (patch)
tree5776ae3af5a3e83d41c7087f70713952b6360988 /src/skaembutils/s6-nuke.c
downloads6-portable-utils-bea0037dbdd979603fb0b5be8b43f5478c1f6fec.tar.xz
initial commit
Diffstat (limited to 'src/skaembutils/s6-nuke.c')
-rw-r--r--src/skaembutils/s6-nuke.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/skaembutils/s6-nuke.c b/src/skaembutils/s6-nuke.c
new file mode 100644
index 0000000..cda1279
--- /dev/null
+++ b/src/skaembutils/s6-nuke.c
@@ -0,0 +1,50 @@
+/* ISC license. */
+
+#include <sys/types.h>
+#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 (;;)
+ {
+ register 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 ;
+}