summaryrefslogtreecommitdiff
path: root/src/libs6rc/s6rc_lock.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-12-07 17:55:23 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-12-07 17:55:23 +0000
commit0e7b69f1af91ccf288f3e1fd29ea7c65b7f6f986 (patch)
tree6ad1fb5b87db3d17ed40c30ac9ea6d980fb3c6b0 /src/libs6rc/s6rc_lock.c
parent79cb9644f99f056641f4c145da6e7ca63b333b80 (diff)
downloads6-rc-0e7b69f1af91ccf288f3e1fd29ea7c65b7f6f986.tar.xz
Prepare for 0.5.2.1; build against new skalibs/execline/s6
Diffstat (limited to 'src/libs6rc/s6rc_lock.c')
-rw-r--r--src/libs6rc/s6rc_lock.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/libs6rc/s6rc_lock.c b/src/libs6rc/s6rc_lock.c
index d3ae2b5..e879fcc 100644
--- a/src/libs6rc/s6rc_lock.c
+++ b/src/libs6rc/s6rc_lock.c
@@ -2,18 +2,10 @@
#include <string.h>
#include <errno.h>
-#include <skalibs/djbunix.h>
-#include <s6-rc/s6rc-utils.h>
-static inline int lockex (int fd, int blocking)
-{
- return blocking ? lock_ex(fd) : lock_exnb(fd) ;
-}
+#include <skalibs/djbunix.h>
-static inline int locksh (int fd, int blocking)
-{
- return blocking ? lock_sh(fd) : lock_shnb(fd) ;
-}
+#include <s6-rc/s6rc-utils.h>
int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int cwhat, int *ccfd, int blocking)
{
@@ -21,6 +13,7 @@ int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int
if (lwhat)
{
+ int r ;
size_t llen = strlen(live) ;
char lfn[llen + 6] ;
memcpy(lfn, live, llen) ;
@@ -28,7 +21,9 @@ int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int
lfd = open_create(lfn) ;
if (lfd < 0) return 0 ;
if (coe(lfd) < 0) goto lerr ;
- if ((lwhat > 1 ? lockex(lfd, blocking) : locksh(lfd, blocking)) < 0) goto lerr ;
+ r = fd_lock(lfd, lwhat > 1, !blocking) ;
+ if (!r) errno = EBUSY ;
+ if (r < 1) goto lerr ;
}
if (cwhat)
@@ -43,8 +38,11 @@ int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int
else cfd = -errno ;
else
{
+ int r ;
if (coe(cfd) < 0) goto cerr ;
- if ((cwhat > 1 ? lockex(cfd, blocking) : locksh(cfd, blocking)) < 0) goto cerr ;
+ r = fd_lock(cfd, cwhat > 1, !blocking) ;
+ if (!r) errno = EBUSY ;
+ if (r < 1) goto cerr ;
}
}