From aeb3ad3d8cac8f1f085725711d2d8739b722b61b Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 9 Jan 2023 22:24:26 +0000 Subject: Next batch of fixes Signed-off-by: Laurent Bercot --- src/instance/s6-instance-create.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/instance/s6-instance-create.c') 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 #include #include +#include #include #include @@ -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]) ; -- cgit v1.3.1