diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2021-04-03 10:18:24 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2021-04-03 10:18:24 +0000 |
commit | 73638ee8e3c7b0ee0d6603d1ead2e3829d9f7686 (patch) | |
tree | 10a0232f1665b8ee6b223ed332ef8b2823c20653 /src | |
parent | bcae3b9d79bc2363914324daba54089f16c636c3 (diff) | |
download | s6-73638ee8e3c7b0ee0d6603d1ead2e3829d9f7686.tar.xz |
bugfix: setlock -r
Diffstat (limited to 'src')
-rw-r--r-- | src/daemontools-extras/s6-setlock.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/daemontools-extras/s6-setlock.c b/src/daemontools-extras/s6-setlock.c index cd938b7..6ba2ec8 100644 --- 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]) ; |