From bba745f906d2a29ec0f619f61c746ad8cbdf5621 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 10 Dec 2020 18:29:11 +0000 Subject: Add the possibility of down files to s6_supervise_link --- src/libs6/s6_supervise_link.c | 30 ++++++++++++++++++++---------- src/libs6/s6_supervise_unlink.c | 8 ++++++-- 2 files changed, 26 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/libs6/s6_supervise_link.c b/src/libs6/s6_supervise_link.c index 511cce1..491a2aa 100644 --- a/src/libs6/s6_supervise_link.c +++ b/src/libs6/s6_supervise_link.c @@ -29,6 +29,21 @@ static inline void do_unlink (char const *scdir, char const *prefix, size_t pref } } +static uint16_t registerit (ftrigr_t *a, char *fn, size_t len, gid_t gid, uint32_t options, tain_t const *deadline, tain_t *stamp) +{ + if (options & 4) + { + int fd ; + memcpy(fn + len, "/down", 6) ; + fd = open_trunc(fn) ; + if (fd < 0) return 0 ; + fd_close(fd) ; + } + memcpy(fn + len, "/" S6_SUPERVISE_EVENTDIR, 1 + sizeof(S6_SUPERVISE_EVENTDIR)) ; + if (!ftrigw_fifodir_make(fn, gid, options & 1)) return 0 ; + return ftrigr_subscribe(a, fn, "s", 0, deadline, stamp) ; +} + int s6_supervise_link (char const *scdir, char const *const *servicedirs, size_t n, char const *prefix, uint32_t options, tain_t const *deadline, tain_t *stamp) { size_t maxlen = 0 ; @@ -81,7 +96,7 @@ int s6_supervise_link (char const *scdir, char const *const *servicedirs, size_t int r ; uint16_t ids[ntotal] ; char lname[scdirlen + prefixlen + maxlen + 2] ; - char fn[maxlen + 5 + sizeof(S6_SUPERVISE_EVENTDIR)] ; + char fn[maxlen + 5 + (sizeof(S6_SUPERVISE_EVENTDIR) > 5 ? sizeof(S6_SUPERVISE_EVENTDIR) : 5)] ; if (!ftrigr_startf(&a, deadline, stamp)) return -1 ; memcpy(lname, scdir, scdirlen) ; lname[scdirlen] = '/' ; @@ -91,17 +106,12 @@ int s6_supervise_link (char const *scdir, char const *const *servicedirs, size_t char *p ; size_t len = strlen(servicedirs[i]) ; memcpy(fn, servicedirs[i], len) ; - fn[len] = '/' ; - memcpy(fn + len + 1, S6_SUPERVISE_EVENTDIR, sizeof(S6_SUPERVISE_EVENTDIR)) ; - if (!ftrigw_fifodir_make(fn, gid, options & 1)) goto err ; - ids[m] = ftrigr_subscribe(&a, fn, "s", 0, deadline, stamp) ; + ids[m] = registerit(&a, fn, len, gid, options, deadline, stamp) ; if (!ids[m++]) goto err ; if (bitarray_peek(logged, i)) { - memcpy(fn + len + 1, "log/", 4) ; - memcpy(fn + len + 5, S6_SUPERVISE_EVENTDIR, sizeof(S6_SUPERVISE_EVENTDIR)) ; - if (!ftrigw_fifodir_make(fn, gid, options & 1)) goto err ; - ids[m] = ftrigr_subscribe(&a, fn, "s", 0, deadline, stamp) ; + memcpy(fn + len, "/log", 4) ; + ids[m] = registerit(&a, fn, len + 4, gid, options, deadline, stamp) ; if (!ids[m++]) goto err ; } fn[len] = 0 ; @@ -129,7 +139,7 @@ int s6_supervise_link (char const *scdir, char const *const *servicedirs, size_t stralloc_free(&rpsa) ; errsa: ftrigr_end(&a) ; - do_unlink(scdir, prefix, prefixlen, maxlen, lnames.s, lnames.len, killopts) ; + do_unlink(scdir, prefix, prefixlen, maxlen, lnames.s, lnames.len, killopts | (options & 4)) ; stralloc_free(&lnames) ; return -1 ; } diff --git a/src/libs6/s6_supervise_unlink.c b/src/libs6/s6_supervise_unlink.c index 36d765b..2e5a9ec 100644 --- a/src/libs6/s6_supervise_unlink.c +++ b/src/libs6/s6_supervise_unlink.c @@ -27,10 +27,14 @@ void s6_supervise_unlink (char const *scdir, char const *name, uint32_t options) memcpy(fn, scdir, scdirlen) ; fn[scdirlen] = '/' ; memcpy(fn + scdirlen + 1, name, namelen) ; + if (options & 4) + { + memcpy(fn + scdirlen + 1 + namelen, "/down", 6) ; + unlink_void(fn) ; + } if (options & 1) { - fn[scdirlen + 1 + namelen] = '/' ; - memcpy(fn + scdirlen + 1 + namelen + 1, S6_SUPERVISE_CTLDIR, sizeof(S6_SUPERVISE_CTLDIR) - 1) ; + memcpy(fn + scdirlen + 1 + namelen, "/" S6_SUPERVISE_CTLDIR, sizeof(S6_SUPERVISE_CTLDIR)) ; memcpy(fn + scdirlen + 1 + namelen + sizeof(S6_SUPERVISE_CTLDIR), "/control", 9) ; fd = open_write(fn) ; } -- cgit v1.2.3