diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-01-10 01:06:48 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-01-10 01:06:48 +0000 |
commit | 955d4078d0709372129fb883d3ea4bd6d7ad735e (patch) | |
tree | 04077179cce9eab1f9d4187c12c36c3e496146d6 /src/instance/s6-instance-list.c | |
parent | c026dea4c33adc3f18b9788cab4d6ce7d56345c8 (diff) | |
download | s6-955d4078d0709372129fb883d3ea4bd6d7ad735e.tar.xz |
Add s6-instance-list, s6-instance-status (no doc yet)
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/instance/s6-instance-list.c')
-rw-r--r-- | src/instance/s6-instance-list.c | 52 |
1 files changed, 52 insertions, 0 deletions
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 <errno.h> +#include <string.h> + +#include <skalibs/buffer.h> +#include <skalibs/strerr.h> +#include <skalibs/sgetopt.h> +#include <skalibs/direntry.h> + +#include <s6/supervise.h> + +#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 ; +} |