about summary refs log tree commit diff
path: root/src/daemontools-extras
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-12-02 05:24:24 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-12-02 05:24:24 +0000
commit8873c303fefaed17f6777989f929612a99675a00 (patch)
tree26efa9863177ec574d4351e8db84a47566a2af98 /src/daemontools-extras
parent2a73901e12a1f3b498e6901ef607b55f9f193097 (diff)
downloads6-8873c303fefaed17f6777989f929612a99675a00.tar.gz
s6-8873c303fefaed17f6777989f929612a99675a00.tar.xz
s6-8873c303fefaed17f6777989f929612a99675a00.zip
Fix build against skalibs-2.10.0.0
Diffstat (limited to 'src/daemontools-extras')
-rw-r--r--src/daemontools-extras/s6-log.c11
-rw-r--r--src/daemontools-extras/s6-setlock.c18
2 files changed, 14 insertions, 15 deletions
diff --git a/src/daemontools-extras/s6-log.c b/src/daemontools-extras/s6-log.c
index 2f8438d..5128751 100644
--- a/src/daemontools-extras/s6-log.c
+++ b/src/daemontools-extras/s6-log.c
@@ -580,13 +580,14 @@ static inline void logdir_init (unsigned int index, uint32_t s, uint32_t n, uint
   ldp->fd = -1 ;
   ldp->rstate = ROTSTATE_WRITABLE ;
   r = mkdir(ldp->dir, S_IRWXU | S_ISGID) ;
-  if ((r < 0) && (errno != EEXIST)) strerr_diefu2sys(111, "mkdir ", name) ;
+  if (r < 0 && errno != EEXIST) strerr_diefu2sys(111, "mkdir ", name) ;
   memcpy(x, name, dirlen) ;
   memcpy(x + dirlen, "/lock", 6) ;
-  ldp->fdlock = open_append(x) ;
-  if ((ldp->fdlock) < 0) strerr_diefu2sys(111, "open_append ", x) ;
-  if (lock_exnb(ldp->fdlock) < 0) strerr_diefu2sys(111, "lock_exnb ", x) ;
-  if (coe(ldp->fdlock) < 0) strerr_diefu2sys(111, "coe ", x) ;
+  ldp->fdlock = openc_create(x) ;
+  if (ldp->fdlock < 0) strerr_diefu2sys(111, "open ", x) ;
+  r = fd_lock(ldp->fdlock, 1, 1) ;
+  if (!r) errno = EBUSY ;
+  if (r < 1) strerr_diefu2sys(111, "lock ", x) ;
   memcpy(x + dirlen + 1, "current", 8) ;
   if (stat(x, &st) < 0)
   {
diff --git a/src/daemontools-extras/s6-setlock.c b/src/daemontools-extras/s6-setlock.c
index bc50519..cd938b7 100644
--- a/src/daemontools-extras/s6-setlock.c
+++ b/src/daemontools-extras/s6-setlock.c
@@ -18,11 +18,6 @@
 #define USAGE "s6-setlock [ -r | -w ] [ -n | -N | -t timeout ] lockfile prog..."
 #define dieusage() strerr_dieusage(100, USAGE)
 
-typedef int lockfunc_t (int) ;
-typedef lockfunc_t *lockfunc_t_ref ;
-
-static lockfunc_t_ref f[2][2] = { { &lock_sh, &lock_shnb }, { &lock_ex, &lock_exnb } } ;
-
 int main (int argc, char const *const *argv)
 {
   unsigned int nb = 0, ex = 1 ;
@@ -47,14 +42,17 @@ int main (int argc, char const *const *argv)
 
   if (nb < 2)
   {
+    int r ;
     int fd = open_create(argv[0]) ;
-    if (fd == -1) strerr_diefu2sys(111, "open_create ", argv[0]) ;
-    if ((*f[ex][nb])(fd) == -1) strerr_diefu2sys(1, "lock ", argv[0]) ;
+    if (fd < 0) strerr_diefu2sys(111, "open_create ", argv[0]) ;
+    r = fd_lock(fd, ex, nb) ;
+    if (!r) errno = EBUSY ;
+    if (r < 1) strerr_diefu2sys(1, "lock ", argv[0]) ;
   }
   else
   {
-    char const *cargv[3] = { "s6lockd-helper", argv[0], 0 } ;
-    char const *cenvp[2] = { ex ? "S6LOCK_EX=1" : 0, 0 } ;
+    char const *cargv[4] = { "s6lockd-helper", ex ? "w" : "r", argv[0], 0 } ;
+    char const *nullenv = { 0 } ;
     iopause_fd x = { .events = IOPAUSE_READ } ;
     tain_t deadline ;
     int p[2] = { 0, 1 } ;
@@ -63,7 +61,7 @@ int main (int argc, char const *const *argv)
     tain_now_set_stopwatch_g() ;
     tain_from_millisecs(&deadline, timeout) ;
     tain_add_g(&deadline, &deadline) ;
-    pid = child_spawn2(S6_LIBEXECPREFIX "s6lockd-helper", cargv, cenvp, p) ;
+    pid = child_spawn2(S6_LIBEXECPREFIX "s6lockd-helper", cargv, &nullenv, p) ;
     if (!pid) strerr_diefu2sys(111, "spawn ", S6_LIBEXECPREFIX "s6lockd-helper") ;
     x.fd = p[0] ;
     for (;;)