diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2021-05-04 12:16:18 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2021-05-04 12:16:18 +0000 |
commit | 95157aa7d44750e248665744518f453ec65e2636 (patch) | |
tree | 658736d14430f4188c7e0420e3f3a23de0936c1a /src/daemontools-extras/s6-setlock.c | |
parent | 80882cf01005ea49672c496eff9f622d5ee5751d (diff) | |
download | s6-95157aa7d44750e248665744518f453ec65e2636.tar.xz |
Also allow shared locks in s6lockd-helper
Diffstat (limited to 'src/daemontools-extras/s6-setlock.c')
-rw-r--r-- | src/daemontools-extras/s6-setlock.c | 27 |
1 files changed, 2 insertions, 25 deletions
diff --git a/src/daemontools-extras/s6-setlock.c b/src/daemontools-extras/s6-setlock.c index 6ba2ec8..6497600 100644 --- 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 } ; |