diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-11-10 12:53:37 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-11-10 12:53:37 +0000 |
commit | 321f8dd75df79a714b17a0f2cd16644ccc4febf9 (patch) | |
tree | 0763334456c8a5b2c2338634773f3b41082c102c /src | |
parent | 5aa544ac273ea5253682b63f9640f9da08073ef3 (diff) | |
download | s6-321f8dd75df79a714b17a0f2cd16644ccc4febf9.tar.xz |
More accurate exit code and clearer error messages for s6-svc and s6-svscanctl
Diffstat (limited to 'src')
-rw-r--r-- | src/libs6/s6_svc_write.c | 13 | ||||
-rw-r--r-- | src/libs6/s6_svc_writectl.c | 21 | ||||
-rw-r--r-- | src/supervision/s6-svc.c | 8 | ||||
-rw-r--r-- | src/supervision/s6-svscanctl.c | 10 |
4 files changed, 40 insertions, 12 deletions
diff --git a/src/libs6/s6_svc_write.c b/src/libs6/s6_svc_write.c index 3ebf3b4..70c3964 100644 --- a/src/libs6/s6_svc_write.c +++ b/src/libs6/s6_svc_write.c @@ -8,9 +8,16 @@ int s6_svc_write (char const *fifo, char const *data, size_t datalen) { int fd = open_write(fifo) ; - if (fd < 0) return (errno == ENXIO) ? 0 : -1 ; - else if (ndelay_off(fd) == -1) return -1 ; - else if (fd_write(fd, data, datalen) == -1) + if (fd < 0) switch (errno) + { + case ENXIO : return 0 ; + case ENOENT : + case ENOTDIR : + case EISDIR : return -2 ; + default : return -1 ; + } + if (ndelay_off(fd) == -1) return -1 ; + if (fd_write(fd, data, datalen) == -1) { fd_close(fd) ; return -1 ; diff --git a/src/libs6/s6_svc_writectl.c b/src/libs6/s6_svc_writectl.c index b4d8e15..c522923 100644 --- a/src/libs6/s6_svc_writectl.c +++ b/src/libs6/s6_svc_writectl.c @@ -1,16 +1,35 @@ /* ISC license. */ +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> #include <string.h> +#include <skalibs/djbunix.h> +#include <skalibs/unix-transactional.h> #include <s6/s6-supervise.h> int s6_svc_writectl (char const *service, char const *subdir, char const *s, size_t len) { size_t svlen = strlen(service) ; size_t sublen = strlen(subdir) ; + int r ; char fn[svlen + sublen + 10] ; memcpy(fn, service, svlen) ; fn[svlen] = '/' ; memcpy(fn + svlen + 1, subdir, sublen) ; memcpy(fn + svlen + 1 + sublen, "/control", 9) ; - return s6_svc_write(fn, s, len) ; + r = s6_svc_write(fn, s, len) ; + if (r != -2) return r ; + + /* Now we need to investigate what went wrong... */ + { + int fd, fdsub ; + fd = open(service, O_RDONLY | O_DIRECTORY) ; + if (fd < 0) return -1 ; + fdsub = open2_at(fd, subdir, O_RDONLY | O_DIRECTORY) ; + fd_close(fd) ; + if (fdsub < 0) return (errno == ENOENT) ? 0 : -2 ; + fd_close(fdsub) ; + return -2 ; + } } diff --git a/src/supervision/s6-svc.c b/src/supervision/s6-svc.c index 12a351e..d844b20 100644 --- a/src/supervision/s6-svc.c +++ b/src/supervision/s6-svc.c @@ -105,11 +105,11 @@ int main (int argc, char const *const *argv, char const *const *envp) newargv[m++] = 0 ; xpathexec_run(newargv[0], newargv, envp) ; } - else + else switch (s6_svc_writectl(argv[0], S6_SUPERVISE_CTLDIR, data + 1, datalen - 1)) { - int r = s6_svc_writectl(argv[0], S6_SUPERVISE_CTLDIR, data + 1, datalen - 1) ; - if (r < 0) strerr_diefu2sys(111, "control ", argv[0]) ; - else if (!r) strerr_diefu3x(100, "control ", argv[0], ": supervisor not listening") ; + case -1 : strerr_diefu2sys(111, "control ", argv[0]) ; + case -2 : strerr_dief3sys(100, "something is wrong with the ", argv[0], "/" S6_SUPERVISE_CTLDIR " directory. errno reported") ; + case 0 : strerr_diefu3x(100, "control ", argv[0], ": supervisor not listening") ; } return 0 ; } diff --git a/src/supervision/s6-svscanctl.c b/src/supervision/s6-svscanctl.c index 2794290..3339c67 100644 --- a/src/supervision/s6-svscanctl.c +++ b/src/supervision/s6-svscanctl.c @@ -13,7 +13,6 @@ int main (int argc, char const *const *argv) { char data[DATASIZE] ; unsigned int datalen = 0 ; - int r ; PROG = "s6-svscanctl" ; { subgetopt_t l = SUBGETOPT_ZERO ; @@ -51,8 +50,11 @@ int main (int argc, char const *const *argv) } if (!argc) dieusage() ; - r = s6_svc_writectl(argv[0], S6_SVSCAN_CTLDIR, data, datalen) ; - if (r < 0) strerr_diefu2sys(111, "control ", argv[0]) ; - else if (!r) strerr_diefu3x(100, "control ", argv[0], ": supervisor not listening") ; + switch (s6_svc_writectl(argv[0], S6_SVSCAN_CTLDIR, data, datalen)) + { + case -1 : strerr_diefu2sys(111, "control ", argv[0]) ; + case -2 : strerr_dief3sys(100, "something is wrong with the ", argv[0], "/" S6_SVSCAN_CTLDIR " directory. errno reported") ; + case 0 : strerr_diefu3x(100, "control ", argv[0], ": supervisor not listening") ; + } return 0 ; } |