s6

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

ftrigr_unsubscribe.c (833B)


      1 /* ISC license. */
      2 
      3 #include <errno.h>
      4 #include <skalibs/uint16.h>
      5 #include <skalibs/stralloc.h>
      6 #include <skalibs/gensetdyn.h>
      7 #include <skalibs/textclient.h>
      8 #include <s6/ftrigr.h>
      9 
     10 int ftrigr_unsubscribe (ftrigr_t *a, uint16_t i, tain const *deadline, tain *stamp)
     11 {
     12   ftrigr1_t *p ;
     13   char pack[3] = "--U" ;
     14   if (!i--) return (errno = EINVAL, 0) ;
     15   p = GENSETDYN_P(ftrigr1_t, &a->data, i) ;
     16   if (!p) return (errno = EINVAL, 0) ;
     17   switch (p->state)
     18   {
     19     case FR1STATE_WAITACK :
     20     case FR1STATE_WAITACKDATA :
     21     {
     22       char dummy ;
     23       ftrigr_check(a, i+1, &dummy) ;
     24       return 1 ;
     25     }
     26     default : break ;
     27   }
     28   uint16_pack_big(pack, i) ;
     29   if (!textclient_command(&a->connection, pack, 3, deadline, stamp)) return 0 ;
     30   stralloc_free(&p->what) ;
     31   *p = ftrigr1_zero ;
     32   return gensetdyn_delete(&a->data, i) ;
     33 }