From 69075d8b479fd85bfea95a914ae3fa89c27fa586 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 16 Nov 2020 03:45:49 +0000 Subject: Fix supervise/svscan startup when the control dir already exists --- src/libs6/s6_supervise_lock_mode.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libs6/s6_supervise_lock_mode.c b/src/libs6/s6_supervise_lock_mode.c index b6b0829..d807bec 100644 --- a/src/libs6/s6_supervise_lock_mode.c +++ b/src/libs6/s6_supervise_lock_mode.c @@ -29,21 +29,25 @@ int s6_supervise_lock_mode (char const *subdir, unsigned int subdirmode, unsigne memcpy(lock + subdirlen, "/lock", 6) ; if (mkdir(subdir, (mode_t)subdirmode) == -1) { - if (errno != EEXIST) strerr_diefu2sys(111, "mkdir ", subdir) ; - else + 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) { - char buf[S6_PATH_MAX] ; - ssize_t r = readlink(subdir, buf, S6_PATH_MAX) ; - if (r < 0) + if (errno != EINVAL) { errno = EEXIST ; strerr_diefu2sys(111, "mkdir ", subdir) ; } - if (r == S6_PATH_MAX) - { - errno = ENAMETOOLONG ; - strerr_diefu2sys(111, "readlink ", 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) ; -- cgit v1.2.3