From 8873c303fefaed17f6777989f929612a99675a00 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 2 Dec 2020 05:24:24 +0000 Subject: Fix build against skalibs-2.10.0.0 --- src/libs6/deps-lib/s6 | 4 -- src/libs6/s6_supervise_lock.c | 9 ---- src/libs6/s6_supervise_lock_mode.c | 85 -------------------------------------- src/libs6/s6_svc_lock_release.c | 8 ---- src/libs6/s6_svc_lock_take.c | 28 ------------- src/libs6/s6_svc_ok.c | 23 +++++------ src/libs6/s6lockd-helper.c | 17 ++++---- src/libs6/s6lockd.c | 10 ++--- 8 files changed, 25 insertions(+), 159 deletions(-) delete mode 100644 src/libs6/s6_supervise_lock.c delete mode 100644 src/libs6/s6_supervise_lock_mode.c delete mode 100644 src/libs6/s6_svc_lock_release.c delete mode 100644 src/libs6/s6_svc_lock_take.c (limited to 'src/libs6') diff --git a/src/libs6/deps-lib/s6 b/src/libs6/deps-lib/s6 index ddd86dc..d9d4341 100644 --- a/src/libs6/deps-lib/s6 +++ b/src/libs6/deps-lib/s6 @@ -31,10 +31,6 @@ s6_dtally_pack.o s6_dtally_unpack.o s6_dtally_read.o s6_dtally_write.o -s6_supervise_lock.o -s6_supervise_lock_mode.o -s6_svc_lock_take.o -s6_svc_lock_release.o s6_svc_ok.o s6_svc_write.o s6_svc_writectl.o diff --git a/src/libs6/s6_supervise_lock.c b/src/libs6/s6_supervise_lock.c deleted file mode 100644 index e241320..0000000 --- a/src/libs6/s6_supervise_lock.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ISC license. */ - -#include -#include - -int s6_supervise_lock (char const *subdir) -{ - return s6_supervise_lock_mode(subdir, S_IRWXU, S_IRUSR | S_IWUSR) ; -} diff --git a/src/libs6/s6_supervise_lock_mode.c b/src/libs6/s6_supervise_lock_mode.c deleted file mode 100644 index d807bec..0000000 --- a/src/libs6/s6_supervise_lock_mode.c +++ /dev/null @@ -1,85 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include -#include - -#include -#include - -#include - -#ifdef PATH_MAX -# define S6_PATH_MAX PATH_MAX -#else -# define S6_PATH_MAX 4096 -#endif - -int s6_supervise_lock_mode (char const *subdir, unsigned int subdirmode, unsigned int controlmode) -{ - size_t subdirlen = strlen(subdir) ; - int fdctl, fdctlw, fdlock ; - char control[subdirlen + 9] ; - char lock[subdirlen + 6] ; - memcpy(control, subdir, subdirlen) ; - memcpy(control + subdirlen, "/control", 9) ; - memcpy(lock, subdir, subdirlen) ; - memcpy(lock + subdirlen, "/lock", 6) ; - if (mkdir(subdir, (mode_t)subdirmode) == -1) - { - char buf[S6_PATH_MAX] ; - ssize_t r ; - if (errno == EEXIST) strerr_diefu2sys(111, "mkdir ", subdir) ; - r = readlink(subdir, buf, S6_PATH_MAX) ; - if (r < 0) - { - if (errno != EINVAL) - { - errno = EEXIST ; - strerr_diefu2sys(111, "mkdir ", subdir) ; - } - } - else if (r == S6_PATH_MAX) - { - errno = ENAMETOOLONG ; - strerr_diefu2sys(111, "readlink ", subdir) ; - } - else - { - buf[r] = 0 ; - if (mkdir(buf, (mode_t)subdirmode) == -1) - strerr_diefu2sys(111, "mkdir ", buf) ; - } - } - if (mkfifo(control, controlmode) < 0) - { - struct stat st ; - if (errno != EEXIST) - strerr_diefu2sys(111, "mkfifo ", control) ; - if (stat(control, &st) < 0) - strerr_diefu2sys(111, "stat ", control) ; - if (!S_ISFIFO(st.st_mode)) - strerr_diefu2x(100, control, " is not a FIFO") ; - } - fdlock = openc_create(lock) ; - if (fdlock < 0) - strerr_diefu2sys(111, "open_create ", lock) ; - if (lock_ex(fdlock) < 0) - strerr_diefu2sys(111, "lock ", lock) ; - fdctlw = openc_write(control) ; - if (fdctlw >= 0) strerr_dief1x(100, "directory already locked") ; - if (errno != ENXIO) - strerr_diefu2sys(111, "open_write ", control) ; - fdctl = openc_read(control) ; - if (fdctl < 0) - strerr_diefu2sys(111, "open_read ", control) ; - fdctlw = openc_write(control) ; - if (fdctlw < 0) - strerr_diefu2sys(111, "open_write ", control) ; - fd_close(fdlock) ; - - return fdctl ; - /* we leak fdctlw but it's coe. */ -} diff --git a/src/libs6/s6_svc_lock_release.c b/src/libs6/s6_svc_lock_release.c deleted file mode 100644 index 4a6f68d..0000000 --- a/src/libs6/s6_svc_lock_release.c +++ /dev/null @@ -1,8 +0,0 @@ -/* ISC license. */ - -#include - -void s6_svc_lock_release (int fd) -{ - fd_close(fd) ; -} diff --git a/src/libs6/s6_svc_lock_take.c b/src/libs6/s6_svc_lock_take.c deleted file mode 100644 index fcb098a..0000000 --- a/src/libs6/s6_svc_lock_take.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include -#include - - /* XXX: does not work with dangling S6_SUPERVISE_CTLDIR symlinks */ - -int s6_svc_lock_take (char const *dir) -{ - size_t dirlen = strlen(dir) ; - int fdlock ; - char lock[dirlen + sizeof(S6_SUPERVISE_CTLDIR) + 6] ; - memcpy(lock, dir, dirlen) ; - memcpy(lock + dirlen, "/" S6_SUPERVISE_CTLDIR, sizeof(S6_SUPERVISE_CTLDIR) + 1) ; - if ((mkdir(lock, S_IRWXU) < 0) && (errno != EEXIST)) return -1 ; - memcpy(lock + dirlen + sizeof(S6_SUPERVISE_CTLDIR), "/lock", 6) ; - fdlock = openc_create(lock) ; - if (fdlock < 0) return -1 ; - if (lock_ex(fdlock) < 0) - { - fd_close(fdlock) ; - return -1 ; - } - return fdlock ; -} diff --git a/src/libs6/s6_svc_ok.c b/src/libs6/s6_svc_ok.c index 5e6aa27..4940071 100644 --- a/src/libs6/s6_svc_ok.c +++ b/src/libs6/s6_svc_ok.c @@ -2,24 +2,23 @@ #include #include + #include + #include int s6_svc_ok (char const *dir) { - size_t dirlen = strlen(dir) ; + int r ; + int e = errno ; int fd ; - char fn[dirlen + 9 + sizeof(S6_SUPERVISE_CTLDIR)] ; + size_t dirlen = strlen(dir) ; + char fn[dirlen + 6 + sizeof(S6_SUPERVISE_CTLDIR)] ; memcpy(fn, dir, dirlen) ; - fn[dirlen] = '/' ; - memcpy(fn + dirlen + 1, S6_SUPERVISE_CTLDIR, sizeof(S6_SUPERVISE_CTLDIR) - 1) ; - memcpy(fn + dirlen + sizeof(S6_SUPERVISE_CTLDIR), "/control", 9) ; - fd = open_write(fn) ; - if (fd < 0) - { - if ((errno == ENXIO) || (errno == ENOENT)) return 0 ; - else return -1 ; - } + memcpy(fn + dirlen, "/" S6_SUPERVISE_CTLDIR "/lock", 6 + sizeof(S6_SUPERVISE_CTLDIR)) ; + fd = open_read(fn) ; + if (fd < 0) return errno == ENOENT ? (errno = e, 0) : -1 ; + r = fd_islocked(fd) ; fd_close(fd) ; - return 1 ; + return r ; } diff --git a/src/libs6/s6lockd-helper.c b/src/libs6/s6lockd-helper.c index 8979c67..469a417 100644 --- a/src/libs6/s6lockd-helper.c +++ b/src/libs6/s6lockd-helper.c @@ -1,24 +1,25 @@ /* ISC license. */ +#include + #include #include -#include #include #define USAGE "s6lockd-helper lockfile" #define dieusage() strerr_dieusage(100, USAGE) -int main (int argc, char const *const *argv, char const *const *envp) +int main (int argc, char const *const *argv) { - int fd ; - char const *x = env_get2(envp, "S6LOCK_EX") ; + int fd, r ; char c ; PROG = "s6lockd-helper" ; - if (argc < 2) dieusage() ; - fd = open_create(argv[1]) ; + if (argc < 3) dieusage() ; + fd = open_create(argv[2]) ; if (fd < 0) strerr_diefu2sys(111, "open ", argv[1]) ; - if (((x && *x) ? lock_ex(fd) : lock_sh(fd)) < 0) - strerr_diefu2sys(111, "lock ", argv[1]) ; + r = fd_lock(fd, argv[1][0] == 'w', 0) ; + if (!r) errno = EBUSY ; + if (r < 1) strerr_diefu2sys(111, "lock ", argv[2]) ; if (fd_write(1, "!", 1) <= 0) strerr_diefu1sys(111, "write to stdout") ; if (fd_read(0, &c, 1) < 0) diff --git a/src/libs6/s6lockd.c b/src/libs6/s6lockd.c index afa8b3e..f2d18f9 100644 --- a/src/libs6/s6lockd.c +++ b/src/libs6/s6lockd.c @@ -131,8 +131,8 @@ static int parse_protocol (struct iovec const *v, void *context) case '<' : /* lock path */ { s6lockio_t f = S6LOCKIO_ZERO ; - char const *cargv[3] = { S6LOCKD_HELPER_PROG, 0, 0 } ; - char const *cenvp[2] = { 0, 0 } ; + char const *cargv[4] = { S6LOCKD_HELPER_PROG, "r", 0, 0 } ; + char const *nullenv = 0 ; uint32_t options, pathlen ; if (v->iov_len < 23) { @@ -150,9 +150,9 @@ static int parse_protocol (struct iovec const *v, void *context) f.id = id ; s[21] = '.' ; s[22] = '/' ; - cargv[1] = (char const *)s + 21 ; - if (options & S6LOCK_OPTIONS_EX) cenvp[0] = "S6LOCK_EX=1" ; - f.pid = child_spawn2(cargv[0], cargv, cenvp, f.p) ; + if (options & S6LOCK_OPTIONS_EX) cargv[1] = "w" ; + cargv[2] = (char const *)s + 21 ; + f.pid = child_spawn2(cargv[0], cargv, &nullenv, f.p) ; if (!f.pid) { answer(errno) ; -- cgit v1.2.3