s6-svunlink.c (1280B)
1 /* ISC license. */ 2 3 #include <stdint.h> 4 5 #include <skalibs/posixplz.h> 6 #include <skalibs/types.h> 7 #include <skalibs/sgetopt.h> 8 #include <skalibs/strerr.h> 9 #include <skalibs/tai.h> 10 11 #include <s6/supervise.h> 12 13 #define USAGE "s6-svunlink [ -X ] [ -t timeout ] scandir servicename" 14 #define dieusage() strerr_dieusage(100, USAGE) 15 16 int main (int argc, char const *const *argv) 17 { 18 tain tto = TAIN_INFINITE_RELATIVE ; 19 uint32_t options = 1 ; 20 PROG = "s6-svunlink" ; 21 { 22 unsigned int t = 0 ; 23 subgetopt l = SUBGETOPT_ZERO ; 24 for (;;) 25 { 26 int opt = subgetopt_r(argc, argv, "Xt:", &l) ; 27 if (opt == -1) break ; 28 switch (opt) 29 { 30 case 'X' : options &= ~1U ; break ; 31 case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; 32 default : dieusage() ; 33 } 34 } 35 argc -= l.ind ; argv += l.ind ; 36 if (t) tain_from_millisecs(&tto, t) ; 37 } 38 if (argc < 2) dieusage() ; 39 40 if (!argv[1][0] || argv[1][0] == '.' || argv[1][0] == '/') 41 strerr_dief1x(100, "invalid service name") ; 42 43 tain_now_set_stopwatch_g() ; 44 tain_add_g(&tto, &tto) ; 45 46 if (s6_supervise_unlink_names_g(argv[0], argv + 1, 1, options, &tto) == -1) 47 strerr_diefu4sys(111, "prepare unlinking of service ", argv[1], " in scandir ", argv[0]) ; 48 return 0 ; 49 }