summaryrefslogtreecommitdiff
path: root/src/libs6
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2018-03-20 14:52:26 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2018-03-20 14:52:26 +0000
commit26c5fee82736e56cff3d114ff9d6e3969d1ce061 (patch)
treea43283438dc8d22b339cda86b0d80c58ef86bf4d /src/libs6
parent1747a0f5142f0c36a61b37786368f05bcb3060f3 (diff)
downloads6-26c5fee82736e56cff3d114ff9d6e3969d1ce061.tar.xz
Add death tally support to s6-supervise, throttling support to s6_svstatus_t
Diffstat (limited to 'src/libs6')
-rw-r--r--src/libs6/deps-lib/s64
-rw-r--r--src/libs6/s6_dtally_pack.c11
-rw-r--r--src/libs6/s6_dtally_read.c51
-rw-r--r--src/libs6/s6_dtally_unpack.c11
-rw-r--r--src/libs6/s6_dtally_write.c16
-rw-r--r--src/libs6/s6_svstatus_pack.c3
-rw-r--r--src/libs6/s6_svstatus_unpack.c1
7 files changed, 96 insertions, 1 deletions
diff --git a/src/libs6/deps-lib/s6 b/src/libs6/deps-lib/s6
index 47a3335..65612cc 100644
--- a/src/libs6/deps-lib/s6
+++ b/src/libs6/deps-lib/s6
@@ -28,6 +28,10 @@ s6_accessrules_uidgid_cdb.o
s6_accessrules_uidgid_fs.o
s6_supervise_lock.o
s6_supervise_lock_mode.o
+s6_dtally_pack.o
+s6_dtally_unpack.o
+s6_dtally_read.o
+s6_dtally_write.o
s6_svc_lock_take.o
s6_svc_lock_release.o
s6_svc_ok.o
diff --git a/src/libs6/s6_dtally_pack.c b/src/libs6/s6_dtally_pack.c
new file mode 100644
index 0000000..1608e78
--- /dev/null
+++ b/src/libs6/s6_dtally_pack.c
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#include <skalibs/tai.h>
+#include <s6/s6-supervise.h>
+
+void s6_dtally_pack (char *pack, s6_dtally_t const *d)
+{
+ tain_pack(pack, &d->stamp) ;
+ pack[TAIN_PACK] = d->exitcode ;
+ pack[TAIN_PACK + 1] = d->sig ;
+}
diff --git a/src/libs6/s6_dtally_read.c b/src/libs6/s6_dtally_read.c
new file mode 100644
index 0000000..3906b93
--- /dev/null
+++ b/src/libs6/s6_dtally_read.c
@@ -0,0 +1,51 @@
+/* ISC license. */
+
+#include <sys/stat.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <skalibs/allreadwrite.h>
+#include <skalibs/tai.h>
+#include <skalibs/djbunix.h>
+#include <s6/s6-supervise.h>
+
+static int truncit (char const *s)
+{
+ int fd = open_trunc(s) ;
+ if (fd < 0) return -1 ;
+ fd_close(fd) ;
+ return 0 ;
+}
+
+ssize_t s6_dtally_read (char const *sv, s6_dtally_t *tab, size_t max)
+{
+ size_t len = strlen(sv) ;
+ size_t n ;
+ int fd ;
+ struct stat st ;
+ char fn[len + sizeof(S6_DTALLY_FILENAME) + 1] ;
+ memcpy(fn, sv, len) ;
+ memcpy(fn + len, "/" S6_DTALLY_FILENAME, sizeof(S6_DTALLY_FILENAME) + 1) ;
+ fd = open_read(fn) ;
+ if (fd < 0) return errno == ENOENT ? truncit(fn) : -1 ;
+ if (fstat(fd, &st) < 0) goto err ;
+ if (st.st_size % S6_DTALLY_PACK)
+ {
+ fd_close(fd) ;
+ return truncit(fn) ;
+ }
+ n = st.st_size / S6_DTALLY_PACK ;
+ if (n > max) n = max ;
+ {
+ char tmp[n ? S6_DTALLY_PACK * n : 1] ;
+ if (lseek(fd, -(off_t)(n * S6_DTALLY_PACK), SEEK_END) < 0) goto err ;
+ if (allread(fd, tmp, n * S6_DTALLY_PACK) < n * S6_DTALLY_PACK) goto err ;
+ fd_close(fd) ;
+ for (size_t i = 0 ; i < n ; i++) s6_dtally_unpack(tmp + i * S6_DTALLY_PACK, tab + i) ;
+ }
+ return n ;
+
+ err:
+ fd_close(fd) ;
+ return -1 ;
+}
diff --git a/src/libs6/s6_dtally_unpack.c b/src/libs6/s6_dtally_unpack.c
new file mode 100644
index 0000000..8fca787
--- /dev/null
+++ b/src/libs6/s6_dtally_unpack.c
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#include <skalibs/tai.h>
+#include <s6/s6-supervise.h>
+
+void s6_dtally_unpack (char const *pack, s6_dtally_t *d)
+{
+ tain_unpack(pack, &d->stamp) ;
+ d->exitcode = pack[TAIN_PACK] ;
+ d->sig = pack[TAIN_PACK + 1] ;
+}
diff --git a/src/libs6/s6_dtally_write.c b/src/libs6/s6_dtally_write.c
new file mode 100644
index 0000000..785376a
--- /dev/null
+++ b/src/libs6/s6_dtally_write.c
@@ -0,0 +1,16 @@
+/* ISC license. */
+
+#include <string.h>
+#include <skalibs/djbunix.h>
+#include <s6/s6-supervise.h>
+
+int s6_dtally_write (char const *sv, s6_dtally_t const *tab, size_t n)
+{
+ size_t len = strlen(sv) ;
+ char fn[len + sizeof(S6_DTALLY_FILENAME) + 1] ;
+ char tmp[n ? S6_DTALLY_PACK * n : 1] ;
+ memcpy(fn, sv, len) ;
+ memcpy(fn + len, "/" S6_DTALLY_FILENAME, sizeof(S6_DTALLY_FILENAME) + 1) ;
+ for (size_t i = 0 ; i < n ; i++) s6_dtally_pack(tmp + i * S6_DTALLY_PACK, tab + i) ;
+ return openwritenclose_suffix(fn, tmp, n * S6_DTALLY_PACK, ".new") ;
+}
diff --git a/src/libs6/s6_svstatus_pack.c b/src/libs6/s6_svstatus_pack.c
index fbce109..ef2d5bd 100644
--- a/src/libs6/s6_svstatus_pack.c
+++ b/src/libs6/s6_svstatus_pack.c
@@ -17,5 +17,6 @@ void s6_svstatus_pack (char *pack, s6_svstatus_t const *sv)
(sv->flagfinishing << 1) |
(sv->flagwant << 2) |
(sv->flagwantup << 3) |
- (sv->flagready << 4) ;
+ (sv->flagready << 4) |
+ (sv->flagthrottled << 5) ;
}
diff --git a/src/libs6/s6_svstatus_unpack.c b/src/libs6/s6_svstatus_unpack.c
index dc358d3..b641c8c 100644
--- a/src/libs6/s6_svstatus_unpack.c
+++ b/src/libs6/s6_svstatus_unpack.c
@@ -21,4 +21,5 @@ void s6_svstatus_unpack (char const *pack, s6_svstatus_t *sv)
sv->flagwant = !!(pack[34] & 4) ;
sv->flagwantup = !!(pack[34] & 8) ;
sv->flagready = !!(pack[34] & 16) ;
+ sv->flagthrottled = !!(pack[34] & 32) ;
}