s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

s6-fdholder-delete.c (1182B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/types.h>
      4 #include <skalibs/sgetopt.h>
      5 #include <skalibs/strerr.h>
      6 #include <skalibs/tai.h>
      7 #include <s6/fdholder.h>
      8 
      9 #define USAGE "s6-fdholder-delete [ -t timeout ] socket id"
     10 #define dieusage() strerr_dieusage(100, USAGE)
     11 
     12 int main (int argc, char const *const *argv)
     13 {
     14   s6_fdholder_t a = S6_FDHOLDER_ZERO ;
     15   tain deadline ;
     16   PROG = "s6-fdholder-delete" ;
     17   {
     18     unsigned int t = 0 ;
     19     subgetopt l = SUBGETOPT_ZERO ;
     20     for (;;)
     21     {
     22       int opt = subgetopt_r(argc, argv, "t:", &l) ;
     23       if (opt == -1) break ;
     24       switch (opt)
     25       {
     26         case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
     27         default : dieusage() ;
     28       }
     29     }
     30     argc -= l.ind ; argv += l.ind ;
     31     if (t) tain_from_millisecs(&deadline, t) ;
     32     else deadline = tain_infinite_relative ;
     33   }
     34   if (argc < 2) dieusage() ;
     35   tain_now_set_stopwatch_g() ;
     36   tain_add_g(&deadline, &deadline) ;
     37   if (!s6_fdholder_start_g(&a, argv[0], &deadline))
     38     strerr_diefu2sys(111, "connect to a fd-holder daemon at ", argv[0]) ;
     39   if (!s6_fdholder_delete_g(&a, argv[1], &deadline))
     40     strerr_diefu2sys(1, "delete fd for id ", argv[0]) ;
     41   return 0 ;
     42 }