s6

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

s6_supervise_link.c (910B)


      1 /* ISC license. */
      2 
      3 #include <string.h>
      4 
      5 #include <skalibs/stralloc.h>
      6 #include <skalibs/djbunix.h>
      7 
      8 #include <s6/supervise.h>
      9 
     10 int s6_supervise_link (char const *scdir, char const *const *servicedirs, size_t n, char const *prefix, uint32_t options, tain const *deadline, tain *stamp)
     11 {
     12   int r ;
     13   size_t prefixlen = strlen(prefix) ;
     14   stralloc sa = STRALLOC_ZERO ;
     15   char const *names[n ? n : 1] ;
     16   {
     17     size_t indices[n ? n : 1] ;
     18     for (size_t i = 0 ; i < n ; i++)
     19     {
     20       indices[i] = sa.len ;
     21       if (!stralloc_catb(&sa, prefix, prefixlen)
     22        || !sabasename(&sa, servicedirs[i], strlen(servicedirs[i]))
     23        || !stralloc_0(&sa)) goto err ;
     24     }
     25     for (size_t i = 0 ; i < n ; i++) names[i] = sa.s + indices[i] ;
     26   }
     27   r = s6_supervise_link_names(scdir, servicedirs, names, n, options, deadline, stamp) ;
     28   stralloc_free(&sa) ;
     29   return r ;
     30 
     31  err:
     32   stralloc_free(&sa) ;
     33   return -1 ;
     34 }