diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2020-12-07 17:55:23 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2020-12-07 17:55:23 +0000 |
commit | 0e7b69f1af91ccf288f3e1fd29ea7c65b7f6f986 (patch) | |
tree | 6ad1fb5b87db3d17ed40c30ac9ea6d980fb3c6b0 /src/libs6rc | |
parent | 79cb9644f99f056641f4c145da6e7ca63b333b80 (diff) | |
download | s6-rc-0e7b69f1af91ccf288f3e1fd29ea7c65b7f6f986.tar.xz |
Prepare for 0.5.2.1; build against new skalibs/execline/s6
Diffstat (limited to 'src/libs6rc')
-rw-r--r-- | src/libs6rc/s6rc_livedir_create.c | 4 | ||||
-rw-r--r-- | src/libs6rc/s6rc_lock.c | 22 | ||||
-rw-r--r-- | src/libs6rc/s6rc_servicedir_block.c | 3 | ||||
-rw-r--r-- | src/libs6rc/s6rc_servicedir_copy_offline.c | 9 | ||||
-rw-r--r-- | src/libs6rc/s6rc_servicedir_copy_online.c | 9 | ||||
-rw-r--r-- | src/libs6rc/s6rc_servicedir_internal.c | 4 | ||||
-rw-r--r-- | src/libs6rc/s6rc_servicedir_manage.c | 110 | ||||
-rw-r--r-- | src/libs6rc/s6rc_servicedir_unsupervise.c | 26 |
8 files changed, 61 insertions, 126 deletions
diff --git a/src/libs6rc/s6rc_livedir_create.c b/src/libs6rc/s6rc_livedir_create.c index fd23a07..bd44bd6 100644 --- a/src/libs6rc/s6rc_livedir_create.c +++ b/src/libs6rc/s6rc_livedir_create.c @@ -10,7 +10,7 @@ #include <skalibs/djbunix.h> #include <s6-rc/s6rc-utils.h> -int s6rc_livedir_create (stralloc *sa, char const *live, char const *suffix, char const *scandir, char const *prefix, char const *compiled, unsigned char const *state, unsigned int statelen, size_t *dirlen) +int s6rc_livedir_create (stralloc *sa, char const *live, char const *suffix, char const *scdir, char const *prefix, char const *compiled, unsigned char const *state, unsigned int statelen, size_t *dirlen) { size_t newlen, ddirlen ; size_t sabase = sa->len ; @@ -28,7 +28,7 @@ int s6rc_livedir_create (stralloc *sa, char const *live, char const *suffix, cha strcpy(sa->s + newlen, "compiled") ; if (symlink(compiled, sa->s + sabase) < 0) goto delerr ; strcpy(sa->s + newlen, "scandir") ; - if (symlink(scandir, sa->s + sabase) < 0) goto delerr ; + if (symlink(scdir, sa->s + sabase) < 0) goto delerr ; strcpy(sa->s + newlen, "prefix") ; if (!openwritenclose_unsafe(sa->s + sabase, prefix, strlen(prefix))) goto delerr ; strcpy(sa->s + newlen, "state") ; diff --git a/src/libs6rc/s6rc_lock.c b/src/libs6rc/s6rc_lock.c index d3ae2b5..e879fcc 100644 --- a/src/libs6rc/s6rc_lock.c +++ b/src/libs6rc/s6rc_lock.c @@ -2,18 +2,10 @@ #include <string.h> #include <errno.h> -#include <skalibs/djbunix.h> -#include <s6-rc/s6rc-utils.h> -static inline int lockex (int fd, int blocking) -{ - return blocking ? lock_ex(fd) : lock_exnb(fd) ; -} +#include <skalibs/djbunix.h> -static inline int locksh (int fd, int blocking) -{ - return blocking ? lock_sh(fd) : lock_shnb(fd) ; -} +#include <s6-rc/s6rc-utils.h> int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int cwhat, int *ccfd, int blocking) { @@ -21,6 +13,7 @@ int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int if (lwhat) { + int r ; size_t llen = strlen(live) ; char lfn[llen + 6] ; memcpy(lfn, live, llen) ; @@ -28,7 +21,9 @@ int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int lfd = open_create(lfn) ; if (lfd < 0) return 0 ; if (coe(lfd) < 0) goto lerr ; - if ((lwhat > 1 ? lockex(lfd, blocking) : locksh(lfd, blocking)) < 0) goto lerr ; + r = fd_lock(lfd, lwhat > 1, !blocking) ; + if (!r) errno = EBUSY ; + if (r < 1) goto lerr ; } if (cwhat) @@ -43,8 +38,11 @@ int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int else cfd = -errno ; else { + int r ; if (coe(cfd) < 0) goto cerr ; - if ((cwhat > 1 ? lockex(cfd, blocking) : locksh(cfd, blocking)) < 0) goto cerr ; + r = fd_lock(cfd, cwhat > 1, !blocking) ; + if (!r) errno = EBUSY ; + if (r < 1) goto cerr ; } } diff --git a/src/libs6rc/s6rc_servicedir_block.c b/src/libs6rc/s6rc_servicedir_block.c index bfa6440..9038342 100644 --- a/src/libs6rc/s6rc_servicedir_block.c +++ b/src/libs6rc/s6rc_servicedir_block.c @@ -2,9 +2,12 @@ #include <string.h> #include <unistd.h> + #include <skalibs/posixplz.h> #include <skalibs/djbunix.h> + #include <s6/s6-supervise.h> + #include <s6-rc/s6rc-servicedir.h> int s6rc_servicedir_block (char const *dir) diff --git a/src/libs6rc/s6rc_servicedir_copy_offline.c b/src/libs6rc/s6rc_servicedir_copy_offline.c index 6581a4f..b517536 100644 --- a/src/libs6rc/s6rc_servicedir_copy_offline.c +++ b/src/libs6rc/s6rc_servicedir_copy_offline.c @@ -2,16 +2,17 @@ #include <sys/stat.h> #include <errno.h> + #include "s6rc-servicedir-internal.h" #include <s6-rc/s6rc-servicedir.h> int s6rc_servicedir_copy_offline (char const *src, char const *dst) { s6rc_servicedir_desc_t const *p = s6rc_servicedir_file_list ; - if (mkdir(dst, 0755) < 0) - { - if (errno != EEXIST) return 0 ; - } + mode_t m = umask(0) ; + int r = mkdir(dst, 0755) ; + umask(m) ; + if (r < 0 && errno != EEXIST) return 0 ; for (; p->name ; p++) if (!s6rc_servicedir_copy_one(src, dst, p)) return 0 ; return 1 ; diff --git a/src/libs6rc/s6rc_servicedir_copy_online.c b/src/libs6rc/s6rc_servicedir_copy_online.c index e676d5a..5e84079 100644 --- a/src/libs6rc/s6rc_servicedir_copy_online.c +++ b/src/libs6rc/s6rc_servicedir_copy_online.c @@ -5,7 +5,9 @@ #include <errno.h> #include <unistd.h> #include <stdio.h> + #include <skalibs/djbunix.h> + #include <s6-rc/s6rc-utils.h> #include "s6rc-servicedir-internal.h" #include <s6-rc/s6rc-servicedir.h> @@ -27,7 +29,12 @@ int s6rc_servicedir_copy_online (char const *src, char const *dst) memcpy(oldfn, dst, dstlen) ; memcpy(oldfn + dstlen, "/old", 5) ; if (rm_rf(oldfn) < 0 && errno != ENOENT) return 0 ; - if (mkdir(oldfn, 0755) < 0) return 0 ; + { + mode_t m = umask(0) ; + int r = mkdir(oldfn, 0755) ; + umask(m) ; + if (r < 0) return 0 ; + } dstfn[dstlen] = '/' ; oldfn[dstlen + 4] = '/' ; wantup = s6rc_servicedir_block(dst) ; diff --git a/src/libs6rc/s6rc_servicedir_internal.c b/src/libs6rc/s6rc_servicedir_internal.c index b70061f..f84b6fb 100644 --- a/src/libs6rc/s6rc_servicedir_internal.c +++ b/src/libs6rc/s6rc_servicedir_internal.c @@ -3,8 +3,11 @@ #include <string.h> #include <errno.h> #include <unistd.h> + +#include <skalibs/posixplz.h> #include <skalibs/types.h> #include <skalibs/djbunix.h> + #include <s6-rc/s6rc-utils.h> #include "s6rc-servicedir-internal.h" @@ -14,7 +17,6 @@ static s6rc_servicedir_desc_t const svdir_file_list[] = { .name = "finish.user", .type = FILETYPE_NORMAL, .options = SVFILE_EXECUTABLE }, { .name = "run", .type = FILETYPE_NORMAL, .options = SVFILE_EXECUTABLE | SVFILE_MANDATORY | SVFILE_ATOMIC }, { .name = "run.user", .type = FILETYPE_NORMAL, .options = SVFILE_EXECUTABLE }, - { .name = "nosetsid", .type = FILETYPE_EMPTY, .options = 0 }, { .name = "notification-fd", .type = FILETYPE_UINT, .options = 0 }, { .name = "timeout-kill", .type = FILETYPE_UINT, .options = 0 }, { .name = "timeout-finish", .type = FILETYPE_UINT, .options = 0 }, diff --git a/src/libs6rc/s6rc_servicedir_manage.c b/src/libs6rc/s6rc_servicedir_manage.c index 5449f35..e11e4e4 100644 --- a/src/libs6rc/s6rc_servicedir_manage.c +++ b/src/libs6rc/s6rc_servicedir_manage.c @@ -1,45 +1,26 @@ /* ISC license. */ #include <string.h> -#include <stdint.h> -#include <unistd.h> #include <errno.h> + #include <skalibs/direntry.h> -#include <skalibs/djbunix.h> #include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> + #include <s6/s6-supervise.h> -#include <s6/ftrigr.h> -#include <s6/ftrigw.h> -#include <s6-rc/s6rc-servicedir.h> -static inline void rollback (char const *live, char const *prefix, char const *s, size_t len) -{ - while (len) - { - size_t n = strlen(s) + 1 ; - s6rc_servicedir_unsupervise(live, prefix, s, 0) ; - s += n ; len -= n ; - } -} +#include <s6-rc/s6rc-servicedir.h> int s6rc_servicedir_manage (char const *live, char const *prefix, tain_t const *deadline, tain_t *stamp) { - ftrigr_t a = FTRIGR_ZERO ; - stralloc newnames = STRALLOC_ZERO ; - genalloc ids = GENALLOC_ZERO ; /* uint16_t */ - gid_t gid = getgid() ; + stralloc names = STRALLOC_ZERO ; size_t livelen = strlen(live) ; - size_t prefixlen = strlen(prefix) ; - int fdlock ; - int ok = 1 ; + size_t n = 0 ; DIR *dir ; char dirfn[livelen + 13] ; - if (!ftrigr_startf(&a, deadline, stamp)) return 0 ; memcpy(dirfn, live, livelen) ; memcpy(dirfn + livelen, "/servicedirs", 13) ; dir = opendir(dirfn) ; - if (!dir) goto closederr ; + if (!dir) return -1 ; for (;;) { direntry *d ; @@ -47,77 +28,28 @@ int s6rc_servicedir_manage (char const *live, char const *prefix, tain_t const * d = readdir(dir) ; if (!d) break ; if (d->d_name[0] == '.') continue ; - { - size_t len = strlen(d->d_name) ; - int r ; - uint16_t id ; - char srcfn[livelen + 20 + len] ; - char dstfn[livelen + 10 + prefixlen + len] ; - memcpy(srcfn, dirfn, livelen + 12) ; - srcfn[livelen + 12] = '/' ; - memcpy(srcfn + livelen + 13, d->d_name, len + 1) ; - fdlock = s6_svc_lock_take(srcfn) ; - if (fdlock < 0) goto err ; - r = s6_svc_ok(srcfn) ; - if (r < 0) goto erru ; - if (!r) - { - memcpy(srcfn + livelen + 13 + len, "/down", 6) ; - if (!touch(srcfn)) goto erru ; - memcpy(srcfn + livelen + 14 + len, "event", 6) ; - if (!ftrigw_fifodir_make(srcfn, gid, 0)) goto erru ; - id = ftrigr_subscribe(&a, srcfn, "s", 0, deadline, stamp) ; - if (!id) goto erru ; - s6_svc_lock_release(fdlock) ; - if (!genalloc_append(uint16_t, &ids, &id)) goto err ; - srcfn[livelen + 13 + len] = 0 ; - } - else s6_svc_lock_release(fdlock) ; - memcpy(dstfn, live, livelen) ; - memcpy(dstfn + livelen, "/scandir/", 9) ; - memcpy(dstfn + livelen + 9, prefix, prefixlen) ; - memcpy(dstfn + livelen + 9 + prefixlen, d->d_name, len + 1) ; - if (symlink(srcfn, dstfn) < 0) - { - if (!r || errno != EEXIST) goto err ; - } - else if (!r) - { - if (!stralloc_catb(&newnames, d->d_name, len + 1)) - { - s6rc_servicedir_unsupervise(live, prefix, d->d_name, 0) ; - goto err ; - } - } - } + if (!stralloc_catb(&names, dirfn, livelen + 12) + || !stralloc_catb(&names, "/", 1) + || !stralloc_cats(&names, d->d_name) + || !stralloc_0(&names)) goto err ; + n++ ; } if (errno) goto err ; dir_close(dir) ; + if (!n) return 0 ; + memcpy(dirfn + livelen + 1, "scandir", 8) ; { - char scanfn[livelen + 9] ; + char const *p = names.s ; + char const *servicedirs[n] ; int r ; - memcpy(scanfn, live, livelen) ; - memcpy(scanfn + livelen, "/scandir", 9) ; - r = s6_svc_writectl(scanfn, S6_SVSCAN_CTLDIR, "a", 1) ; - if (r < 0) goto closederr ; - if (!r) ok = 3 ; - else if (ftrigr_wait_and(&a, genalloc_s(uint16_t, &ids), genalloc_len(uint16_t, &ids), deadline, stamp) < 0) - goto closederr ; + for (size_t i = 0 ; i < n ; p += strlen(p) + 1) servicedirs[i++] = p ; + r = s6_supervise_link(dirfn, servicedirs, n, prefix, 0, deadline, stamp) ; + stralloc_free(&names) ; + return r ; } - ftrigr_end(&a) ; - genalloc_free(uint16_t, &ids) ; - stralloc_free(&newnames) ; - return ok ; - - erru: - s6_svc_lock_release(fdlock) ; err: dir_close(dir) ; - closederr: - ftrigr_end(&a) ; - genalloc_free(uint16_t, &ids) ; - rollback(live, prefix, newnames.s, newnames.len) ; - stralloc_free(&newnames) ; - return 0 ; + stralloc_free(&names) ; + return -1 ; } diff --git a/src/libs6rc/s6rc_servicedir_unsupervise.c b/src/libs6rc/s6rc_servicedir_unsupervise.c index 2d15a70..44cc7b9 100644 --- a/src/libs6rc/s6rc_servicedir_unsupervise.c +++ b/src/libs6rc/s6rc_servicedir_unsupervise.c @@ -1,10 +1,9 @@ /* ISC license. */ -#include <errno.h> #include <string.h> -#include <unistd.h> -#include <skalibs/posixplz.h> + #include <s6/s6-supervise.h> + #include <s6-rc/s6rc-servicedir.h> void s6rc_servicedir_unsupervise (char const *live, char const *prefix, char const *name, int keepsupervisor) @@ -12,18 +11,11 @@ void s6rc_servicedir_unsupervise (char const *live, char const *prefix, char con size_t livelen = strlen(live) ; size_t prefixlen = strlen(prefix) ; size_t namelen = strlen(name) ; - char fn[livelen + 14 + prefixlen + namelen] ; - memcpy(fn, live, livelen) ; - memcpy(fn + livelen, "/scandir/", 9) ; - memcpy(fn + livelen + 9, prefix, prefixlen) ; - memcpy(fn + livelen + 9 + prefixlen, name, namelen + 1) ; - unlink_void(fn) ; - if (!keepsupervisor) - { - int e = errno ; - memcpy(fn + livelen + 1, "servicedirs/", 12) ; - memcpy(fn + livelen + 13, name, namelen + 1) ; - s6_svc_writectl(fn, S6_SUPERVISE_CTLDIR, "x", 1) ; - errno = e ; - } + char scdir[livelen + 9] ; + char fn[prefixlen + namelen + 1] ; + memcpy(scdir, live, livelen) ; + memcpy(scdir + livelen, "/scandir", 9) ; + memcpy(fn, prefix, prefixlen) ; + memcpy(fn + prefixlen, name, namelen + 1) ; + s6_supervise_unlink(scdir, fn, keepsupervisor ? 0 : 3) ; } |