summaryrefslogtreecommitdiff
path: root/src/libs6rc/s6rc_lock.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-03-23 14:34:16 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-03-23 14:34:16 +0000
commit543c1405653c48d23e19d03d7c62e9534fc9a110 (patch)
treefe8e0c8d29ec5312c4b62cc87a7f21a43e42e155 /src/libs6rc/s6rc_lock.c
parentc59874cf6426522ec4caa7b88b23f477ef2a5967 (diff)
downloads6-rc-543c1405653c48d23e19d03d7c62e9534fc9a110.tar.xz
Don't wait on locks by default (fail instead); add a -b option to get the waiting behaviour
Also fix a few types in s6-rc-compile (unsigned int -> uint32_t for avltree indices)
Diffstat (limited to 'src/libs6rc/s6rc_lock.c')
-rw-r--r--src/libs6rc/s6rc_lock.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/libs6rc/s6rc_lock.c b/src/libs6rc/s6rc_lock.c
index dab3035..2a623d0 100644
--- a/src/libs6rc/s6rc_lock.c
+++ b/src/libs6rc/s6rc_lock.c
@@ -5,7 +5,17 @@
#include <skalibs/djbunix.h>
#include <s6-rc/s6rc-utils.h>
-int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int cwhat, int *ccfd)
+static inline int lockex (int fd, int blocking)
+{
+ return blocking ? lock_ex(fd) : lock_exnb(fd) ;
+}
+
+static inline int locksh (int fd, int blocking)
+{
+ return blocking ? lock_sh(fd) : lock_shnb(fd) ;
+}
+
+int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int cwhat, int *ccfd, int blocking)
{
int e = 0 ;
int lfd = -1, cfd = -1 ;
@@ -18,7 +28,7 @@ int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int
memcpy(lfn + llen, "/lock", 6) ;
lfd = open_create(lfn) ;
if (lfd < 0) return 0 ;
- if ((lwhat > 1 ? lock_ex(lfd) : lock_sh(lfd)) < 0) { e = errno ; goto lerr ; }
+ if ((lwhat > 1 ? lockex(lfd, blocking) : locksh(lfd, blocking)) < 0) { e = errno ; goto lerr ; }
}
if (cwhat)
@@ -31,7 +41,7 @@ int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int
if (cfd < 0)
if (cwhat > 1 || errno != EROFS) { e = errno ; goto lerr ; }
else cfd = -errno ;
- else if ((cwhat > 1 ? lock_ex(cfd) : lock_sh(cfd)) < 0) { e = errno ; goto cerr ; }
+ else if ((cwhat > 1 ? lockex(cfd, blocking) : locksh(cfd, blocking)) < 0) { e = errno ; goto cerr ; }
}
if (lwhat) *llfd = lfd ;