summaryrefslogtreecommitdiff
path: root/src/libs6
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-09-01 23:59:39 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-09-01 23:59:39 +0000
commit405117d42e6222c20e066e67487e87da0d8cf271 (patch)
tree920bf483df65395fcaf5be39f4640cd3d1d555b7 /src/libs6
parent8fd7d96ea5a4dd6be8a1c7d67a740df8b5148a79 (diff)
downloads6-405117d42e6222c20e066e67487e87da0d8cf271.tar.xz
add s6_svc_ok in libs6, refactor s6-svok
Diffstat (limited to 'src/libs6')
-rw-r--r--src/libs6/deps-lib/s61
-rw-r--r--src/libs6/s6_svc_ok.c25
2 files changed, 26 insertions, 0 deletions
diff --git a/src/libs6/deps-lib/s6 b/src/libs6/deps-lib/s6
index 23ca024..65062e1 100644
--- a/src/libs6/deps-lib/s6
+++ b/src/libs6/deps-lib/s6
@@ -25,6 +25,7 @@ s6_accessrules_uidgid_cdb.o
s6_accessrules_uidgid_fs.o
s6_supervise_lock.o
s6_supervise_lock_mode.o
+s6_svc_ok.o
s6_svc_write.o
s6_svc_writectl.o
s6_svstatus_pack.o
diff --git a/src/libs6/s6_svc_ok.c b/src/libs6/s6_svc_ok.c
new file mode 100644
index 0000000..37c317c
--- /dev/null
+++ b/src/libs6/s6_svc_ok.c
@@ -0,0 +1,25 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/djbunix.h>
+#include <s6/s6-supervise.h>
+
+int s6_svc_ok (char const *dir)
+{
+ int fd ;
+ unsigned int dirlen = str_len(dir) ;
+ char fn[dirlen + 9 + sizeof(S6_SUPERVISE_CTLDIR)] ;
+ byte_copy(fn, dirlen, dir) ;
+ fn[dirlen] = '/' ;
+ byte_copy(fn + dirlen + 1, sizeof(S6_SUPERVISE_CTLDIR) - 1, S6_SUPERVISE_CTLDIR) ;
+ byte_copy(fn + dirlen + sizeof(S6_SUPERVISE_CTLDIR), 9, "/control") ;
+ fd = open_write(fn) ;
+ if (fd < 0)
+ {
+ if ((errno == ENXIO) || (errno == ENOENT)) return 0 ;
+ else return -1 ;
+ }
+ fd_close(fd) ;
+ return 1 ;
+}