summaryrefslogtreecommitdiff
path: root/src/libs6
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/libs6
parent2a73901e12a1f3b498e6901ef607b55f9f193097 (diff)
downloads6-8873c303fefaed17f6777989f929612a99675a00.tar.xz
Fix build against skalibs-2.10.0.0
Diffstat (limited to 'src/libs6')
-rw-r--r--src/libs6/deps-lib/s64
-rw-r--r--src/libs6/s6_supervise_lock.c9
-rw-r--r--src/libs6/s6_supervise_lock_mode.c85
-rw-r--r--src/libs6/s6_svc_lock_release.c8
-rw-r--r--src/libs6/s6_svc_lock_take.c28
-rw-r--r--src/libs6/s6_svc_ok.c23
-rw-r--r--src/libs6/s6lockd-helper.c17
-rw-r--r--src/libs6/s6lockd.c10
8 files changed, 25 insertions, 159 deletions
diff --git a/src/libs6/deps-lib/s6 b/src/libs6/deps-lib/s6
index ddd86dc..d9d4341 100644
--- a/src/libs6/deps-lib/s6
+++ b/src/libs6/deps-lib/s6
@@ -31,10 +31,6 @@ s6_dtally_pack.o
s6_dtally_unpack.o
s6_dtally_read.o
s6_dtally_write.o
-s6_supervise_lock.o
-s6_supervise_lock_mode.o
-s6_svc_lock_take.o
-s6_svc_lock_release.o
s6_svc_ok.o
s6_svc_write.o
s6_svc_writectl.o
diff --git a/src/libs6/s6_supervise_lock.c b/src/libs6/s6_supervise_lock.c
deleted file mode 100644
index e241320..0000000
--- a/src/libs6/s6_supervise_lock.c
+++ /dev/null
@@ -1,9 +0,0 @@
-/* ISC license. */
-
-#include <sys/stat.h>
-#include <s6/s6-supervise.h>
-
-int s6_supervise_lock (char const *subdir)
-{
- return s6_supervise_lock_mode(subdir, S_IRWXU, S_IRUSR | S_IWUSR) ;
-}
diff --git a/src/libs6/s6_supervise_lock_mode.c b/src/libs6/s6_supervise_lock_mode.c
deleted file mode 100644
index d807bec..0000000
--- a/src/libs6/s6_supervise_lock_mode.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* ISC license. */
-
-#include <limits.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <errno.h>
-
-#include <skalibs/strerr2.h>
-#include <skalibs/djbunix.h>
-
-#include <s6/s6-supervise.h>
-
-#ifdef PATH_MAX
-# define S6_PATH_MAX PATH_MAX
-#else
-# define S6_PATH_MAX 4096
-#endif
-
-int s6_supervise_lock_mode (char const *subdir, unsigned int subdirmode, unsigned int controlmode)
-{
- size_t subdirlen = strlen(subdir) ;
- int fdctl, fdctlw, fdlock ;
- char control[subdirlen + 9] ;
- char lock[subdirlen + 6] ;
- memcpy(control, subdir, subdirlen) ;
- memcpy(control + subdirlen, "/control", 9) ;
- memcpy(lock, subdir, subdirlen) ;
- memcpy(lock + subdirlen, "/lock", 6) ;
- if (mkdir(subdir, (mode_t)subdirmode) == -1)
- {
- char buf[S6_PATH_MAX] ;
- ssize_t r ;
- if (errno == EEXIST) strerr_diefu2sys(111, "mkdir ", subdir) ;
- r = readlink(subdir, buf, S6_PATH_MAX) ;
- if (r < 0)
- {
- if (errno != EINVAL)
- {
- errno = EEXIST ;
- strerr_diefu2sys(111, "mkdir ", subdir) ;
- }
- }
- else if (r == S6_PATH_MAX)
- {
- errno = ENAMETOOLONG ;
- strerr_diefu2sys(111, "readlink ", subdir) ;
- }
- else
- {
- buf[r] = 0 ;
- if (mkdir(buf, (mode_t)subdirmode) == -1)
- strerr_diefu2sys(111, "mkdir ", buf) ;
- }
- }
- if (mkfifo(control, controlmode) < 0)
- {
- struct stat st ;
- if (errno != EEXIST)
- strerr_diefu2sys(111, "mkfifo ", control) ;
- if (stat(control, &st) < 0)
- strerr_diefu2sys(111, "stat ", control) ;
- if (!S_ISFIFO(st.st_mode))
- strerr_diefu2x(100, control, " is not a FIFO") ;
- }
- fdlock = openc_create(lock) ;
- if (fdlock < 0)
- strerr_diefu2sys(111, "open_create ", lock) ;
- if (lock_ex(fdlock) < 0)
- strerr_diefu2sys(111, "lock ", lock) ;
- fdctlw = openc_write(control) ;
- if (fdctlw >= 0) strerr_dief1x(100, "directory already locked") ;
- if (errno != ENXIO)
- strerr_diefu2sys(111, "open_write ", control) ;
- fdctl = openc_read(control) ;
- if (fdctl < 0)
- strerr_diefu2sys(111, "open_read ", control) ;
- fdctlw = openc_write(control) ;
- if (fdctlw < 0)
- strerr_diefu2sys(111, "open_write ", control) ;
- fd_close(fdlock) ;
-
- return fdctl ;
- /* we leak fdctlw but it's coe. */
-}
diff --git a/src/libs6/s6_svc_lock_release.c b/src/libs6/s6_svc_lock_release.c
deleted file mode 100644
index 4a6f68d..0000000
--- a/src/libs6/s6_svc_lock_release.c
+++ /dev/null
@@ -1,8 +0,0 @@
-/* ISC license. */
-
-#include <skalibs/djbunix.h>
-
-void s6_svc_lock_release (int fd)
-{
- fd_close(fd) ;
-}
diff --git a/src/libs6/s6_svc_lock_take.c b/src/libs6/s6_svc_lock_take.c
deleted file mode 100644
index fcb098a..0000000
--- a/src/libs6/s6_svc_lock_take.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* ISC license. */
-
-#include <sys/stat.h>
-#include <string.h>
-#include <errno.h>
-#include <skalibs/djbunix.h>
-#include <s6/s6-supervise.h>
-
- /* XXX: does not work with dangling S6_SUPERVISE_CTLDIR symlinks */
-
-int s6_svc_lock_take (char const *dir)
-{
- size_t dirlen = strlen(dir) ;
- int fdlock ;
- char lock[dirlen + sizeof(S6_SUPERVISE_CTLDIR) + 6] ;
- memcpy(lock, dir, dirlen) ;
- memcpy(lock + dirlen, "/" S6_SUPERVISE_CTLDIR, sizeof(S6_SUPERVISE_CTLDIR) + 1) ;
- if ((mkdir(lock, S_IRWXU) < 0) && (errno != EEXIST)) return -1 ;
- memcpy(lock + dirlen + sizeof(S6_SUPERVISE_CTLDIR), "/lock", 6) ;
- fdlock = openc_create(lock) ;
- if (fdlock < 0) return -1 ;
- if (lock_ex(fdlock) < 0)
- {
- fd_close(fdlock) ;
- return -1 ;
- }
- return fdlock ;
-}
diff --git a/src/libs6/s6_svc_ok.c b/src/libs6/s6_svc_ok.c
index 5e6aa27..4940071 100644
--- a/src/libs6/s6_svc_ok.c
+++ b/src/libs6/s6_svc_ok.c
@@ -2,24 +2,23 @@
#include <string.h>
#include <errno.h>
+
#include <skalibs/djbunix.h>
+
#include <s6/s6-supervise.h>
int s6_svc_ok (char const *dir)
{
- size_t dirlen = strlen(dir) ;
+ int r ;
+ int e = errno ;
int fd ;
- char fn[dirlen + 9 + sizeof(S6_SUPERVISE_CTLDIR)] ;
+ size_t dirlen = strlen(dir) ;
+ char fn[dirlen + 6 + sizeof(S6_SUPERVISE_CTLDIR)] ;
memcpy(fn, dir, dirlen) ;
- fn[dirlen] = '/' ;
- memcpy(fn + dirlen + 1, S6_SUPERVISE_CTLDIR, sizeof(S6_SUPERVISE_CTLDIR) - 1) ;
- memcpy(fn + dirlen + sizeof(S6_SUPERVISE_CTLDIR), "/control", 9) ;
- fd = open_write(fn) ;
- if (fd < 0)
- {
- if ((errno == ENXIO) || (errno == ENOENT)) return 0 ;
- else return -1 ;
- }
+ memcpy(fn + dirlen, "/" S6_SUPERVISE_CTLDIR "/lock", 6 + sizeof(S6_SUPERVISE_CTLDIR)) ;
+ fd = open_read(fn) ;
+ if (fd < 0) return errno == ENOENT ? (errno = e, 0) : -1 ;
+ r = fd_islocked(fd) ;
fd_close(fd) ;
- return 1 ;
+ return r ;
}
diff --git a/src/libs6/s6lockd-helper.c b/src/libs6/s6lockd-helper.c
index 8979c67..469a417 100644
--- a/src/libs6/s6lockd-helper.c
+++ b/src/libs6/s6lockd-helper.c
@@ -1,24 +1,25 @@
/* ISC license. */
+#include <errno.h>
+
#include <skalibs/allreadwrite.h>
#include <skalibs/strerr2.h>
-#include <skalibs/env.h>
#include <skalibs/djbunix.h>
#define USAGE "s6lockd-helper lockfile"
#define dieusage() strerr_dieusage(100, USAGE)
-int main (int argc, char const *const *argv, char const *const *envp)
+int main (int argc, char const *const *argv)
{
- int fd ;
- char const *x = env_get2(envp, "S6LOCK_EX") ;
+ int fd, r ;
char c ;
PROG = "s6lockd-helper" ;
- if (argc < 2) dieusage() ;
- fd = open_create(argv[1]) ;
+ if (argc < 3) dieusage() ;
+ fd = open_create(argv[2]) ;
if (fd < 0) strerr_diefu2sys(111, "open ", argv[1]) ;
- if (((x && *x) ? lock_ex(fd) : lock_sh(fd)) < 0)
- strerr_diefu2sys(111, "lock ", argv[1]) ;
+ r = fd_lock(fd, argv[1][0] == 'w', 0) ;
+ if (!r) errno = EBUSY ;
+ if (r < 1) strerr_diefu2sys(111, "lock ", argv[2]) ;
if (fd_write(1, "!", 1) <= 0)
strerr_diefu1sys(111, "write to stdout") ;
if (fd_read(0, &c, 1) < 0)
diff --git a/src/libs6/s6lockd.c b/src/libs6/s6lockd.c
index afa8b3e..f2d18f9 100644
--- a/src/libs6/s6lockd.c
+++ b/src/libs6/s6lockd.c
@@ -131,8 +131,8 @@ static int parse_protocol (struct iovec const *v, void *context)
case '<' : /* lock path */
{
s6lockio_t f = S6LOCKIO_ZERO ;
- char const *cargv[3] = { S6LOCKD_HELPER_PROG, 0, 0 } ;
- char const *cenvp[2] = { 0, 0 } ;
+ char const *cargv[4] = { S6LOCKD_HELPER_PROG, "r", 0, 0 } ;
+ char const *nullenv = 0 ;
uint32_t options, pathlen ;
if (v->iov_len < 23)
{
@@ -150,9 +150,9 @@ static int parse_protocol (struct iovec const *v, void *context)
f.id = id ;
s[21] = '.' ;
s[22] = '/' ;
- cargv[1] = (char const *)s + 21 ;
- if (options & S6LOCK_OPTIONS_EX) cenvp[0] = "S6LOCK_EX=1" ;
- f.pid = child_spawn2(cargv[0], cargv, cenvp, f.p) ;
+ if (options & S6LOCK_OPTIONS_EX) cargv[1] = "w" ;
+ cargv[2] = (char const *)s + 21 ;
+ f.pid = child_spawn2(cargv[0], cargv, &nullenv, f.p) ;
if (!f.pid)
{
answer(errno) ;