s6

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

s6_svc_write.c (556B)


      1 /* ISC license. */
      2 
      3 #include <errno.h>
      4 #include <skalibs/allreadwrite.h>
      5 #include <skalibs/djbunix.h>
      6 #include <s6/supervise.h>
      7 
      8 int s6_svc_write (char const *fifo, char const *data, size_t datalen)
      9 {
     10   int fd = open_write(fifo) ;
     11   if (fd < 0) switch (errno)
     12   {
     13     case ENXIO : return 0 ;
     14     case ENOENT :
     15     case ENOTDIR :
     16     case EISDIR : return -2 ;
     17     default : return -1 ;
     18   }
     19   if (ndelay_off(fd) == -1) return -1 ;
     20   if (datalen && fd_write(fd, data, datalen) == -1)
     21   {
     22     fd_close(fd) ;
     23     return -1 ;
     24   }
     25   fd_close(fd) ;
     26   return 1 ;
     27 }