diff options
Diffstat (limited to 'src/libs6/s6_supervise_link.c')
-rw-r--r-- | src/libs6/s6_supervise_link.c | 30 |
1 files changed, 20 insertions, 10 deletions
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 ; } |