s6-fdholder-store.c (1497B)
1 /* ISC license. */ 2 3 #include <skalibs/types.h> 4 #include <skalibs/strerr.h> 5 #include <skalibs/sgetopt.h> 6 #include <skalibs/tai.h> 7 #include <s6/fdholder.h> 8 9 #define USAGE "s6-fdholder-store [ -d fd ] [ -t timeout ] [ -T fdtimeout ] 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, limit ; 16 unsigned int fd = 0 ; 17 PROG = "s6-fdholder-store" ; 18 { 19 unsigned int t = 0, T = 0 ; 20 subgetopt l = SUBGETOPT_ZERO ; 21 for (;;) 22 { 23 int opt = subgetopt_r(argc, argv, "d:t:T:", &l) ; 24 if (opt == -1) break ; 25 switch (opt) 26 { 27 case 'd' : if (!uint0_scan(l.arg, &fd)) dieusage() ; break ; 28 case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; 29 case 'T' : if (!uint0_scan(l.arg, &T)) dieusage() ; break ; 30 default : dieusage() ; 31 } 32 } 33 argc -= l.ind ; argv += l.ind ; 34 if (t) tain_from_millisecs(&deadline, t) ; 35 else deadline = tain_infinite_relative ; 36 if (T) tain_from_millisecs(&limit, T) ; 37 else limit = tain_infinite_relative ; 38 } 39 if (argc < 2) dieusage() ; 40 41 tain_now_set_stopwatch_g() ; 42 tain_add_g(&deadline, &deadline) ; 43 tain_add_g(&limit, &limit) ; 44 if (!s6_fdholder_start_g(&a, argv[0], &deadline)) 45 strerr_diefu2sys(111, "connect to a fd-holder daemon at ", argv[0]) ; 46 if (!s6_fdholder_store_g(&a, fd, argv[1], &limit, &deadline)) 47 strerr_diefu1sys(1, "store fd") ; 48 return 0 ; 49 }