summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-01-09 22:24:26 +0000
committerLaurent Bercot <ska@appnovation.com>2023-01-09 22:24:26 +0000
commitaeb3ad3d8cac8f1f085725711d2d8739b722b61b (patch)
tree2225c0b37c1a19161383c67bdb9043006e8b4fe0
parent724fc63f4736d620173e733a3b35c003a0d82ff8 (diff)
downloads6-aeb3ad3d8cac8f1f085725711d2d8739b722b61b.tar.xz
Next batch of fixes
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r--.gitignore3
-rw-r--r--doc/s6-instance-control.html2
-rw-r--r--doc/s6-instance-create.html9
-rw-r--r--doc/s6-instance-delete.html9
-rw-r--r--doc/s6-svc.html2
-rw-r--r--src/instance/s6-instance-control.c4
-rw-r--r--src/instance/s6-instance-create.c14
-rw-r--r--src/instance/s6-instance-delete.c10
-rw-r--r--src/libs6/s6_supervise_link_names.c3
-rw-r--r--src/supervision/s6-svc.c2
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
<h2> Interface </h2>
<pre>
- s6-instance-control [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T <em>timeout</em> ] [ -abqhkti12pcyoduDUxOr ] <em>servicedir</em> <em>name</em>
+ s6-instance-control [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T <em>timeout</em> ] [ -abqhkti12pcyroduDUxO ] <em>servicedir</em> <em>name</em>
</pre>
<ul>
diff --git a/doc/s6-instance-create.html b/doc/s6-instance-create.html
index c81dfe4..1aa0d4c 100644
--- a/doc/s6-instance-create.html
+++ b/doc/s6-instance-create.html
@@ -86,6 +86,15 @@ s6-instance-create adds a service directory to that tree and ensures it gets
supervised. </li>
<li> If the template for the service is logged, then s6-instance-create will
wait until supervisors have been spawned for both the instance and its logger. </li>
+ <li> s6-instance-create and <a href="s6-instance-delete.html">s6-instance-delete</a>
+are relatively expensive operations, because they have to recursively copy or
+delete directories and use the <a href="libs6/ftrigr.html">synchronization mechanism</a>
+with the instance supervisor, compared to
+<a href="s6-instance-control.html">s6-instance-control</a> 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 <a href="s6-instance-control.html">s6-instance-control</a> than it is to
+repeatedly create and delete it. </li>
</ul>
</body>
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. </li>
<li> If the template for the service is logged, then s6-instance-delete will
delete both the instance and its logger. </li>
+ <li> s6-instance-delete and <a href="s6-instance-create.html">s6-instance-create</a>
+are relatively expensive operations, because they have to recursively copy or
+delete directories and use the <a href="libs6/ftrigr.html">synchronization mechanism</a>
+with the instance supervisor, compared to
+<a href="s6-instance-control.html">s6-instance-control</a> 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 <a href="s6-instance-control.html">s6-instance-control</a> than it is to
+repeatedly create and delete it. </li>
</ul>
</body>
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.
<h2> Interface </h2>
<pre>
- s6-svc [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T <em>timeout</em> ] [ -abqhkti12pcyoduDUxOr ] <em>servicedir</em>
+ s6-svc [ -wu | -wU | -wd | -wD | -wr | -wR ] [ -T <em>timeout</em> ] [ -abqhkti12pcyroduDUxO ] <em>servicedir</em>
</pre>
<p>
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 <s6/config.h>
-#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 <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]) ;
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 <skalibs/tai.h>
#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>
+#include <skalibs/lolstdio.h>
#include <s6/ftrigr.h>
#include <s6/ftrigw.h>
@@ -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 <s6/config.h>
#include <s6/supervise.h>
-#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