diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-01-09 22:24:26 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-01-09 22:24:26 +0000 |
commit | aeb3ad3d8cac8f1f085725711d2d8739b722b61b (patch) | |
tree | 2225c0b37c1a19161383c67bdb9043006e8b4fe0 /src/instance/s6-instance-create.c | |
parent | 724fc63f4736d620173e733a3b35c003a0d82ff8 (diff) | |
download | s6-aeb3ad3d8cac8f1f085725711d2d8739b722b61b.tar.xz |
Next batch of fixes
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/instance/s6-instance-create.c')
-rw-r--r-- | src/instance/s6-instance-create.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/instance/s6-instance-create.c b/src/instance/s6-instance-create.c index 40b8a83..5e3d172 100644 --- a/src/instance/s6-instance-create.c +++ b/src/instance/s6-instance-create.c @@ -4,6 +4,7 @@ #include <stdint.h> #include <string.h> #include <unistd.h> +#include <sys/stat.h> #include <skalibs/bytestr.h> #include <skalibs/types.h> @@ -80,14 +81,25 @@ int main (int argc, char const *const *argv) { char sv[namelen + 14] ; + char const *p = sv ; memcpy(sv, "../instances/", 13) ; memcpy(sv + 13, argv[1], namelen + 1) ; + { + struct stat st ; + if (stat(sv, &st) == 0) + if (!S_ISDIR(st.st_mode)) + strerr_dief3x(100, "unexpected file preventing instance creation at ", argv[0], sv+2) ; + else + strerr_dief3x(100, "instance appears to already exist at ", argv[0], sv+2) ; + else if (errno != ENOENT) + strerr_diefu3sys(111, "stat ", argv[0], sv+2) ; + } if (!hiercopy("../instances/.template", sv)) { cleanup(sv) ; strerr_diefu5sys(111, "copy ", argv[0], "/instances/.template to ", argv[0], sv+2) ; } - if (s6_supervise_link_names_g(".", (char const *const *)&sv, argv + 1, 1, options, &tto) == -1) + if (s6_supervise_link_names_g(".", &p, argv + 1, 1, options, &tto) == -1) { cleanup(sv) ; strerr_diefu4sys(errno == ETIMEDOUT ? 99 : 111, "create instance of ", argv[0], " named ", argv[1]) ; |