aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs6
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs6')
-rwxr-xr-xsrc/libs6/deps-exe/s6-ftrigrd3
-rw-r--r--src/libs6/deps-lib/s68
-rw-r--r--src/libs6/ftrig1.h23
-rw-r--r--src/libs6/ftrig1_free.c25
-rw-r--r--src/libs6/ftrig1_make.c45
-rw-r--r--src/libs6/ftrigr-internal.h20
-rw-r--r--src/libs6/ftrigr1_zero.c5
-rw-r--r--src/libs6/ftrigr_ack.c19
-rw-r--r--src/libs6/ftrigr_check.c20
-rw-r--r--src/libs6/ftrigr_checksa.c45
-rw-r--r--src/libs6/ftrigr_end.c22
-rw-r--r--src/libs6/ftrigr_peek.c26
-rw-r--r--src/libs6/ftrigr_peek1.c14
-rw-r--r--src/libs6/ftrigr_release.c18
-rw-r--r--src/libs6/ftrigr_start.c10
-rw-r--r--src/libs6/ftrigr_startf.c11
-rw-r--r--src/libs6/ftrigr_subscribe.c51
-rw-r--r--src/libs6/ftrigr_unsubscribe.c37
-rw-r--r--src/libs6/ftrigr_update.c20
-rw-r--r--src/libs6/ftrigr_updateb.c68
-rw-r--r--src/libs6/ftrigr_wait_and.c28
-rw-r--r--src/libs6/ftrigr_wait_or.c25
-rw-r--r--src/libs6/ftrigr_zero.c5
-rw-r--r--src/libs6/ftrigw_clean.c20
-rw-r--r--src/libs6/ftrigw_notifyb_nosig.c11
-rw-r--r--src/libs6/s6-ftrigrd.c312
-rw-r--r--src/libs6/s6_compat_el_semicolon.c34
-rw-r--r--src/libs6/s6_supervise_link_names.c16
-rw-r--r--src/libs6/s6_supervise_unlink_names.c14
29 files changed, 352 insertions, 603 deletions
diff --git a/src/libs6/deps-exe/s6-ftrigrd b/src/libs6/deps-exe/s6-ftrigrd
index e6238ab..a11a5f4 100755
--- a/src/libs6/deps-exe/s6-ftrigrd
+++ b/src/libs6/deps-exe/s6-ftrigrd
@@ -1,5 +1,2 @@
-ftrig1_free.o
-ftrig1_make.o
-lskarnet
-${SOCKET_LIB}
${SYSCLOCK_LIB}
diff --git a/src/libs6/deps-lib/s6 b/src/libs6/deps-lib/s6
index 9b1d285..74a30a7 100644
--- a/src/libs6/deps-lib/s6
+++ b/src/libs6/deps-lib/s6
@@ -1,17 +1,15 @@
-ftrigr1_zero.o
-ftrigr_check.o
-ftrigr_checksa.o
ftrigr_ack.o
ftrigr_end.o
+ftrigr_peek.o
+ftrigr_peek1.o
+ftrigr_release.o
ftrigr_start.o
ftrigr_startf.o
ftrigr_subscribe.o
ftrigr_unsubscribe.o
ftrigr_update.o
-ftrigr_updateb.o
ftrigr_wait_and.o
ftrigr_wait_or.o
-ftrigr_zero.o
ftrigw_clean.o
ftrigw_fifodir_make.o
ftrigw_notify.o
diff --git a/src/libs6/ftrig1.h b/src/libs6/ftrig1.h
deleted file mode 100644
index 229de66..0000000
--- a/src/libs6/ftrig1.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* ISC license. */
-
-#ifndef FTRIG1_H
-#define FTRIG1_H
-
-#include <skalibs/stralloc.h>
-
-#define FTRIG1_PREFIX "ftrig1"
-#define FTRIG1_PREFIXLEN (sizeof FTRIG1_PREFIX - 1)
-
-typedef struct ftrig1_s ftrig1_t, *ftrig1_t_ref ;
-struct ftrig1_s
-{
- int fd ;
- int fdw ;
- stralloc name ;
-} ;
-#define FTRIG1_ZERO { .fd = -1, .fdw = -1, .name = STRALLOC_ZERO }
-
-extern int ftrig1_make (ftrig1_t *, char const *) ;
-extern void ftrig1_free (ftrig1_t *) ;
-
-#endif
diff --git a/src/libs6/ftrig1_free.c b/src/libs6/ftrig1_free.c
deleted file mode 100644
index 61c0d1d..0000000
--- a/src/libs6/ftrig1_free.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* ISC license. */
-
-#include <skalibs/posixplz.h>
-#include <skalibs/stralloc.h>
-#include <skalibs/djbunix.h>
-#include "ftrig1.h"
-
-void ftrig1_free (ftrig1_t *p)
-{
- if (p->name.s)
- {
- unlink_void(p->name.s) ;
- stralloc_free(&p->name) ;
- }
- if (p->fd >= 0)
- {
- fd_close(p->fd) ;
- p->fd = -1 ;
- }
- if (p->fdw >= 0)
- {
- fd_close(p->fdw) ;
- p->fdw = -1 ;
- }
-}
diff --git a/src/libs6/ftrig1_make.c b/src/libs6/ftrig1_make.c
deleted file mode 100644
index 5c38e4b..0000000
--- a/src/libs6/ftrig1_make.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/* ISC license. */
-
-#include <string.h>
-#include <stdio.h>
-#include <fcntl.h>
-
-#include <skalibs/posixplz.h>
-#include <skalibs/tai.h>
-#include <skalibs/stralloc.h>
-#include <skalibs/djbunix.h>
-
-#include "ftrig1.h"
-
-int ftrig1_make (ftrig1_t *f, char const *path)
-{
- ftrig1_t ff = FTRIG1_ZERO ;
- size_t pathlen = strlen(path) ;
- char tmp[pathlen + FTRIG1_PREFIXLEN + 36] ;
-
- memcpy(tmp, path, pathlen) ;
- tmp[pathlen] = '/' ; tmp[pathlen+1] = '.' ;
- memcpy(tmp + pathlen + 2, FTRIG1_PREFIX, FTRIG1_PREFIXLEN) ;
- tmp[pathlen + 2 + FTRIG1_PREFIXLEN] = ':' ;
- if (!timestamp(tmp + pathlen + 3 + FTRIG1_PREFIXLEN)) return 0 ;
- memcpy(tmp + pathlen + FTRIG1_PREFIXLEN + 28, ":XXXXXX", 8) ;
- ff.fd = mkptemp3(tmp, 0622, O_NONBLOCK|O_CLOEXEC) ;
- if (ff.fd == -1) return 0 ;
- ff.fdw = open_write(tmp) ;
- if (ff.fdw == -1) goto err1 ;
- if (!stralloc_ready(&ff.name, pathlen + FTRIG1_PREFIXLEN + 36)) goto err2 ;
- stralloc_copyb(&ff.name, tmp, pathlen + 1) ;
- stralloc_catb(&ff.name, tmp + pathlen + 2, FTRIG1_PREFIXLEN + 34) ;
- if (rename(tmp, ff.name.s) == -1) goto err3 ;
- *f = ff ;
- return 1 ;
-
- err3:
- stralloc_free(&ff.name) ;
- err2:
- fd_close(ff.fdw) ;
- err1:
- fd_close(ff.fd) ;
- unlink_void(tmp) ;
- return 0 ;
-}
diff --git a/src/libs6/ftrigr-internal.h b/src/libs6/ftrigr-internal.h
new file mode 100644
index 0000000..dc9e442
--- /dev/null
+++ b/src/libs6/ftrigr-internal.h
@@ -0,0 +1,20 @@
+/* ISC license. */
+
+#ifndef FTRIGR_INTERNAL_H
+#define FTRIGR_INTERNAL_H
+
+#include <skalibs/stralloc.h>
+
+#define FTRIGR_BANNER1 "ftrigr v2.0 (b)\n"
+#define FTRIGR_BANNER2 "ftrigr v2.0 (a)\n"
+
+typedef struct ftrigr_data_s ftrigr_data, *ftrigr_data_ref ;
+struct ftrigr_data_s
+{
+ int status ;
+ stralloc sa ;
+} ;
+#define FTRIGR_DATA_ZERO { .id = 0, .status = 0, .sa = STRALLOC_ZERO }
+
+
+#endif
diff --git a/src/libs6/ftrigr1_zero.c b/src/libs6/ftrigr1_zero.c
deleted file mode 100644
index 967b4e0..0000000
--- a/src/libs6/ftrigr1_zero.c
+++ /dev/null
@@ -1,5 +0,0 @@
-/* ISC license. */
-
-#include <s6/ftrigr.h>
-
-ftrigr1_t const ftrigr1_zero = FTRIGR1_ZERO ;
diff --git a/src/libs6/ftrigr_ack.c b/src/libs6/ftrigr_ack.c
index 5c9a9f3..ac5ee7c 100644
--- a/src/libs6/ftrigr_ack.c
+++ b/src/libs6/ftrigr_ack.c
@@ -1,17 +1,16 @@
/* ISC license. */
-#include <stdint.h>
+#include <errno.h>
+
#include <skalibs/genalloc.h>
+
#include <s6/ftrigr.h>
+#include "ftrigr-internal.h"
-void ftrigr_ack (ftrigr_t *a, size_t n)
+int ftrigr_ack (ftrigr *a, uint32_t id)
{
- size_t len = genalloc_len(uint16_t, &a->list) ;
- a->head += n ;
- if (a->head > len) a->head = len ;
- if (a->head == len)
- {
- a->head = 0 ;
- genalloc_setlen(uint16_t, &a->list, 0) ;
- }
+ ftrigr_data *p = genalloc_s(ftrigr_data, &a->data) + id ;
+ if (p->status && p->status != EAGAIN) return (errno = p->status, 0) ;
+ p->sa.len = 0 ;
+ return 1 ;
}
diff --git a/src/libs6/ftrigr_check.c b/src/libs6/ftrigr_check.c
deleted file mode 100644
index 30be701..0000000
--- a/src/libs6/ftrigr_check.c
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ISC license. */
-
-#include <errno.h>
-#include <skalibs/stralloc.h>
-#include <s6/ftrigr.h>
-
-int ftrigr_check (ftrigr_t *a, uint16_t id, char *c)
-{
- stralloc sa = STRALLOC_ZERO ;
- int r = ftrigr_checksa(a, id, &sa) ;
-
- if (r && sa.len)
- {
- int e = errno ;
- *c = sa.s[sa.len - 1] ;
- stralloc_free(&sa) ;
- errno = e ;
- }
- return r ;
-}
diff --git a/src/libs6/ftrigr_checksa.c b/src/libs6/ftrigr_checksa.c
deleted file mode 100644
index 6573182..0000000
--- a/src/libs6/ftrigr_checksa.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/* ISC license. */
-
-#include <errno.h>
-#include <skalibs/stralloc.h>
-#include <skalibs/gensetdyn.h>
-#include <s6/ftrigr.h>
-
-int ftrigr_checksa (ftrigr_t *a, uint16_t id, stralloc *sa)
-{
- ftrigr1_t *p ;
- if (!id--) return (errno = EINVAL, -1) ;
- p = GENSETDYN_P(ftrigr1_t, &a->data, id) ;
- if (!p) return (errno = EINVAL, -1) ;
- switch (p->state)
- {
- case FR1STATE_WAITACKDATA :
- {
- if (!stralloc_catb(sa, p->what.s, p->what.len)) return -1 ;
- stralloc_free(&p->what) ;
- *p = ftrigr1_zero ;
- gensetdyn_delete(&a->data, id) ;
- return 1 ;
- }
- case FR1STATE_LISTENING :
- {
- if (!p->what.len) break ;
- if (!stralloc_catb(sa, p->what.s, p->what.len)) return -1 ;
- p->what.len = 0 ;
- return 1 ;
- }
- case FR1STATE_WAITACK :
- {
- int e ;
- if (!stralloc_catb(sa, p->what.s, p->what.len - 1)) return -1 ;
- e = p->what.s[p->what.len - 1] ;
- stralloc_free(&p->what) ;
- *p = ftrigr1_zero ;
- gensetdyn_delete(&a->data, id) ;
- errno = e ;
- return -1 ;
- }
- default: return (errno = EINVAL, -1) ;
- }
- return 0 ;
-}
diff --git a/src/libs6/ftrigr_end.c b/src/libs6/ftrigr_end.c
index 555053f..5c0eb13 100644
--- a/src/libs6/ftrigr_end.c
+++ b/src/libs6/ftrigr_end.c
@@ -1,15 +1,21 @@
/* ISC license. */
-#include <stdint.h>
+#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
-#include <skalibs/gensetdyn.h>
-#include <skalibs/textclient.h>
+#include <skalibs/sassclient.h>
+
#include <s6/ftrigr.h>
+#include "ftrigr-internal.h"
+
+static void ftrigr_data_free (void *x)
+{
+ ftrigr_data *p = x ;
+ stralloc_free(&p->sa) ;
+}
-void ftrigr_end (ftrigr_ref a)
+void ftrigr_end (ftrigr *a)
{
- gensetdyn_free(&a->data) ;
- genalloc_free(uint16_t, &a->list) ;
- textclient_end(&a->connection) ;
- *a = ftrigr_zero ;
+ sassclient_end(&a->client) ;
+ a->data.len = a->data.a ;
+ genalloc_deepfree(ftrigr_data, &a->data, &ftrigr_data_free) ;
}
diff --git a/src/libs6/ftrigr_peek.c b/src/libs6/ftrigr_peek.c
new file mode 100644
index 0000000..155fce3
--- /dev/null
+++ b/src/libs6/ftrigr_peek.c
@@ -0,0 +1,26 @@
+/* ISC license. */
+
+#include <sys/uio.h>
+#include <errno.h>
+
+#include <skalibs/genalloc.h>
+
+#include <s6/ftrigr.h>
+#include "ftrigr-internal.h"
+
+int ftrigr_peek (ftrigr *a, uint32_t id, struct iovec *v)
+{
+ ftrigr_data *p = genalloc_s(ftrigr_data, &a->data) + id ;
+ switch (p->status)
+ {
+ case EAGAIN : return 0 ;
+ case 0 :
+ {
+ v->iov_base = p->sa.s ;
+ v->iov_len = p->sa.len ;
+ return 1 ;
+ }
+ default: break ;
+ }
+ return (errno = p->status, -1) ;
+}
diff --git a/src/libs6/ftrigr_peek1.c b/src/libs6/ftrigr_peek1.c
new file mode 100644
index 0000000..81059f7
--- /dev/null
+++ b/src/libs6/ftrigr_peek1.c
@@ -0,0 +1,14 @@
+/* ISC license. */
+
+#include <sys/uio.h>
+
+#include <s6/ftrigr.h>
+
+int ftrigr_peek1 (ftrigr *a, uint32_t id, char *c)
+{
+ struct iovec v ;
+ int r = ftrigr_peek(a, id, &v) ;
+ if (r <= 0) return r ;
+ *c = ((char *)v.iov_base)[v.iov_len - 1] ;
+ return 1 ;
+}
diff --git a/src/libs6/ftrigr_release.c b/src/libs6/ftrigr_release.c
new file mode 100644
index 0000000..fdcd9d0
--- /dev/null
+++ b/src/libs6/ftrigr_release.c
@@ -0,0 +1,18 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <errno.h>
+
+#include <skalibs/genalloc.h>
+#include <skalibs/sassclient.h>
+
+#include <s6/ftrigr.h>
+#include "ftrigr-internal.h"
+
+void ftrigr_release (ftrigr *a, uint32_t id)
+{
+ ftrigr_data *p = genalloc_s(ftrigr_data, &a->data) + id ;
+ sassclient_release(&a->client, id) ;
+ p->status = EINVAL ;
+ p->sa.len = 0 ;
+}
diff --git a/src/libs6/ftrigr_start.c b/src/libs6/ftrigr_start.c
index c4422dc..cf73573 100644
--- a/src/libs6/ftrigr_start.c
+++ b/src/libs6/ftrigr_start.c
@@ -1,9 +1,13 @@
/* ISC license. */
-#include <skalibs/textclient.h>
+#include <skalibs/tai.h>
+
#include <s6/ftrigr.h>
-int ftrigr_start (ftrigr_t *a, char const *path, tain const *deadline, tain *stamp)
+int ftrigr_start (ftrigr *a, unsigned int sec)
{
- return textclient_start(&a->connection, path, 0, FTRIGR_BANNER1, FTRIGR_BANNER1_LEN, FTRIGR_BANNER2, FTRIGR_BANNER2_LEN, deadline, stamp) ;
+ tain deadline = TAIN_INFINITE ;
+ if (!tain_now_set_stopwatch_g()) return 0 ;
+ if (sec) tain_addsec_g(&deadline, sec) ;
+ return ftrigr_startf_g(a, &deadline) ;
}
diff --git a/src/libs6/ftrigr_startf.c b/src/libs6/ftrigr_startf.c
index bc503ba..5ebf6ce 100644
--- a/src/libs6/ftrigr_startf.c
+++ b/src/libs6/ftrigr_startf.c
@@ -1,12 +1,13 @@
/* ISC license. */
-#include <skalibs/posixplz.h>
-#include <skalibs/textclient.h>
+#include <skalibs/sassclient.h>
+#include <s6/config.h>
#include <s6/ftrigr.h>
+#include "ftrigr-internal.h"
-int ftrigr_startf (ftrigr_t *a, tain const *deadline, tain *stamp)
+int ftrigr_startf (ftrigr *a, tain const *deadline, tain *stamp)
{
- static char const *const cargv[2] = { FTRIGRD_PROG, 0 } ;
- return textclient_startf(&a->connection, cargv, (char const *const *)environ, TEXTCLIENT_OPTION_WAITPID, FTRIGR_BANNER1, FTRIGR_BANNER1_LEN, FTRIGR_BANNER2, FTRIGR_BANNER2_LEN, deadline, stamp) ;
+ char const *argv[2] = { S6_LIBEXECPREFIX "s6-ftrigrd", 0 } ;
+ return sassclient_start(&a->client, argv, FTRIGR_BANNER1, FTRIGR_BANNER2, deadline, stamp) ;
}
diff --git a/src/libs6/ftrigr_subscribe.c b/src/libs6/ftrigr_subscribe.c
index 1dc86e7..eb1d365 100644
--- a/src/libs6/ftrigr_subscribe.c
+++ b/src/libs6/ftrigr_subscribe.c
@@ -2,41 +2,42 @@
#include <sys/uio.h>
#include <string.h>
-#include <stdint.h>
#include <errno.h>
-#include <skalibs/uint16.h>
-#include <skalibs/uint32.h>
-#include <skalibs/tai.h>
-#include <skalibs/stralloc.h>
-#include <skalibs/gensetdyn.h>
-#include <skalibs/textclient.h>
+
#include <s6/ftrigr.h>
+#include "ftrigr-internal.h"
+
+static int ftrigr_cb (char const *s, size_t len, uint32_t id, void *x)
+{
+ ftrigr_data *p = genalloc_s(ftrigr_data, (genalloc *)x) + id ;
+ if (!stralloc_catb(&p->sa, s, len)) return errno ;
+ p->status = 0 ;
+ return 0 ;
+}
-uint16_t ftrigr_subscribe (ftrigr_t *a, char const *path, char const *re, uint32_t options, tain const *deadline, tain *stamp)
+int ftrigr_subscribe (ftrigr *a, uint32_t *i, uint32_t flags, uint32_t timeout, char const *path, char const *re, tain const *deadline, tain *stamp)
{
+ ftrigr_data *p ;
+ uint32_t id ;
size_t pathlen = strlen(path) ;
size_t relen = strlen(re) ;
- ftrigr1_t ft = { .options = options, .state = FR1STATE_LISTENING, .what = STRALLOC_ZERO } ;
- uint32_t i ;
- char tmp[15] = "--L" ;
- struct iovec v[3] = { { .iov_base = tmp, .iov_len = 15 }, { .iov_base = (char *)path, .iov_len = pathlen + 1 }, { .iov_base = (char *)re, .iov_len = relen + 1 } } ;
- if (!gensetdyn_new(&a->data, &i)) return 0 ;
- if (i >= UINT16_MAX)
+
+ struct iovec v[2] =
{
- gensetdyn_delete(&a->data, i) ;
- return (errno = EMFILE, 0) ;
- }
- uint16_pack_big(tmp, (uint16_t)i) ;
- uint32_pack_big(tmp+3, options) ;
- uint32_pack_big(tmp+7, (uint32_t)pathlen) ;
- uint32_pack_big(tmp+11, (uint32_t)relen) ;
- if (!textclient_commandv(&a->connection, v, 3, deadline, stamp))
+ { .iov_base = (char *)path, .iov_len = pathlen + 1 },
+ { .iov_base = (char *)re, .iov_len = relen + 1 }
+ } ;
+ if (!sassclient_sendv(&a->client, &id, flags, timeout, 0, v, 2, &ftrigr_cb, &a->data, deadline, stamp)) return 0 ;
+ if (!genalloc_ready(ftrigr_data, &a->data, id + 1))
{
int e = errno ;
- gensetdyn_delete(&a->data, i) ;
+ sassclient_cancel(&a->client, id, deadline, stamp) ;
errno = e ;
return 0 ;
}
- *GENSETDYN_P(ftrigr1_t, &a->data, i) = ft ;
- return (uint16_t)(i+1) ;
+ p = genalloc_s(ftrigr_data, &a->data) + id ;
+ p->sa.len = 0 ;
+ p->status = EAGAIN ;
+ *i = id ;
+ return 1 ;
}
diff --git a/src/libs6/ftrigr_unsubscribe.c b/src/libs6/ftrigr_unsubscribe.c
index 8a716d5..9aa5595 100644
--- a/src/libs6/ftrigr_unsubscribe.c
+++ b/src/libs6/ftrigr_unsubscribe.c
@@ -1,33 +1,18 @@
/* ISC license. */
#include <errno.h>
-#include <skalibs/uint16.h>
-#include <skalibs/stralloc.h>
-#include <skalibs/gensetdyn.h>
-#include <skalibs/textclient.h>
+
+#include <skalibs/sassclient.h>
+
#include <s6/ftrigr.h>
+#include "ftrigr-internal.h"
-int ftrigr_unsubscribe (ftrigr_t *a, uint16_t i, tain const *deadline, tain *stamp)
+int ftrigr_unsubscribe (ftrigr *a, uint32_t id, tain const *deadline, tain *stamp)
{
- ftrigr1_t *p ;
- char pack[3] = "--U" ;
- if (!i--) return (errno = EINVAL, 0) ;
- p = GENSETDYN_P(ftrigr1_t, &a->data, i) ;
- if (!p) return (errno = EINVAL, 0) ;
- switch (p->state)
- {
- case FR1STATE_WAITACK :
- case FR1STATE_WAITACKDATA :
- {
- char dummy ;
- ftrigr_check(a, i+1, &dummy) ;
- return 1 ;
- }
- default : break ;
- }
- uint16_pack_big(pack, i) ;
- if (!textclient_command(&a->connection, pack, 3, deadline, stamp)) return 0 ;
- stralloc_free(&p->what) ;
- *p = ftrigr1_zero ;
- return gensetdyn_delete(&a->data, i) ;
+ ftrigr_data *p ;
+ if (!sassclient_cancel(&a->client, id, deadline, stamp)) return 0 ;
+ p = genalloc_s(ftrigr_data, &a->data) + id ;
+ p->sa.len = 0 ;
+ p->status = EINVAL ;
+ return 1 ;
}
diff --git a/src/libs6/ftrigr_update.c b/src/libs6/ftrigr_update.c
index 674d8cb..afae759 100644
--- a/src/libs6/ftrigr_update.c
+++ b/src/libs6/ftrigr_update.c
@@ -1,11 +1,25 @@
/* ISC license. */
#include <stdint.h>
+
#include <skalibs/genalloc.h>
+#include <skalibs/sassclient.h>
+
#include <s6/ftrigr.h>
+#include "ftrigr-internal.h"
-int ftrigr_update (ftrigr_t *a)
+int ftrigr_update (ftrigr *a)
{
- genalloc_setlen(uint16_t, &a->list, 0) ;
- return ftrigr_updateb(a) ;
+ int r = sassclient_update(&a->client) ;
+ if (r <= 0) return r ;
+ for (;;)
+ {
+ uint32_t id ;
+ int status ;
+ r = sassclient_ack(&a->client, &id, &status) ;
+ if (r == -1) return -1 ;
+ if (!r) break ;
+ genalloc_s(ftrigr_data, &a->data)[id].status = status ;
+ }
+ return 1 ;
}
diff --git a/src/libs6/ftrigr_updateb.c b/src/libs6/ftrigr_updateb.c
deleted file mode 100644
index 2a47e49..0000000
--- a/src/libs6/ftrigr_updateb.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/* ISC license. */
-
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <stdint.h>
-#include <errno.h>
-
-#include <skalibs/gccattributes.h>
-#include <skalibs/uint16.h>
-#include <skalibs/genalloc.h>
-#include <skalibs/gensetdyn.h>
-#include <skalibs/textclient.h>
-#include <s6/ftrigr.h>
-
-#include <skalibs/posixishard.h>
-
-static inline int appears (uint16_t, uint16_t const *, size_t) gccattr_pure ;
-
-static inline int appears (uint16_t id, uint16_t const *list, size_t len)
-{
- while (len) if (id == list[--len]) return 1 ;
- return 0 ;
-}
-
-static int msghandler (struct iovec const *v, void *context)
-{
- ftrigr_t *a = (ftrigr_t *)context ;
- ftrigr1_t *p ;
- int addit = 1 ;
- char const *s = v->iov_base ;
- uint16_t id ;
- if (v->iov_len != 4) return (errno = EPROTO, 0) ;
- uint16_unpack_big(s, &id) ;
- p = GENSETDYN_P(ftrigr1_t, &a->data, id) ;
- if (!p) return 1 ;
- if (p->state != FR1STATE_LISTENING) return (errno = EINVAL, 0) ;
- if (!genalloc_readyplus(uint16_t, &a->list, 1)) return 0 ;
- switch (s[2])
- {
- case 'd' :
- if (!stralloc_catb(&p->what, s + 3, 1)) return 0 ;
- p->state = FR1STATE_WAITACK ;
- break ;
- case '!' :
- if (!stralloc_catb(&p->what, s + 3, 1)) return 0 ;
- if (p->options & FTRIGR_REPEAT)
- {
- if (p->what.len > 1
- && appears(id+1, genalloc_s(uint16_t, &a->list), genalloc_len(uint16_t, &a->list)))
- addit = 0 ;
- }
- else p->state = FR1STATE_WAITACKDATA ;
- break ;
- default : return (errno = EPROTO, 0) ;
- }
- if (addit)
- {
- id++ ; genalloc_append(uint16_t, &a->list, &id) ;
- }
- return 1 ;
-}
-
-int ftrigr_updateb (ftrigr_t *a)
-{
- size_t curlen = genalloc_len(uint16_t, &a->list) ;
- int r = textclient_update(&a->connection, &msghandler, a) ;
- return r < 0 ? r : (int)(genalloc_len(uint16_t, &a->list) - curlen) ;
-}
diff --git a/src/libs6/ftrigr_wait_and.c b/src/libs6/ftrigr_wait_and.c
index ebdbde0..24e722f 100644
--- a/src/libs6/ftrigr_wait_and.c
+++ b/src/libs6/ftrigr_wait_and.c
@@ -1,27 +1,29 @@
/* ISC license. */
+#include <sys/uio.h>
#include <errno.h>
+
#include <skalibs/iopause.h>
+
#include <s6/ftrigr.h>
-int ftrigr_wait_and (ftrigr_t *a, uint16_t const *idlist, unsigned int n, tain const *deadline, tain *stamp)
+int ftrigr_wait_and (ftrigr *a, uint32_t const *list, unsigned int n, tain const *deadline, tain *stamp)
{
- iopause_fd x = { -1, IOPAUSE_READ, 0 } ;
- x.fd = ftrigr_fd(a) ;
- for (; n ; n--, idlist++)
+ iopause_fd x = { .fd = ftrigr_fd(a), .events = IOPAUSE_READ } ;
+ for (unsigned int i = 0 ; i < n ; i++)
{
for (;;)
{
- char dummy ;
- int r = ftrigr_check(a, *idlist, &dummy) ;
- if (r < 0) return r ;
- else if (r) break ;
+ struct iovec v ;
+ int r = ftrigr_peek(a, list[i], &v) ;
+ if (r == -1) return -1 ;
+ if (r) break ;
r = iopause_stamp(&x, 1, deadline, stamp) ;
- if (r < 0) return r ;
- else if (!r) return (errno = ETIMEDOUT, -1) ;
- else if (ftrigr_updateb(a) < 0) return -1 ;
+ if (r == -1) return -1 ;
+ if (!r) return (errno = ETIMEDOUT, -1) ;
+ if (ftrigr_update(a) == -1) return -1 ;
}
+ ftrigr_ack(a, list[i]) ;
}
-
- return 1 ;
+ return 0 ;
}
diff --git a/src/libs6/ftrigr_wait_or.c b/src/libs6/ftrigr_wait_or.c
index efe6e14..0ed41b7 100644
--- a/src/libs6/ftrigr_wait_or.c
+++ b/src/libs6/ftrigr_wait_or.c
@@ -1,32 +1,27 @@
/* ISC license. */
+#include <sys/uio.h>
#include <errno.h>
#include <skalibs/iopause.h>
#include <s6/ftrigr.h>
-#include <skalibs/posixishard.h>
-
-int ftrigr_wait_or (ftrigr_t *a, uint16_t const *idlist, unsigned int n, tain const *deadline, tain *stamp, char *c)
+int ftrigr_wait_or (ftrigr *a, uint32_t const *list, unsigned int n, struct iovec *v, tain const *deadline, tain *stamp)
{
- iopause_fd x = { -1, IOPAUSE_READ | IOPAUSE_EXCEPT, 0 } ;
- x.fd = ftrigr_fd(a) ;
- if (x.fd < 0) return -1 ;
+ iopause_fd x = { .fd = ftrigr_fd(a), .events = IOPAUSE_READ } ;
for (;;)
{
- unsigned int i = 0 ;
int r ;
- for (; i < n ; i++)
+ for (unsigned int i = 0 ; i < n ; i++)
{
- r = ftrigr_check(a, idlist[i], c) ;
- if (r < 0) return r ;
- else if (r) return i ;
+ r = ftrigr_peek(a, list[i], v) ;
+ if (r == -1) return -1 ;
+ if (r) return i ;
}
r = iopause_stamp(&x, 1, deadline, stamp) ;
- if (r < 0) return 0 ;
- else if (!r) return (errno = ETIMEDOUT, -1) ;
- else if (ftrigr_update(a) < 0) return -1 ;
+ if (r == -1) return -1 ;
+ if (!r) return (errno = ETIMEDOUT, -1) ;
+ if (ftrigr_update(a) == -1) return -1 ;
}
- return (errno = EPROTO, -1) ; /* can't happen */
}
diff --git a/src/libs6/ftrigr_zero.c b/src/libs6/ftrigr_zero.c
deleted file mode 100644
index b09ddb6..0000000
--- a/src/libs6/ftrigr_zero.c
+++ /dev/null
@@ -1,5 +0,0 @@
-/* ISC license. */
-
-#include <s6/ftrigr.h>
-
-ftrigr_t const ftrigr_zero = FTRIGR_ZERO ;
diff --git a/src/libs6/ftrigw_clean.c b/src/libs6/ftrigw_clean.c
index e540aba..301fd39 100644
--- a/src/libs6/ftrigw_clean.c
+++ b/src/libs6/ftrigw_clean.c
@@ -3,21 +3,22 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
+
+#include <skalibs/posixplz.h>
#include <skalibs/direntry.h>
#include <skalibs/djbunix.h>
-#include "ftrig1.h"
+
#include <s6/ftrigw.h>
int ftrigw_clean (char const *path)
{
size_t pathlen = strlen(path) ;
- int e = 0 ;
DIR *dir = opendir(path) ;
if (!dir) return 0 ;
{
- char tmp[pathlen + FTRIG1_PREFIXLEN + 35] ;
+ char tmp[pathlen + 41] ;
memcpy(tmp, path, pathlen) ;
- tmp[pathlen] = '/' ; tmp[pathlen + FTRIG1_PREFIXLEN + 34] = 0 ;
+ tmp[pathlen] = '/' ; tmp[pathlen + 40] = 0 ;
for (;;)
{
direntry *d ;
@@ -25,15 +26,14 @@ int ftrigw_clean (char const *path)
errno = 0 ;
d = readdir(dir) ;
if (!d) break ;
- if (strncmp(d->d_name, FTRIG1_PREFIX, FTRIG1_PREFIXLEN)) continue ;
- if (strlen(d->d_name) != FTRIG1_PREFIXLEN + 33) continue ;
- memcpy(tmp + pathlen + 1, d->d_name, FTRIG1_PREFIXLEN + 33) ;
+ if (strncmp(d->d_name, "ftrig1", 6)) continue ;
+ if (strlen(d->d_name) != 39) continue ;
+ memcpy(tmp + pathlen + 1, d->d_name, 39) ;
fd = open_write(tmp) ;
if (fd >= 0) fd_close(fd) ;
- else if ((errno == ENXIO) && (unlink(tmp) < 0)) e = errno ;
+ else if (errno == ENXIO) unlink_void(tmp) ;
}
}
dir_close(dir) ;
- if (errno) e = errno ;
- return e ? (errno = e, 0) : 1 ;
+ return !errno ;
}
diff --git a/src/libs6/ftrigw_notifyb_nosig.c b/src/libs6/ftrigw_notifyb_nosig.c
index 103e2b9..06abae6 100644
--- a/src/libs6/ftrigw_notifyb_nosig.c
+++ b/src/libs6/ftrigw_notifyb_nosig.c
@@ -10,7 +10,6 @@
#include <skalibs/djbunix.h>
#include <s6/ftrigw.h>
-#include "ftrig1.h"
int ftrigw_notifyb_nosig (char const *path, char const *s, size_t len)
{
@@ -19,10 +18,10 @@ int ftrigw_notifyb_nosig (char const *path, char const *s, size_t len)
if (!dir) return -1 ;
{
size_t pathlen = strlen(path) ;
- char tmp[pathlen + FTRIG1_PREFIXLEN + 35] ;
+ char tmp[pathlen + 41] ;
memcpy(tmp, path, pathlen) ;
tmp[pathlen] = '/' ;
- tmp[pathlen + FTRIG1_PREFIXLEN + 34] = 0 ;
+ tmp[pathlen + 40] = 0 ;
for (;;)
{
direntry *d ;
@@ -30,9 +29,9 @@ int ftrigw_notifyb_nosig (char const *path, char const *s, size_t len)
errno = 0 ;
d = readdir(dir) ;
if (!d) break ;
- if (strncmp(d->d_name, FTRIG1_PREFIX ":@", FTRIG1_PREFIXLEN + 2)) continue ;
- if (strlen(d->d_name) != FTRIG1_PREFIXLEN + 33) continue ;
- memcpy(tmp + pathlen + 1, d->d_name, FTRIG1_PREFIXLEN + 33) ;
+ if (strncmp(d->d_name, "ftrig1:@", 8)) continue ;
+ if (strlen(d->d_name) != 39) continue ;
+ memcpy(tmp + pathlen + 1, d->d_name, 39) ;
fd = open_write(tmp) ;
if (fd == -1)
{
diff --git a/src/libs6/s6-ftrigrd.c b/src/libs6/s6-ftrigrd.c
index 5b5ffd9..a037e31 100644
--- a/src/libs6/s6-ftrigrd.c
+++ b/src/libs6/s6-ftrigrd.c
@@ -1,293 +1,207 @@
/* ISC license. */
-#include <sys/uio.h>
#include <string.h>
#include <stdint.h>
+#include <unistd.h>
#include <errno.h>
+#include <fcntl.h>
#include <signal.h>
#include <regex.h>
+#include <stdio.h>
#include <skalibs/posixplz.h>
-#include <skalibs/types.h>
#include <skalibs/allreadwrite.h>
-#include <skalibs/error.h>
-#include <skalibs/strerr.h>
#include <skalibs/buffer.h>
-#include <skalibs/alloc.h>
+#include <skalibs/strerr.h>
#include <skalibs/stralloc.h>
-#include <skalibs/genalloc.h>
#include <skalibs/sig.h>
#include <skalibs/tai.h>
#include <skalibs/djbunix.h>
#include <skalibs/iopause.h>
-#include <skalibs/textmessage.h>
-#include <skalibs/textclient.h>
+#include <skalibs/sassserver.h>
-#include "ftrig1.h"
-#include <s6/ftrigr.h>
+#include "ftrigr-internal.h"
#include <skalibs/posixishard.h>
#define FTRIGRD_MAXREADS 32
-#define FTRIGRD_BUFSIZE 16
+#define FTRIGRD_BUFSIZE 32
#define dienomem() strerr_diefu1sys(111, "stralloc_catb")
typedef struct ftrigio_s ftrigio, *ftrigio_ref ;
struct ftrigio_s
{
+ ftrigio_ref prev ;
+ ftrigio_ref next ;
unsigned int xindex ;
- ftrig1_t trig ;
+ uint32_t id ;
+ uint32_t flags ;
buffer b ;
- regex_t re ;
+ char buf[FTRIGRD_BUFSIZE] ;
+ int fdw ;
+ size_t start ;
stralloc sa ;
- uint32_t options ;
- uint16_t id ; /* given by client */
+ regex_t re ;
} ;
-#define FTRIGIO_ZERO { .xindex = 0, .trig = FTRIG1_ZERO, .b = BUFFER_INIT(0, -1, 0, 0), .buf = "", .sa = STRALLOC_ZERO, .options = 0, .id = 0 }
+#define FTRIGIO_ZERO { .prev = 0, .next = 0, .xindex = 0, .id = 0, .flags = 0, .b = BUFFER_INIT(0, -1, 0, 0), .buf = "", .fdw = -1, .start = 0, .sa = STRALLOC_ZERO }
-static genalloc g = GENALLOC_ZERO ; /* ftrigio */
+static ftrigio ftrigio_head = { .prev = &ftrigio_head, .next = &ftrigio_head, .start = 0, .sa = STRALLOC_ZERO } ;
+#define numio (ftrigio_head.start)
-static void ftrigio_free (ftrigio *p)
+static void cleanup (void *x)
{
- alloc_free(p->b.c.x) ;
- ftrig1_free(&p->trig) ;
- stralloc_free(&p->sa) ;
- regfree(&p->re) ;
+ (void)x ;
+ for (ftrigio *p = ftrigio_head.next ; p != &ftrigio_head ; p = p->next)
+ unlink_void(p->sa.s) ;
}
-static void cleanup (void)
+static void ftrigio_remove (void *x)
{
- size_t n = genalloc_len(ftrigio, &g) ;
- ftrigio *a = genalloc_s(ftrigio, &g) ;
- for (size_t i = 0 ; i < n ; i++) ftrigio_free(a + i) ;
- genalloc_setlen(ftrigio, &g, 0) ;
+ ftrigio *p = x ;
+ p->next->prev = p->prev ;
+ p->prev->next = p->next ;
+ numio-- ;
+ p->prev = p->next = 0 ;
+ unlink_void(p->sa.s) ;
+ fd_close(p->fdw) ;
+ fd_close(buffer_fd(&p->b)) ;
+ p->sa.len = 0 ;
+ regfree(&p->re) ;
}
-static void trig (uint16_t id, char what, char info)
+static int ftrigio_add (void *x, uint32_t id, uint32_t flags, uint32_t opcode, char const *s, size_t len)
{
- char pack[4] ;
- uint16_pack_big(pack, id) ;
- pack[2] = what ; pack[3] = info ;
- if (!textmessage_put(textmessage_sender_x, pack, 4))
- {
- cleanup() ;
- strerr_diefu1sys(111, "build answer") ;
- }
-}
+ ftrigio *p = x ;
+ size_t pathlen ;
+ if (len < 3 || s[len - 1]) return EPROTO ;
+ pathlen = strlen(s) ;
+ if (pathlen + 1 >= len) return EPROTO ;
+ p->start = pathlen + 41 ;
+ if (!stralloc_ready(&p->sa, p->start)) { cleanup(0) ; dienomem() ; }
-static void answer (unsigned char c)
-{
- if (!textmessage_put(textmessage_sender_1, (char *)&c, 1))
{
- cleanup() ;
- strerr_diefu1sys(111, "textmessage_put") ;
+ char tmp[p->start + 1] ;
+ int r = skalibs_regcomp(&p->re, s + pathlen + 1, REG_EXTENDED) ;
+ if (r) return r == REG_ESPACE ? ENOMEM : EINVAL ;
+ memcpy(tmp, s, pathlen) ;
+ memcpy(tmp + pathlen, "/.ftrig1:", 9) ;
+ if (!timestamp(tmp + pathlen + 9)) goto err0 ;
+ memcpy(tmp + pathlen + 34, ":XXXXXX", 8) ;
+ r = mkptemp3(tmp, 0622, O_NONBLOCK | O_CLOEXEC) ;
+ if (r == -1) goto err0 ;
+ buffer_init(&p->b, &buffer_read, r, p->buf, FTRIGRD_BUFSIZE) ;
+ p->fdw = open_write(tmp) ;
+ if (p->fdw == -1) { unlink_void(tmp) ; goto err1 ; }
+ stralloc_copyb(&p->sa, tmp, pathlen + 1) ;
+ stralloc_catb(&p->sa, tmp + pathlen + 2, 40) ;
+ if (rename(tmp, p->sa.s) == -1) { unlink_void(tmp) ; goto err2 ; }
}
-}
+
+ p->id = id ;
+ p->flags = flags ;
+ p->prev = &ftrigio_head ;
+ p->next = ftrigio_head.next ;
+ ftrigio_head.next = p ;
+ numio++ ;
+ (void)opcode ;
+ return 0 ;
-static void ftrigio_remove (size_t i)
-{
- size_t n = genalloc_len(ftrigio, &g) ;
- ftrigio *a = genalloc_s(ftrigio, &g) ;
- ftrigio_free(a + i) ;
- a[i] = a[--n] ;
- genalloc_setlen(ftrigio, &g, n) ;
+ err2:
+ fd_close(p->fdw) ;
+ err1:
+ fd_close(buffer_fd(&p->b)) ;
+ err0:
+ regfree(&p->re) ;
+ return errno ;
}
-static inline int ftrigio_read (ftrigio *p)
+static inline int ftrigio_read (sassserver *a, ftrigio *p)
{
unsigned int i = FTRIGRD_MAXREADS ;
while (i--)
{
- regmatch_t pmatch ;
size_t blen ;
ssize_t r = sanitize_read(buffer_fill(&p->b)) ;
if (!r) break ;
- if (r < 0) return (trig(p->id, 'd', errno), 0) ;
- blen = buffer_len(&p->b) ;
- if (!stralloc_readyplus(&p->sa, blen+1))
+ if (r == -1)
{
- cleanup() ;
- dienomem() ;
+ sassserver_async_failure(a, p->id, errno) ;
+ return 0 ;
}
+ blen = buffer_len(&p->b) ;
+ if (!stralloc_readyplus(&p->sa, blen+1)) { cleanup(0) ; dienomem() ; }
buffer_getnofill(&p->b, p->sa.s + p->sa.len, blen) ;
p->sa.len += blen ;
p->sa.s[p->sa.len] = 0 ;
- while (!regexec(&p->re, p->sa.s, 1, &pmatch, REG_NOTBOL | REG_NOTEOL))
- {
- trig(p->id, '!', p->sa.s[pmatch.rm_eo - 1]) ;
- if (!(p->options & FTRIGR_REPEAT)) return 0 ;
- memmove(p->sa.s, p->sa.s + pmatch.rm_eo, p->sa.len + 1 - pmatch.rm_eo) ;
- p->sa.len -= pmatch.rm_eo ;
- }
- }
- return 1 ;
-}
-
-static int parse_protocol (struct iovec const *v, void *context)
-{
- char const *s = v->iov_base ;
- uint16_t id ;
- if (v->iov_len < 3)
- {
- cleanup() ;
- strerr_dief1x(100, "invalid client request") ;
- }
- uint16_unpack_big(s, &id) ;
- switch (s[2])
- {
- case 'U' : /* unsubscribe */
- {
- size_t n = genalloc_len(ftrigio, &g) ;
- size_t i = 0 ;
- for (; i < n ; i++) if (genalloc_s(ftrigio, &g)[i].id == id) break ;
- if (i < n)
- {
- ftrigio_remove(i) ;
- answer(0) ;
- }
- else answer(EINVAL) ;
- break ;
- }
- case 'L' : /* subscribe to path and match re */
+ if (!regexec(&p->re, p->sa.s + p->start, 0, 0, 0))
{
- size_t n = genalloc_len(ftrigio, &g) ;
- ftrigio *p ;
- char *x ;
- uint32_t options, pathlen, relen ;
- int r ;
- if (v->iov_len < 19)
- {
- answer(EPROTO) ;
- break ;
- }
- uint32_unpack_big(s + 3, &options) ;
- uint32_unpack_big(s + 7, &pathlen) ;
- uint32_unpack_big(s + 11, &relen) ;
- if (((pathlen + relen + 17) != v->iov_len) || s[15 + pathlen] || s[v->iov_len - 1])
- {
- answer(EPROTO) ;
- break ;
- }
- if (!genalloc_readyplus(ftrigio, &g, 1))
- {
- answer(ENOMEM) ;
- break ;
- }
- x = alloc(FTRIGRD_BUFSIZE) ;
- if (!x)
- {
- answer(ENOMEM) ;
- break ;
- }
- p = genalloc_s(ftrigio, &g) + n ;
- r = skalibs_regcomp(&p->re, s + 16 + pathlen, REG_EXTENDED) ;
- if (r)
- {
- alloc_free(x) ;
- answer(r == REG_ESPACE ? ENOMEM : EINVAL) ;
- break ;
- }
- if (!ftrig1_make(&p->trig, s + 15))
- {
- regfree(&p->re) ;
- alloc_free(x) ;
- answer(errno) ;
- break ;
- }
- buffer_init(&p->b, &buffer_read, p->trig.fd, x, FTRIGRD_BUFSIZE) ;
- p->options = options ;
- p->id = id ;
- p->sa = stralloc_zero ;
- genalloc_setlen(ftrigio, &g, n+1) ;
- answer(0) ;
- break ;
+ sassserver_async_success(a, p->id, p->flags, p->sa.s + p->start, p->sa.len - p->start) ;
+ p->sa.len = p->start ;
}
- default :
- cleanup() ;
- strerr_dief1x(100, "invalid client request") ;
}
- (void)context ;
return 1 ;
}
int main (void)
{
+ sassserver a = SASSSERVER_ZERO ;
+ int r = 0 ;
PROG = "s6-ftrigrd" ;
if (ndelay_on(0) == -1 || ndelay_on(1) == -1)
strerr_diefu1sys(111, "make fds nonblocking") ;
if (!sig_altignore(SIGPIPE))
strerr_diefu1sys(111, "ignore SIGPIPE") ;
+ if (!tain_now_set_stopwatch_g())
+ strerr_diefu1sys(111, "tain_now_set_stopwatch") ;
{
tain deadline ;
- tain_now_set_stopwatch_g() ;
- tain_addsec_g(&deadline, 2) ;
- if (!textclient_server_01x_init_g(FTRIGR_BANNER1, FTRIGR_BANNER1_LEN, FTRIGR_BANNER2, FTRIGR_BANNER2_LEN, &deadline))
- strerr_diefu1sys(111, "sync with client") ;
+ tain_addsec_g(&deadline, 5) ;
+ sassserver_init_g(&a, FTRIGR_BANNER1, FTRIGR_BANNER2, &ftrigio_add, &ftrigio_remove, sizeof(ftrigio), &cleanup, 0, &deadline) ;
}
- for (;;)
+ while (!r)
{
- size_t n = genalloc_len(ftrigio, &g) ;
- size_t i = 0 ;
- iopause_fd x[3 + n] ;
+ tain deadline = TAIN_INFINITE ;
+ iopause_fd x[3 + numio] ;
+
+ sassserver_prepare_iopause(&a, x, &deadline) ;
- x[0].fd = 0 ; x[0].events = IOPAUSE_EXCEPT | IOPAUSE_READ ;
- x[1].fd = 1 ; x[1].events = IOPAUSE_EXCEPT | (textmessage_sender_isempty(textmessage_sender_1) ? 0 : IOPAUSE_WRITE) ;
- x[2].fd = textmessage_sender_fd(textmessage_sender_x) ;
- x[2].events = IOPAUSE_EXCEPT | (textmessage_sender_isempty(textmessage_sender_x) ? 0 : IOPAUSE_WRITE) ;
- for (; i < n ; i++)
+ for (ftrigio *p = ftrigio_head.next ; p != &ftrigio_head ; p = p->next, r++)
{
- ftrigio *p = genalloc_s(ftrigio, &g) + i ;
- p->xindex = 3+i ;
- x[3+i].fd = p->trig.fd ;
- x[3+i].events = IOPAUSE_READ ;
+ p->xindex = 3+r ;
+ x[3+r].fd = buffer_fd(&p->b) ;
+ x[3+r].events = IOPAUSE_READ ;
}
- if (iopause(x, 3 + n, 0, 0) < 0)
+ r = iopause_g(x, 3 + numio, &deadline) ;
+ if (r == -1)
{
- cleanup() ;
+ cleanup(0) ;
strerr_diefu1sys(111, "iopause") ;
}
-
- /* client closed */
- if ((x[0].revents | x[1].revents) & IOPAUSE_EXCEPT) break ;
-
- /* client is reading */
- if (x[1].revents & IOPAUSE_WRITE)
- if (!textmessage_sender_flush(textmessage_sender_1) && !error_isagain(errno))
- {
- cleanup() ;
- strerr_diefu1sys(111, "flush stdout") ;
- }
- if (x[2].revents & IOPAUSE_WRITE)
- if (!textmessage_sender_flush(textmessage_sender_x) && !error_isagain(errno))
- {
- cleanup() ;
- return 1 ;
- }
-
- /* scan listening ftrigs */
- for (i = 0 ; i < genalloc_len(ftrigio, &g) ; i++)
+ if (!r)
{
- ftrigio *p = genalloc_s(ftrigio, &g) + i ;
- if (x[p->xindex].revents & IOPAUSE_READ)
- if (!ftrigio_read(p)) ftrigio_remove(i--) ;
+ sassserver_timeout(&a) ;
+ continue ;
}
- /* client is writing */
- if (!textmessage_receiver_isempty(textmessage_receiver_0) || x[0].revents & IOPAUSE_READ)
+ sassserver_write_event(&a, x) ;
+
+ for (ftrigio *p = ftrigio_head.next ; p != &ftrigio_head ; p = p->next) if (x[p->xindex].revents & IOPAUSE_READ)
{
- if (textmessage_handle(textmessage_receiver_0, &parse_protocol, 0) < 0)
+ if (!ftrigio_read(&a, p))
{
- if (errno == EPIPE) break ; /* normal exit */
- cleanup() ;
- strerr_diefu1sys(111, "handle messages from client") ;
+ p = p->prev ;
+ ftrigio_remove(p->next) ;
}
}
+
+ r = sassserver_read_event(&a, x) ;
}
- cleanup() ;
- return 0 ;
+
+ cleanup(0) ;
+ _exit(0) ;
}
diff --git a/src/libs6/s6_compat_el_semicolon.c b/src/libs6/s6_compat_el_semicolon.c
index fe4787e..8d214dd 100644
--- a/src/libs6/s6_compat_el_semicolon.c
+++ b/src/libs6/s6_compat_el_semicolon.c
@@ -25,30 +25,26 @@ static unsigned int el_getstrict (void)
int s6_compat_el_semicolon (char const **argv)
{
static unsigned int nblock = 0 ;
- int argc1 = 0 ;
+ unsigned int strict = el_getstrict() ;
nblock++ ;
- for (;; argc1++, argv++)
+ unsigned int i = 0 ;
+ for (; argv[i] ; i++)
{
- char const *arg = *argv ;
- if (!arg) return argc1 + 1 ;
- if (!arg[0]) return argc1 ;
- else if (arg[0] == ' ') ++*argv ;
- else
+ if (!argv[i][0]) return i ;
+ else if (argv[i][0] == ' ') argv[i]++ ;
+ else if (strict)
{
- unsigned int strict = el_getstrict() ;
- if (strict)
- {
- char fmt1[UINT_FMT] ;
- char fmt2[UINT_FMT] ;
- fmt1[uint_fmt(fmt1, nblock)] = 0 ;
- fmt2[uint_fmt(fmt2, (unsigned int)argc1)] = 0 ;
- if (strict >= 2)
- strerr_dief6x(100, "unquoted argument ", arg, " at block ", fmt1, " position ", fmt2) ;
- else
- strerr_warnw6x("unquoted argument ", arg, " at block ", fmt1, " position ", fmt2) ;
- }
+ char fmt1[UINT_FMT] ;
+ char fmt2[UINT_FMT] ;
+ fmt1[uint_fmt(fmt1, nblock)] = 0 ;
+ fmt2[uint_fmt(fmt2, i)] = 0 ;
+ if (strict >= 2)
+ strerr_dief6x(100, "unquoted argument ", argv[i], " at block ", fmt1, " position ", fmt2) ;
+ else
+ strerr_warnw6x("unquoted argument ", argv[i], " at block ", fmt1, " position ", fmt2) ;
}
}
+ return i + 1 ;
}
#endif
diff --git a/src/libs6/s6_supervise_link_names.c b/src/libs6/s6_supervise_link_names.c
index de8e5c5..1002cc4 100644
--- a/src/libs6/s6_supervise_link_names.c
+++ b/src/libs6/s6_supervise_link_names.c
@@ -22,19 +22,19 @@ static inline void do_unlink (char const *scdir, char const *const *names, size_
s6_supervise_unlink(scdir, names[i], killopts) ;
}
-static uint16_t registerit (ftrigr_t *a, char *fn, size_t len, gid_t gid, uint32_t options, tain const *deadline, tain *stamp)
+static int registerit (ftrigr *a, uint32_t *id, char *fn, size_t len, gid_t gid, uint32_t options, tain const *deadline, tain *stamp)
{
if (options & 4)
{
int fd ;
memcpy(fn + len, "/down", 6) ;
fd = open_trunc(fn) ;
- if (fd < 0) return 0 ;
+ if (fd == -1) return 0 ;
fd_close(fd) ;
}
memcpy(fn + len, "/" S6_SUPERVISE_EVENTDIR, 1 + sizeof(S6_SUPERVISE_EVENTDIR)) ;
if (!ftrigw_fifodir_make(fn, gid, options & 1)) return 0 ;
- return ftrigr_subscribe(a, fn, "s", 0, deadline, stamp) ;
+ return ftrigr_subscribe(a, id, 0, 0, fn, "s", deadline, stamp) ;
}
/*
@@ -86,7 +86,7 @@ int s6_supervise_link_names (char const *scdir, char const *const *servicedirs,
}
{
- ftrigr_t a = FTRIGR_ZERO ;
+ ftrigr a = FTRIGR_ZERO ;
stralloc rpsa = STRALLOC_ZERO ;
gid_t gid = options & 2 ? -1 : getegid() ;
size_t scdirlen = strlen(scdir) ;
@@ -94,7 +94,7 @@ int s6_supervise_link_names (char const *scdir, char const *const *servicedirs,
size_t i = 0 ;
uint32_t killopts = 0 ;
int r ;
- uint16_t ids[ntotal] ;
+ uint32_t ids[ntotal] ;
char lname[scdirlen + maxnlen + 7] ;
char fn[maxlen + 5 + (sizeof(S6_SUPERVISE_EVENTDIR) > 5 ? sizeof(S6_SUPERVISE_EVENTDIR) : 5)] ;
if (!ftrigr_startf(&a, deadline, stamp)) return -1 ;
@@ -108,13 +108,11 @@ int s6_supervise_link_names (char const *scdir, char const *const *servicedirs,
memcpy(fn, servicedirs[i], len) ;
if (!h)
{
- ids[m] = registerit(&a, fn, len, gid, options, deadline, stamp) ;
- if (!ids[m++]) goto err ;
+ if (!registerit(&a, ids + m++, fn, len, gid, options, deadline, stamp)) goto err ;
if (bitarray_peek(logged, i))
{
memcpy(fn + len, "/log", 4) ;
- ids[m] = registerit(&a, fn, len + 4, gid, options, deadline, stamp) ;
- if (!ids[m++]) goto err ;
+ if (!registerit(&a, ids + m++, fn, len + 4, gid, options, deadline, stamp)) goto err ;
}
}
fn[len] = 0 ;
diff --git a/src/libs6/s6_supervise_unlink_names.c b/src/libs6/s6_supervise_unlink_names.c
index a0b424d..d8bb4e0 100644
--- a/src/libs6/s6_supervise_unlink_names.c
+++ b/src/libs6/s6_supervise_unlink_names.c
@@ -12,10 +12,10 @@
#include <s6/ftrigr.h>
#include <s6/supervise.h>
-static uint16_t registerit (ftrigr_t *a, char *fn, size_t len, tain const *deadline, tain *stamp)
+static int registerit (ftrigr *a, uint32_t *id, char *fn, size_t len, tain const *deadline, tain *stamp)
{
memcpy(fn + len, "/" S6_SUPERVISE_EVENTDIR, sizeof(S6_SUPERVISE_EVENTDIR) + 1) ;
- return ftrigr_subscribe(a, fn, "x", 0, deadline, stamp) ;
+ return ftrigr_subscribe(a, id, 0, 0, fn, "x", deadline, stamp) ;
}
/*
@@ -62,9 +62,9 @@ int s6_supervise_unlink_names (char const *scdir, char const *const *names, size
}
{
- ftrigr_t a = FTRIGR_ZERO ;
+ ftrigr a = FTRIGR_ZERO ;
unsigned int m = 0 ;
- uint16_t ids[ntotal] ;
+ uint32_t ids[ntotal] ;
if (options & 1 && !ftrigr_startf(&a, deadline, stamp)) return -1 ;
for (size_t i = 0 ; i < n ; i++)
{
@@ -75,13 +75,11 @@ int s6_supervise_unlink_names (char const *scdir, char const *const *names, size
memcpy(fn + scdirlen + 1, names[i], nlen) ;
if (options & 1 && bitarray_peek(locked, i))
{
- ids[m] = registerit(&a, fn, scdirlen + 1 + nlen, deadline, stamp) ;
- if (ids[m]) m++ ;
+ if (registerit(&a, ids + m, fn, scdirlen + 1 + nlen, deadline, stamp)) m++ ;
if (bitarray_peek(logged, i))
{
memcpy(fn + scdirlen + 1 + nlen, "/log", 4) ;
- ids[m] = registerit(&a, fn, scdirlen + 5 + nlen, deadline, stamp) ;
- if (ids[m]) m++ ;
+ if (registerit(&a, ids + m, fn, scdirlen + 5 + nlen, deadline, stamp)) m++ ;
}
}
fn[scdirlen + 1 + nlen] = 0 ;