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-control.c | 4 ++-- src/instance/s6-instance-create.c | 14 +++++++++++++- src/instance/s6-instance-delete.c | 10 ++++++++-- src/libs6/s6_supervise_link_names.c | 3 +++ src/supervision/s6-svc.c | 2 +- 5 files changed, 27 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/instance/s6-instance-control.c b/src/instance/s6-instance-control.c index badb8b2..ef064e6 100644 --- a/src/instance/s6-instance-control.c +++ b/src/instance/s6-instance-control.c @@ -10,7 +10,7 @@ #include -#define USAGE "s6-instance-control [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcyroduDUxOX ] service instance" +#define USAGE "s6-instance-control [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcyroduDUxO ] service instance" #define dieusage() strerr_dieusage(100, USAGE) #define DATASIZE 63 @@ -27,7 +27,7 @@ int main (int argc, char const **argv) unsigned int timeout = 0 ; for (;;) { - int opt = subgetopt_r(argc, argv, "abqhkti12pcyroduxOT:w:", &l) ; + int opt = subgetopt_r(argc, argv, "abqhkti12pcyroduDUxOT:w:", &l) ; if (opt == -1) break ; switch (opt) { 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]) ; diff --git a/src/instance/s6-instance-delete.c b/src/instance/s6-instance-delete.c index 37c345c..92078e0 100644 --- a/src/instance/s6-instance-delete.c +++ b/src/instance/s6-instance-delete.c @@ -21,6 +21,7 @@ int main (int argc, char const *const *argv) { tain tto = TAIN_INFINITE_RELATIVE ; + size_t namelen ; uint32_t options = 1 ; PROG = "s6-instance-delete" ; { @@ -42,7 +43,9 @@ int main (int argc, char const *const *argv) } if (argc < 2) dieusage() ; if (!argv[0][0]) strerr_dief1x(100, "invalid service path") ; - if (!argv[1][0] || argv[1][0] == '.' || byte_in(argv[1], strlen(argv[1]), " \t\f\r\n", 5) < strlen(argv[1])) + + namelen = strlen(argv[1]) ; + if (!argv[1][0] || argv[1][0] == '.' || byte_in(argv[1], namelen, " \t\f\r\n", 5) < namelen) strerr_dief1x(100, "invalid instance name") ; tain_now_set_stopwatch_g() ; @@ -50,11 +53,14 @@ int main (int argc, char const *const *argv) { size_t svlen = strlen(argv[0]) ; - char sc[svlen + 10] ; + char sc[svlen + 12 + namelen] ; memcpy(sc, argv[0], svlen) ; memcpy(sc + svlen, "/instance", 10) ; if (s6_supervise_unlink_names_g(sc, argv + 1, 1, options, &tto) == -1) strerr_diefu4sys(111, "prepare deletion of instance ", argv[1], " of service ", argv[0]) ; + memcpy(sc + svlen + 9, "s/", 2) ; + memcpy(sc + svlen + 11, argv[1], namelen + 1) ; + rm_rf(sc) ; } return 0 ; diff --git a/src/libs6/s6_supervise_link_names.c b/src/libs6/s6_supervise_link_names.c index de8e5c5..7712e7e 100644 --- a/src/libs6/s6_supervise_link_names.c +++ b/src/libs6/s6_supervise_link_names.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -55,8 +56,10 @@ int s6_supervise_link_names (char const *scdir, char const *const *servicedirs, memset(locked, 0, bitarray_div8(n)) ; memset(logged, 0, bitarray_div8(n)) ; + LOLDEBUG("s6_supervise_link_names: scdir = %s n = %zu options = %u", scdir, n, options) ; for (size_t i = 0 ; i < n ; i++) { + LOLDEBUG("i = %zu dir = %s name = %s", i, servicedirs[i], names[i]) ; struct stat st ; size_t len = strlen(servicedirs[i]) ; size_t nlen = strlen(names[i]) ; diff --git a/src/supervision/s6-svc.c b/src/supervision/s6-svc.c index 5982248..8c75abb 100644 --- a/src/supervision/s6-svc.c +++ b/src/supervision/s6-svc.c @@ -13,7 +13,7 @@ #include #include -#define USAGE "s6-svc [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcyroduDUxOX ] servicedir" +#define USAGE "s6-svc [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcyroduDUxO ] servicedir" #define dieusage() strerr_dieusage(100, USAGE) #define DATASIZE 63 -- cgit v1.2.3