summaryrefslogtreecommitdiff
path: root/src/libs6rc/s6rc_servicedir_block.c
blob: d01481baf4d4066d24a24253406a5e2203e99021 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* ISC license. */

#include <errno.h>
#include <unistd.h>
#include <skalibs/bytestr.h>
#include <skalibs/djbunix.h>
#include <s6/s6-supervise.h>
#include <s6-rc/s6rc-servicedir.h>

int s6rc_servicedir_block (char const *dir)
{
  unsigned int dirlen = str_len(dir) ;
  s6_svstatus_t status ;
  char fn[dirlen + 6] ;
  if (!s6_svstatus_read(dir, &status)) return -1 ;
  byte_copy(fn, dirlen, dir) ;
  byte_copy(fn + dirlen, 6, "/down") ;
  if (!touch(fn)) return -1 ;
  if (s6_svc_writectl(dir, S6_SUPERVISE_CTLDIR, "O", 1) < 0)
  {
    register int e = errno ;
    unlink(fn) ;
    errno = e ;
    return -1 ;
  }
  return status.flagwantup ;
}