s6

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

s6_svc_ok.c (534B)


      1 /* ISC license. */
      2 
      3 #include <string.h>
      4 #include <errno.h>
      5 
      6 #include <skalibs/djbunix.h>
      7 
      8 #include <s6/supervise.h>
      9 
     10 int s6_svc_ok (char const *dir)
     11 {
     12   int r ;
     13   int e = errno ;
     14   int fd ;
     15   size_t dirlen = strlen(dir) ;
     16   char fn[dirlen + 6 + sizeof(S6_SUPERVISE_CTLDIR)] ;
     17   memcpy(fn, dir, dirlen) ;
     18   memcpy(fn + dirlen, "/" S6_SUPERVISE_CTLDIR "/lock", 6 + sizeof(S6_SUPERVISE_CTLDIR)) ;
     19   fd = open_read(fn) ;
     20   if (fd < 0) return errno == ENOENT ? (errno = e, 0) : -1 ;
     21   r = fd_islocked(fd) ;
     22   fd_close(fd) ;
     23   return r ;
     24 }