summaryrefslogtreecommitdiff
path: root/src/libs6/s6_svc_ok.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs6/s6_svc_ok.c')
-rw-r--r--src/libs6/s6_svc_ok.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/libs6/s6_svc_ok.c b/src/libs6/s6_svc_ok.c
index 5e6aa27..4940071 100644
--- a/src/libs6/s6_svc_ok.c
+++ b/src/libs6/s6_svc_ok.c
@@ -2,24 +2,23 @@
#include <string.h>
#include <errno.h>
+
#include <skalibs/djbunix.h>
+
#include <s6/s6-supervise.h>
int s6_svc_ok (char const *dir)
{
- size_t dirlen = strlen(dir) ;
+ int r ;
+ int e = errno ;
int fd ;
- char fn[dirlen + 9 + sizeof(S6_SUPERVISE_CTLDIR)] ;
+ size_t dirlen = strlen(dir) ;
+ char fn[dirlen + 6 + sizeof(S6_SUPERVISE_CTLDIR)] ;
memcpy(fn, dir, dirlen) ;
- fn[dirlen] = '/' ;
- memcpy(fn + dirlen + 1, S6_SUPERVISE_CTLDIR, sizeof(S6_SUPERVISE_CTLDIR) - 1) ;
- memcpy(fn + dirlen + sizeof(S6_SUPERVISE_CTLDIR), "/control", 9) ;
- fd = open_write(fn) ;
- if (fd < 0)
- {
- if ((errno == ENXIO) || (errno == ENOENT)) return 0 ;
- else return -1 ;
- }
+ 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 1 ;
+ return r ;
}