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/libs6/s6_instance_chdirservice.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/libs6/s6_instance_chdirservice.c')
-rw-r--r-- | src/libs6/s6_instance_chdirservice.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/libs6/s6_instance_chdirservice.c b/src/libs6/s6_instance_chdirservice.c new file mode 100644 index 0000000..356ee20 --- /dev/null +++ b/src/libs6/s6_instance_chdirservice.c @@ -0,0 +1,26 @@ +/* ISC license. */ + +#include <string.h> +#include <unistd.h> + +#include <skalibs/strerr.h> +#include <skalibs/djbunix.h> + +#include <s6/supervise.h> + +void s6_instance_chdirservice (char const *s) +{ + int fd, r ; + size_t len = strlen(s) ; + char fn[len + 10] ; + if (!*s) strerr_dief1x(100, "invalid service path") ; + memcpy(fn, s, len) ; + memcpy(fn + len, "/instance", 10) ; + if (chdir(fn) == -1) strerr_diefu2sys(111, "chdir to ", fn) ; + fd = open_read(S6_SVSCAN_CTLDIR "/lock") ; + if (fd < 0) strerr_diefu3sys(111, "open ", fn, "/" S6_SVSCAN_CTLDIR "/lock") ; + r = fd_islocked(fd) ; + if (r < 0) strerr_diefu3sys(111, "check lock on ", fn, "/" S6_SVSCAN_CTLDIR "/lock") ; + if (!r) strerr_dief2x(1, "instanced service not running on ", s) ; + fd_close(fd) ; +} |