s6

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

commit 95157aa7d44750e248665744518f453ec65e2636
parent 80882cf01005ea49672c496eff9f622d5ee5751d
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Tue,  4 May 2021 12:16:18 +0000

 Also allow shared locks in s6lockd-helper

Diffstat:
Mpackage/deps.mak | 15+++++++++++----
Msrc/daemontools-extras/deps-exe/s6-setlock | 1+
Msrc/daemontools-extras/s6-setlock.c | 27++-------------------------
Asrc/include-local/s6lockd.h | 8++++++++
Msrc/libs6/deps-exe/s6lockd-helper | 1+
Asrc/libs6/deps-lib/s6lockd | 1+
Msrc/libs6/s6lockd-helper.c | 14++++----------
Asrc/libs6/s6lockd_openandlock.c | 35+++++++++++++++++++++++++++++++++++
Mtools/gen-deps.sh | 11+++++++++--
9 files changed, 72 insertions(+), 41 deletions(-)

diff --git a/package/deps.mak b/package/deps.mak @@ -24,7 +24,7 @@ src/daemontools-extras/s6-envdir.o src/daemontools-extras/s6-envdir.lo: src/daem src/daemontools-extras/s6-envuidgid.o src/daemontools-extras/s6-envuidgid.lo: src/daemontools-extras/s6-envuidgid.c src/daemontools-extras/s6-fghack.o src/daemontools-extras/s6-fghack.lo: src/daemontools-extras/s6-fghack.c src/daemontools-extras/s6-log.o src/daemontools-extras/s6-log.lo: src/daemontools-extras/s6-log.c src/include/s6/config.h -src/daemontools-extras/s6-setlock.o src/daemontools-extras/s6-setlock.lo: src/daemontools-extras/s6-setlock.c src/include/s6/config.h +src/daemontools-extras/s6-setlock.o src/daemontools-extras/s6-setlock.lo: src/daemontools-extras/s6-setlock.c src/include/s6/config.h src/include-local/s6lockd.h src/daemontools-extras/s6-setsid.o src/daemontools-extras/s6-setsid.lo: src/daemontools-extras/s6-setsid.c src/daemontools-extras/s6-setuidgid.o src/daemontools-extras/s6-setuidgid.lo: src/daemontools-extras/s6-setuidgid.c src/include/s6/config.h src/daemontools-extras/s6-softlimit.o src/daemontools-extras/s6-softlimit.lo: src/daemontools-extras/s6-softlimit.c @@ -109,8 +109,9 @@ src/libs6/s6lock_update.o src/libs6/s6lock_update.lo: src/libs6/s6lock_update.c src/libs6/s6lock_wait_and.o src/libs6/s6lock_wait_and.lo: src/libs6/s6lock_wait_and.c src/include/s6/s6lock.h src/libs6/s6lock_wait_or.o src/libs6/s6lock_wait_or.lo: src/libs6/s6lock_wait_or.c src/include/s6/s6lock.h src/libs6/s6lock_zero.o src/libs6/s6lock_zero.lo: src/libs6/s6lock_zero.c src/include/s6/s6lock.h -src/libs6/s6lockd-helper.o src/libs6/s6lockd-helper.lo: src/libs6/s6lockd-helper.c +src/libs6/s6lockd-helper.o src/libs6/s6lockd-helper.lo: src/libs6/s6lockd-helper.c src/include-local/s6lockd.h src/libs6/s6lockd.o src/libs6/s6lockd.lo: src/libs6/s6lockd.c src/include/s6/s6lock.h +src/libs6/s6lockd_openandlock.o src/libs6/s6lockd_openandlock.lo: src/libs6/s6lockd_openandlock.c src/include-local/s6lockd.h src/pipe-tools/s6-cleanfifodir.o src/pipe-tools/s6-cleanfifodir.lo: src/pipe-tools/s6-cleanfifodir.c src/include/s6/ftrigw.h src/pipe-tools/s6-ftrig-listen.o src/pipe-tools/s6-ftrig-listen.lo: src/pipe-tools/s6-ftrig-listen.c src/include/s6/compat.h src/include/s6/ftrigr.h src/pipe-tools/s6-ftrig-listen1.o src/pipe-tools/s6-ftrig-listen1.lo: src/pipe-tools/s6-ftrig-listen1.c src/include/s6/ftrigr.h @@ -170,7 +171,7 @@ s6-fghack: src/daemontools-extras/s6-fghack.o s6-log: EXTRA_LIBS := -lskarnet ${SYSCLOCK_LIB} s6-log: src/daemontools-extras/s6-log.o s6-setlock: EXTRA_LIBS := -lskarnet ${SYSCLOCK_LIB} ${SPAWN_LIB} -s6-setlock: src/daemontools-extras/s6-setlock.o +s6-setlock: src/daemontools-extras/s6-setlock.o libs6lockd.a.xyzzy s6-setsid: EXTRA_LIBS := -lskarnet s6-setsid: src/daemontools-extras/s6-setsid.o s6-setuidgid: EXTRA_LIBS := -lskarnet @@ -208,12 +209,17 @@ libs6.a.xyzzy: src/libs6/ftrigr1_zero.lo src/libs6/ftrigr_check.lo src/libs6/ftr endif libs6.so.xyzzy: EXTRA_LIBS := -lskarnet libs6.so.xyzzy: src/libs6/ftrigr1_zero.lo src/libs6/ftrigr_check.lo src/libs6/ftrigr_checksa.lo src/libs6/ftrigr_ack.lo src/libs6/ftrigr_end.lo src/libs6/ftrigr_start.lo src/libs6/ftrigr_startf.lo src/libs6/ftrigr_subscribe.lo src/libs6/ftrigr_unsubscribe.lo src/libs6/ftrigr_update.lo src/libs6/ftrigr_updateb.lo src/libs6/ftrigr_wait_and.lo src/libs6/ftrigr_wait_or.lo src/libs6/ftrigr_zero.lo src/libs6/ftrigw_clean.lo src/libs6/ftrigw_fifodir_make.lo src/libs6/ftrigw_notify.lo src/libs6/ftrigw_notifyb.lo src/libs6/ftrigw_notifyb_nosig.lo src/libs6/s6_accessrules_backend_cdb.lo src/libs6/s6_accessrules_backend_fs.lo src/libs6/s6_accessrules_keycheck_ip4.lo src/libs6/s6_accessrules_keycheck_ip6.lo src/libs6/s6_accessrules_keycheck_reversedns.lo src/libs6/s6_accessrules_keycheck_uidgid.lo src/libs6/s6_accessrules_params_free.lo src/libs6/s6_accessrules_uidgid_cdb.lo src/libs6/s6_accessrules_uidgid_fs.lo src/libs6/s6_compat_el_semicolon.lo src/libs6/s6_dtally_pack.lo src/libs6/s6_dtally_unpack.lo src/libs6/s6_dtally_read.lo src/libs6/s6_dtally_write.lo src/libs6/s6_svc_ok.lo src/libs6/s6_svc_write.lo src/libs6/s6_svc_writectl.lo src/libs6/s6_svstatus_pack.lo src/libs6/s6_svstatus_read.lo src/libs6/s6_svstatus_unpack.lo src/libs6/s6_svstatus_write.lo src/libs6/s6lock_acquire.lo src/libs6/s6lock_check.lo src/libs6/s6lock_end.lo src/libs6/s6lock_release.lo src/libs6/s6lock_start.lo src/libs6/s6lock_startf.lo src/libs6/s6lock_update.lo src/libs6/s6lock_wait_and.lo src/libs6/s6lock_wait_or.lo src/libs6/s6lock_zero.lo src/libs6/s6_fdholder_delete.lo src/libs6/s6_fdholder_delete_async.lo src/libs6/s6_fdholder_end.lo src/libs6/s6_fdholder_getdump.lo src/libs6/s6_fdholder_list.lo src/libs6/s6_fdholder_list_async.lo src/libs6/s6_fdholder_list_cb.lo src/libs6/s6_fdholder_retrieve.lo src/libs6/s6_fdholder_retrieve_async.lo src/libs6/s6_fdholder_retrieve_cb.lo src/libs6/s6_fdholder_setdump.lo src/libs6/s6_fdholder_start.lo src/libs6/s6_fdholder_store.lo src/libs6/s6_fdholder_store_async.lo src/libs6/s6_supervise_link.lo src/libs6/s6_supervise_unlink.lo +ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) +libs6lockd.a.xyzzy: src/libs6/s6lockd_openandlock.o +else +libs6lockd.a.xyzzy: src/libs6/s6lockd_openandlock.lo +endif s6-ftrigrd: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} s6-ftrigrd: src/libs6/s6-ftrigrd.o src/libs6/ftrig1_free.o src/libs6/ftrig1_make.o s6lockd: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} ${SPAWN_LIB} s6lockd: src/libs6/s6lockd.o s6lockd-helper: EXTRA_LIBS := -lskarnet -s6lockd-helper: src/libs6/s6lockd-helper.o +s6lockd-helper: src/libs6/s6lockd-helper.o libs6lockd.a.xyzzy s6-cleanfifodir: EXTRA_LIBS := -lskarnet s6-cleanfifodir: src/pipe-tools/s6-cleanfifodir.o ${LIBS6} s6-ftrig-listen: EXTRA_LIBS := ${EXECLINE_LIB} -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} ${SPAWN_LIB} @@ -256,3 +262,4 @@ s6-svwait: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} ${SPAWN_LIB} s6-svwait: src/supervision/s6-svwait.o src/supervision/s6_svlisten_loop.o ${LIBS6} s6-usertree-maker: EXTRA_LIBS := -lskarnet s6-usertree-maker: src/usertree/s6-usertree-maker.o +INTERNAL_LIBS := libs6lockd.a.xyzzy diff --git a/src/daemontools-extras/deps-exe/s6-setlock b/src/daemontools-extras/deps-exe/s6-setlock @@ -1,3 +1,4 @@ +libs6lockd.a.xyzzy -lskarnet ${SYSCLOCK_LIB} ${SPAWN_LIB} diff --git a/src/daemontools-extras/s6-setlock.c b/src/daemontools-extras/s6-setlock.c @@ -14,6 +14,7 @@ #include <skalibs/exec.h> #include <s6/config.h> +#include "s6lockd.h" #define USAGE "s6-setlock [ -r | -w ] [ -n | -N | -t timeout ] lockfile prog..." #define dieusage() strerr_dieusage(100, USAGE) @@ -40,31 +41,7 @@ int main (int argc, char const *const *argv) argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ; if (argc < 2) dieusage() ; - if (nb < 2) - { - int r, fd ; - if (ex) - { - fd = open_create(argv[0]) ; - if (fd < 0) strerr_diefu3sys(111, "open ", argv[0], " for writing") ; - } - else - { - fd = open_read(argv[0]) ; - if (fd < 0) - { - if (errno != ENOENT) strerr_diefu3sys(111, "open ", argv[0], " for reading") ; - fd = open_create(argv[0]) ; - if (fd < 0) strerr_diefu2sys(111, "create ", argv[0]) ; - close(fd) ; - fd = open_read(argv[0]) ; - if (fd < 0) strerr_diefu3sys(111, "open ", argv[0], " for reading") ; - } - } - r = fd_lock(fd, ex, nb) ; - if (!r) errno = EBUSY ; - if (r < 1) strerr_diefu2sys(1, "lock ", argv[0]) ; - } + if (nb < 2) s6lockd_openandlock(argv[0], ex, nb) ; else { char const *cargv[4] = { "s6lockd-helper", ex ? "w" : "r", argv[0], 0 } ; diff --git a/src/include-local/s6lockd.h b/src/include-local/s6lockd.h @@ -0,0 +1,8 @@ +/* ISC license. */ + +#ifndef S6LOCKD_H +#define S6LOCKD_H + +extern int s6lockd_openandlock (char const *, int, int) ; + +#endif diff --git a/src/libs6/deps-exe/s6lockd-helper b/src/libs6/deps-exe/s6lockd-helper @@ -1 +1,2 @@ +libs6lockd.a.xyzzy -lskarnet diff --git a/src/libs6/deps-lib/s6lockd b/src/libs6/deps-lib/s6lockd @@ -0,0 +1 @@ +s6lockd_openandlock.o diff --git a/src/libs6/s6lockd-helper.c b/src/libs6/s6lockd-helper.c @@ -1,25 +1,19 @@ /* ISC license. */ -#include <errno.h> - #include <skalibs/allreadwrite.h> #include <skalibs/strerr2.h> -#include <skalibs/djbunix.h> -#define USAGE "s6lockd-helper lockfile" +#include "s6lockd.h" + +#define USAGE "s6lockd-helper r|w lockfile" #define dieusage() strerr_dieusage(100, USAGE) int main (int argc, char const *const *argv) { - int fd, r ; char c ; PROG = "s6lockd-helper" ; if (argc < 3) dieusage() ; - fd = open_create(argv[2]) ; - if (fd < 0) strerr_diefu2sys(111, "open ", argv[1]) ; - r = fd_lock(fd, argv[1][0] == 'w', 0) ; - if (!r) errno = EBUSY ; - if (r < 1) strerr_diefu2sys(111, "lock ", argv[2]) ; + s6lockd_openandlock(argv[2], argv[1][0] == 'w', 0) ; 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_openandlock.c b/src/libs6/s6lockd_openandlock.c @@ -0,0 +1,35 @@ +/* ISC license. */ + +#include <errno.h> + +#include <skalibs/strerr2.h> +#include <skalibs/djbunix.h> + +#include "s6lockd.h" + +int s6lockd_openandlock (char const *file, int ex, int nb) +{ + int fd, r ; + if (ex) + { + fd = open_create(file) ; + if (fd < 0) strerr_diefu3sys(111, "open ", file, " for writing") ; + } + else + { + fd = open_read(file) ; + if (fd < 0) + { + if (errno != ENOENT) strerr_diefu3sys(111, "open ", file, " for reading") ; + fd = open_create(file) ; + if (fd < 0) strerr_diefu2sys(111, "create ", file) ; + fd_close(fd) ; + fd = open_read(file) ; + if (fd < 0) strerr_diefu3sys(111, "open ", file, " for reading") ; + } + } + r = fd_lock(fd, ex, nb) ; + if (!r) errno = EBUSY ; + if (r < 1) strerr_diefu2sys(1, "lock ", file) ; + return fd ; +} diff --git a/tools/gen-deps.sh b/tools/gen-deps.sh @@ -7,6 +7,8 @@ echo '# This file has been generated by tools/gen-deps.sh' echo '#' echo +internal_libs= + for dir in src/include/${package} src/* ; do for file in $(ls -1 $dir | grep -- \\.h$) ; do { @@ -70,8 +72,12 @@ for dir in $(ls -1 src | grep -v ^include) ; do echo else echo "lib${file}.a.xyzzy:$(echo "$deps" | sed 's/\.o/.lo/g')" echo endif - echo "lib${file}.so.xyzzy: EXTRA_LIBS :=$libs" - echo "lib${file}.so.xyzzy:$(echo "$deps" | sed 's/\.o/.lo/g')" + if grep -F "LIB_DEFS :=" package/targets.mak | grep -qF "$file" ; then + echo "lib${file}.so.xyzzy: EXTRA_LIBS :=$libs" + echo "lib${file}.so.xyzzy:$(echo "$deps" | sed 's/\.o/.lo/g')" + else + internal_libs="$internal_libs lib${file}.a.xyzzy" + fi done for file in $(ls -1 src/$dir/deps-exe) ; do @@ -91,3 +97,4 @@ for dir in $(ls -1 src | grep -v ^include) ; do echo "$file: src/$dir/$file.o$deps" done done +echo "INTERNAL_LIBS :=$internal_libs"