summaryrefslogtreecommitdiff
path: root/src/libs6
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs6')
-rw-r--r--src/libs6/s6_svc_write.c13
-rw-r--r--src/libs6/s6_svc_writectl.c21
2 files changed, 30 insertions, 4 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 ;
+ }
}