summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-07-14 14:26:21 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-07-14 14:26:21 +0000
commitd0c7a4001e4c2db27dfd77ccea6890422b6114e8 (patch)
treeff70a1e69bea67877dab89eb9f4e47df02695d37 /src
parent1b80dacb9b94c17f4d60a8374956c8965c44cbd5 (diff)
downloads6-rc-d0c7a4001e4c2db27dfd77ccea6890422b6114e8.tar.xz
allow existing empty directories for live in s6-rc-init
Diffstat (limited to 'src')
-rw-r--r--src/s6-rc/s6-rc-init.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/s6-rc/s6-rc-init.c b/src/s6-rc/s6-rc-init.c
index 27ba819..d4b0218 100644
--- a/src/s6-rc/s6-rc-init.c
+++ b/src/s6-rc/s6-rc-init.c
@@ -26,6 +26,28 @@ static void cleanup (char const *live)
errno = e ;
}
+static inline void check_emptydir (char const *path)
+{
+ DIR *dir = opendir(path) ;
+ if (!dir)
+ {
+ if (errno == ENOTDIR) strerr_diefu2sys(100, "create live directory at ", path) ;
+ else strerr_diefu2sys(111, "opendir ", path) ;
+ }
+ for (;;)
+ {
+ direntry *d ;
+ errno = 0 ;
+ d = readdir(dir) ;
+ if (!d) break ;
+ if (d->d_name[0] == '.' && (!d->d_name[1] || (d->d_name[1] == '.' && !d->d_name[2])))
+ continue ;
+ strerr_diefu3x(100, "create live directory at ", path, ": directory not empty") ;
+ }
+ if (errno) strerr_diefu2sys(111, "readdir ", path) ;
+ dir_close(dir) ;
+}
+
int main (int argc, char const *const *argv)
{
tain_t deadline, tto ;
@@ -61,7 +83,10 @@ int main (int argc, char const *const *argv)
strerr_dief2x(100, "scandir", " must be an absolute path") ;
if (mkdir(live, 0755) < 0)
- strerr_diefu2sys(111, "mkdir ", live) ;
+ {
+ if (errno != EEXIST) strerr_diefu2sys(111, "mkdir ", live) ;
+ check_emptydir(live) ;
+ }
{
int fdlock ;
@@ -96,7 +121,11 @@ int main (int argc, char const *const *argv)
/* compiled */
fdcompiled = open_readb(compiled) ;
- if (fdcompiled < 0) strerr_diefu2sys(111, "open ", compiled) ;
+ if (fdcompiled < 0)
+ {
+ cleanup(live) ;
+ strerr_diefu2sys(111, "open ", compiled) ;
+ }
byte_copy(lfn + llen + 1, 9, "compiled") ;
if (symlink(compiled, lfn) < 0)
{