From 955d4078d0709372129fb883d3ea4bd6d7ad735e Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Tue, 10 Jan 2023 01:06:48 +0000 Subject: Add s6-instance-list, s6-instance-status (no doc yet) Signed-off-by: Laurent Bercot --- src/instance/s6-instance-list.c | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/instance/s6-instance-list.c (limited to 'src/instance/s6-instance-list.c') diff --git a/src/instance/s6-instance-list.c b/src/instance/s6-instance-list.c new file mode 100644 index 0000000..20fff9e --- /dev/null +++ b/src/instance/s6-instance-list.c @@ -0,0 +1,52 @@ +/* ISC license. */ + +#include +#include + +#include +#include +#include +#include + +#include + +#define USAGE "s6-instance-list service" +#define dieusage() strerr_dieusage(100, USAGE) + +int main (int argc, char const *const *argv) +{ + DIR *dir ; + PROG = "s6-instance-list" ; + { + subgetopt l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "", &l) ; + if (opt == -1) break ; + switch (opt) + { + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + } + if (!argc) dieusage() ; + + s6_instance_chdirservice(argv[0]) ; + dir = opendir(".") ; + for (;;) + { + direntry *d ; + errno = 0 ; + d = readdir(dir) ; + if (!d) break ; + if (d->d_name[0] == '.') continue ; + if (buffer_puts(buffer_1, d->d_name) < 0 + || buffer_put(buffer_1, "\n", 1) < 0) + strerr_diefu1sys(111, "write to stdout") ; + } + if (errno) strerr_diefu3sys(111, "readdir ", argv[0], "/instance") ; + dir_close(dir) ; + if (!buffer_flush(buffer_1)) strerr_diefu1sys(111, "write to stdout") ; + return 0 ; +} -- cgit v1.2.3