From 321f8dd75df79a714b17a0f2cd16644ccc4febf9 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 10 Nov 2017 12:53:37 +0000 Subject: More accurate exit code and clearer error messages for s6-svc and s6-svscanctl --- src/libs6/s6_svc_writectl.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/libs6/s6_svc_writectl.c') 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 +#include +#include #include +#include +#include #include 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 ; + } } -- cgit v1.2.3