diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-01-09 11:09:14 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-01-09 11:09:14 +0000 |
commit | 09750ce3525129a676dec4f579aea3ad2eca1b19 (patch) | |
tree | acae6b5f47914d7ed85bbb8fe9780ed34a85cfd0 /src/instance/s6-instance-delete.c | |
parent | 191b46491407632f2431c46eab97dbf5543fa26d (diff) | |
download | s6-09750ce3525129a676dec4f579aea3ad2eca1b19.tar.xz |
Add instances implementation (still needs testing)
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/instance/s6-instance-delete.c')
-rw-r--r-- | src/instance/s6-instance-delete.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/instance/s6-instance-delete.c b/src/instance/s6-instance-delete.c new file mode 100644 index 0000000..fc1337a --- /dev/null +++ b/src/instance/s6-instance-delete.c @@ -0,0 +1,61 @@ +/* ISC license. */ + +#include <errno.h> +#include <stdint.h> +#include <string.h> +#include <unistd.h> + +#include <skalibs/bytestr.h> +#include <skalibs/types.h> +#include <skalibs/sgetopt.h> +#include <skalibs/tai.h> +#include <skalibs/strerr.h> +#include <skalibs/stralloc.h> +#include <skalibs/djbunix.h> + +#include <s6/supervise.h> + +#define USAGE "s6-instance-delete [ -X ] [ -t timeout ] service instancename" +#define dieusage() strerr_dieusage(100, USAGE) + +int main (int argc, char const *const *argv) +{ + tain tto = TAIN_INFINITE_RELATIVE ; + uint32_t options = 1 ; + PROG = "s6-instance-delete" ; + { + unsigned int t = 0 ; + subgetopt l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "Xt:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'X' : options &= ~1U ; break ; + case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + if (t) tain_from_millisecs(&tto, t) ; + } + 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) < 5) + strerr_dief1x(100, "invalid instance name") ; + + tain_now_set_stopwatch_g() ; + tain_add_g(&tto, &tto) ; + + { + size_t svlen = strlen(argv[0]) ; + char sc[svlen + 10] ; + 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]) ; + } + + return 0 ; +} |