s6

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

s6_instance_chdirservice.c (765B)


      1 /* ISC license. */
      2 
      3 #include <string.h>
      4 #include <unistd.h>
      5 
      6 #include <skalibs/strerr.h>
      7 #include <skalibs/djbunix.h>
      8 
      9 #include <s6/supervise.h>
     10 
     11 void s6_instance_chdirservice (char const *s)
     12 {
     13   int fd, r ;
     14   size_t len = strlen(s) ;
     15   char fn[len + 10] ;
     16   if (!*s) strerr_dief1x(100, "invalid service path") ;
     17   memcpy(fn, s, len) ;
     18   memcpy(fn + len, "/instance", 10) ;
     19   if (chdir(fn) == -1) strerr_diefu2sys(111, "chdir to ", fn) ;
     20   fd = open_read(S6_SVSCAN_CTLDIR "/lock") ;
     21   if (fd < 0) strerr_diefu3sys(111, "open ", fn, "/" S6_SVSCAN_CTLDIR "/lock") ;
     22   r = fd_islocked(fd) ;
     23   if (r < 0) strerr_diefu3sys(111, "check lock on ", fn, "/" S6_SVSCAN_CTLDIR "/lock") ;
     24   if (!r) strerr_dief2x(1, "instanced service not running on ", s) ;
     25   fd_close(fd) ;
     26 }