summaryrefslogtreecommitdiff
path: root/src/instance
diff options
context:
space:
mode:
Diffstat (limited to 'src/instance')
-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
3 files changed, 23 insertions, 5 deletions
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 ;