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 --- .gitignore | 3 +++ doc/s6-instance-control.html | 2 +- doc/s6-instance-create.html | 9 +++++++++ doc/s6-instance-delete.html | 9 +++++++++ doc/s6-svc.html | 2 +- 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 +- 10 files changed, 50 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 08ecbf7..4c96631 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,6 @@ /s6-setuidgid /s6-usertree-maker /s6-instance-maker +/s6-instance-create +/s6-instance-delete +/s6-instance-control diff --git a/doc/s6-instance-control.html b/doc/s6-instance-control.html index cd76688..b52819a 100644 --- a/doc/s6-instance-control.html +++ b/doc/s6-instance-control.html @@ -26,7 +26,7 @@ s6-instance-control sends commands to a running instance of an

Interface

-     s6-instance-control [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcyoduDUxOr ] servicedir name
+     s6-instance-control [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcyroduDUxO ] servicedir name
 
diff --git a/doc/s6-instance-delete.html b/doc/s6-instance-delete.html index 28eca9c..49530b2 100644 --- a/doc/s6-instance-delete.html +++ b/doc/s6-instance-delete.html @@ -66,6 +66,15 @@ on a supervision tree that is specific to the instanced service, and s6-instance-delete removes a service directory from that tree.
  • If the template for the service is logged, then s6-instance-delete will delete both the instance and its logger.
  • +
  • s6-instance-delete and s6-instance-create +are relatively expensive operations, because they have to recursively copy or +delete directories and use the synchronization mechanism +with the instance supervisor, compared to +s6-instance-control which only has to send +commands to already existing supervisors. If you are going to turn instances on and +off on a regular basis, it is more efficient to keep the instance existing and control +it with s6-instance-control than it is to +repeatedly create and delete it.
  • diff --git a/doc/s6-svc.html b/doc/s6-svc.html index b8d3c4d..4668a45 100644 --- a/doc/s6-svc.html +++ b/doc/s6-svc.html @@ -28,7 +28,7 @@ knowing their PIDs, and without using horrible hacks such as .pid files.

    Interface

    -     s6-svc [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcyoduDUxOr ] servicedir
    +     s6-svc [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T timeout ] [ -abqhkti12pcyroduDUxO ] servicedir
     

    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