s6-svscanctl.c (1331B)
1 /* ISC license. */ 2 3 #include <skalibs/sgetopt.h> 4 #include <skalibs/strerr.h> 5 #include <s6/supervise.h> 6 7 #define USAGE "s6-svscanctl [ -zabhitqnN ] svscandir" 8 #define dieusage() strerr_dieusage(100, USAGE) 9 10 #define DATASIZE 64 11 12 int main (int argc, char const *const *argv) 13 { 14 char data[DATASIZE] ; 15 unsigned int datalen = 0 ; 16 PROG = "s6-svscanctl" ; 17 { 18 subgetopt l = SUBGETOPT_ZERO ; 19 for (;;) 20 { 21 int opt = subgetopt_r(argc, argv, "phratszbnNiq0678", &l) ; 22 if (opt == -1) break ; 23 switch (opt) 24 { 25 case 'z' : 26 case 'a' : 27 case 'b' : 28 case 'h' : 29 case 'i' : 30 case 't' : 31 case 'q' : 32 case 'n' : 33 case 'N' : 34 { 35 if (datalen >= DATASIZE) strerr_dief1x(100, "too many commands") ; 36 data[datalen++] = opt ; 37 break ; 38 } 39 default : dieusage() ; 40 } 41 } 42 argc -= l.ind ; argv += l.ind ; 43 } 44 if (!argc) dieusage() ; 45 46 switch (s6_svc_writectl(argv[0], S6_SVSCAN_CTLDIR, data, datalen)) 47 { 48 case -1 : strerr_diefu2sys(111, "control ", argv[0]) ; 49 case -2 : strerr_dief3sys(100, "something is wrong with the ", argv[0], "/" S6_SVSCAN_CTLDIR " directory. errno reported") ; 50 case 0 : strerr_diefu3x(100, "control ", argv[0], ": supervisor not listening") ; 51 } 52 return 0 ; 53 }