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

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

void s6rc_servicedir_unsupervise (char const *live, char const *name, int keepsupervisor)
{
  unsigned int namelen = str_len(name) ;
  unsigned int livelen = str_len(live) ;
  char fn[livelen + 14 + namelen] ;
  byte_copy(fn, livelen, live) ;
  byte_copy(fn + livelen, 9, "/scandir/") ;
  byte_copy(fn + livelen + 9, namelen + 1, name) ;
  unlink(fn) ;
  if (!keepsupervisor)
  {
    byte_copy(fn + livelen + 1, 12, "servicedirs/") ;
    byte_copy(fn + livelen + 13, namelen + 1, name) ;
    s6_svc_writectl(fn, S6_SUPERVISE_CTLDIR, "x", 1) ;
  }
}