s6

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

ftrigr_wait_and.c (649B)


      1 /* ISC license. */
      2 
      3 #include <errno.h>
      4 #include <skalibs/iopause.h>
      5 #include <s6/ftrigr.h>
      6 
      7 int ftrigr_wait_and (ftrigr_t *a, uint16_t const *idlist, unsigned int n, tain const *deadline, tain *stamp)
      8 {
      9   iopause_fd x = { -1, IOPAUSE_READ, 0 } ;
     10   x.fd = ftrigr_fd(a) ;
     11   for (; n ; n--, idlist++)
     12   {
     13     for (;;)
     14     {
     15       char dummy ;
     16       int r = ftrigr_check(a, *idlist, &dummy) ;
     17       if (r < 0) return r ;
     18       else if (r) break ;
     19       r = iopause_stamp(&x, 1, deadline, stamp) ;
     20       if (r < 0) return r ;
     21       else if (!r) return (errno = ETIMEDOUT, -1) ;
     22       else if (ftrigr_updateb(a) < 0) return -1 ;
     23     }
     24   }
     25 
     26   return 1 ;
     27 }