s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

commit 26067f0ad8c5e2f57c81d0bef8d126d50b112fb6
parent 7d4f117642a8c026cb708e48506694c6b8090f1e
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Fri, 18 Dec 2020 23:31:41 +0000

 More fixes to s6_supervise_link

Diffstat:
Msrc/libs6/s6_supervise_link.c | 27+++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/libs6/s6_supervise_link.c b/src/libs6/s6_supervise_link.c @@ -101,35 +101,38 @@ int s6_supervise_link (char const *scdir, char const *const *servicedirs, size_t memcpy(lname, scdir, scdirlen) ; lname[scdirlen] = '/' ; memcpy(lname + scdirlen + 1, prefix, prefixlen) ; - for (i = 0 ; i < n ; i++) if (!bitarray_peek(locked, i)) + for (i = 0 ; i < n ; i++) { char *p ; + char const *src ; size_t len = strlen(servicedirs[i]) ; + int h = bitarray_peek(locked, i) ; memcpy(fn, servicedirs[i], len) ; - ids[m] = registerit(&a, fn, len, gid, options, deadline, stamp) ; - if (!ids[m++]) goto err ; - if (bitarray_peek(logged, i)) + if (!h) { - memcpy(fn + len, "/log", 4) ; - ids[m] = registerit(&a, fn, len + 4, gid, options, 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, "/log", 4) ; + ids[m] = registerit(&a, fn, len + 4, gid, options, deadline, stamp) ; + if (!ids[m++]) goto err ; + } } fn[len] = 0 ; p = basename(fn) ; len = strlen(p) ; memcpy(lname + scdirlen + 1 + prefixlen, p, len + 1) ; lstart = lnames.len ; - if (!stralloc_catb(&lnames, p, len + 1)) goto err ; - if (servicedirs[i][0] == '/') - { - if (symlink(servicedirs[i], lname) < 0) goto errl ; - } + if (!h && !stralloc_catb(&lnames, p, len + 1)) goto err ; + if (servicedirs[i][0] == '/') src = servicedirs[i] ; else { rpsa.len = 0 ; if (sarealpath(&rpsa, servicedirs[i]) < 0 || !stralloc_0(&rpsa)) goto errl ; - if (symlink(rpsa.s, lname) < 0) goto errl ; + src = rpsa.s ; } + if (symlink(src, lname) < 0 && (!h || errno != EEXIST)) goto errl ; } stralloc_free(&rpsa) ; r = s6_svc_writectl(scdir, S6_SVSCAN_CTLDIR, "a", 1) ;