blob: 49400710a57dae28cc3b72617a6fca8e30cb2341 (
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
|
/* ISC license. */
#include <string.h>
#include <errno.h>
#include <skalibs/djbunix.h>
#include <s6/s6-supervise.h>
int s6_svc_ok (char const *dir)
{
int r ;
int e = errno ;
int fd ;
size_t dirlen = strlen(dir) ;
char fn[dirlen + 6 + sizeof(S6_SUPERVISE_CTLDIR)] ;
memcpy(fn, dir, dirlen) ;
memcpy(fn + dirlen, "/" S6_SUPERVISE_CTLDIR "/lock", 6 + sizeof(S6_SUPERVISE_CTLDIR)) ;
fd = open_read(fn) ;
if (fd < 0) return errno == ENOENT ? (errno = e, 0) : -1 ;
r = fd_islocked(fd) ;
fd_close(fd) ;
return r ;
}
|