s6

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

commit 73638ee8e3c7b0ee0d6603d1ead2e3829d9f7686
parent bcae3b9d79bc2363914324daba54089f16c636c3
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Sat,  3 Apr 2021 10:18:24 +0000

 bugfix: setlock -r

Diffstat:
Msrc/daemontools-extras/s6-setlock.c | 22+++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/daemontools-extras/s6-setlock.c b/src/daemontools-extras/s6-setlock.c @@ -42,9 +42,25 @@ int main (int argc, char const *const *argv) if (nb < 2) { - int r ; - int fd = open_create(argv[0]) ; - if (fd < 0) strerr_diefu2sys(111, "open_create ", argv[0]) ; + 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]) ;