summaryrefslogtreecommitdiff
path: root/src/libs6/ftrigw_notifyb_nosig.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-01-19 16:11:24 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-01-19 16:11:24 +0000
commit701540827e27a4f07ac725db3ce361d3be0c106f (patch)
tree98c4b2fb8ba8f69ef791feebdcd61cd5bca34140 /src/libs6/ftrigw_notifyb_nosig.c
parent83853a80eb18238796154164f9ea776b0c167ab7 (diff)
downloads6-701540827e27a4f07ac725db3ce361d3be0c106f.tar.xz
- added the s6_fdholder library to libs6. (Nothing useful yet.)
- fixed execline invocation in s6-log with slashpackage - integrated s6_svc_main.c's functionality into s6-svscanctl and deleted it - integrated Olivier Brunel's suggestions for wstat report in supervise/status - minor fixes to s6-supervise's status reports - separated sigaction calls in ftrigw_notifyb, this spares a few syscalls in s6-supervise - updated doc to reflect the changes - version bumped to 2.1.0.0 because API breakage (./finish, s6-svstat)
Diffstat (limited to 'src/libs6/ftrigw_notifyb_nosig.c')
-rw-r--r--src/libs6/ftrigw_notifyb_nosig.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/libs6/ftrigw_notifyb_nosig.c b/src/libs6/ftrigw_notifyb_nosig.c
new file mode 100644
index 0000000..0d7b565
--- /dev/null
+++ b/src/libs6/ftrigw_notifyb_nosig.c
@@ -0,0 +1,62 @@
+/* ISC license. */
+
+#include <unistd.h>
+#include <errno.h>
+#include <skalibs/direntry.h>
+#include <skalibs/allreadwrite.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/djbunix.h>
+#include "ftrig1.h"
+#include <s6/ftrigw.h>
+
+int ftrigw_notifyb_nosig (char const *path, char const *s, unsigned int len)
+{
+ unsigned int i = 0 ;
+ DIR *dir = opendir(path) ;
+ if (!dir) return -1 ;
+ {
+ unsigned int pathlen = str_len(path) ;
+ char tmp[pathlen + FTRIG1_PREFIXLEN + 45] ;
+ byte_copy(tmp, pathlen, path) ;
+ tmp[pathlen] = '/' ; tmp[pathlen + FTRIG1_PREFIXLEN + 44] = 0 ;
+ for (;;)
+ {
+ direntry *d ;
+ int fd ;
+ errno = 0 ;
+ d = readdir(dir) ;
+ if (!d) break ;
+ if (str_diffn(d->d_name, FTRIG1_PREFIX, FTRIG1_PREFIXLEN)) continue ;
+ if (str_len(d->d_name) != FTRIG1_PREFIXLEN + 43) continue ;
+ byte_copy(tmp + pathlen + 1, FTRIG1_PREFIXLEN + 43, d->d_name) ;
+ fd = open_write(tmp) ;
+ if (fd == -1)
+ {
+ if (errno == ENXIO) unlink(tmp) ;
+ }
+ else
+ {
+ register int r = fd_write(fd, s, len) ;
+ if ((r < 0) || (unsigned int)r < len)
+ {
+ if (errno == EPIPE) unlink(tmp) ;
+ /* what to do if EGAIN ? full fifo -> fix the reader !
+ There's a race condition in extreme cases though ;
+ but it's still better to be nonblocking - the writer
+ shouldn't get in trouble because of a bad reader. */
+ fd_close(fd) ;
+ }
+ else
+ {
+ fd_close(fd) ;
+ i++ ;
+ }
+ }
+ }
+ }
+ {
+ int e = errno ;
+ dir_close(dir) ;
+ return e ? (errno = e, -1) : (int)i ;
+ }
+}