diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-06-14 04:09:00 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-06-14 04:09:00 +0000 |
commit | 0445f2a3590f67441602a05fe3924ab677c79ff0 (patch) | |
tree | 1a011697fbd92ca53468efe019c8c93c364ad6a8 | |
parent | f287ac765101f21b530f1a9886e06976c165c922 (diff) | |
download | s6-0445f2a3590f67441602a05fe3924ab677c79ff0.tar.xz |
Add ftrigr_checksa(), rewrite s6_svlisten_loop() around it
- Fixes the race condition hit by permanent failure, i.e. two ftrig events close to each other
- Requires storing the sequence of events client-side, so an additional stralloc, bleh
- The visible struct ftrigr_s changes, so a major bump is needed -> prepare for 2.6.0.0
- ftrigr_check() is now a trivial wrapper around ftrigr_checksa()
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | COPYING | 2 | ||||
-rw-r--r-- | INSTALL | 2 | ||||
-rw-r--r-- | doc/index.html | 4 | ||||
-rw-r--r-- | doc/libs6/ftrigr.html | 21 | ||||
-rw-r--r-- | doc/upgrade.html | 6 | ||||
-rw-r--r-- | package/deps.mak | 5 | ||||
-rw-r--r-- | package/info | 2 | ||||
-rw-r--r-- | src/include/s6/ftrigr.h | 7 | ||||
-rw-r--r-- | src/libs6/deps-lib/s6 | 1 | ||||
-rw-r--r-- | src/libs6/ftrigr_check.c | 39 | ||||
-rw-r--r-- | src/libs6/ftrigr_checksa.c | 45 | ||||
-rw-r--r-- | src/libs6/ftrigr_subscribe.c | 4 | ||||
-rw-r--r-- | src/libs6/ftrigr_unsubscribe.c | 2 | ||||
-rw-r--r-- | src/libs6/ftrigr_update.c | 5 | ||||
-rw-r--r-- | src/supervision/s6_svlisten_loop.c | 41 |
16 files changed, 129 insertions, 58 deletions
@@ -25,3 +25,4 @@ Thanks to: John O'Meara <john.fr.omeara@gmail.com> Michael Zuo <muh.muhten@gmail.com> Casper Ti. Vector <caspervector@gmail.com> + Lionel Van Bemten <lionel.van_bemten@nokia.com> @@ -1,4 +1,4 @@ -Copyright (c) 2011-2016 Laurent Bercot <ska-skaware@skarnet.org> +Copyright (c) 2011-2017 Laurent Bercot <ska-skaware@skarnet.org> Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -6,7 +6,7 @@ Build Instructions - A POSIX-compliant C development environment - GNU make version 3.81 or later - - skalibs version 2.5.1.0 or later: http://skarnet.org/software/skalibs/ + - skalibs version 2.5.1.1 or later: http://skarnet.org/software/skalibs/ - execline version 2.3.0.1 or later: http://skarnet.org/software/execline/ This software will run on any operating system that implements diff --git a/doc/index.html b/doc/index.html index 4030733..636d015 100644 --- a/doc/index.html +++ b/doc/index.html @@ -83,7 +83,7 @@ with s6</a> </li> <li> A POSIX-compliant system with a standard C development environment </li> <li> GNU make, version 3.81 or later </li> <li> <a href="//skarnet.org/software/skalibs/">skalibs</a> version -2.5.1.0 or later. It's a build-time requirement. It's also a run-time +2.5.1.1 or later. It's a build-time requirement. It's also a run-time requirement if you link against the shared version of the skalibs library. </li> <li> <a href="//skarnet.org/software/execline/">execline</a> version @@ -100,7 +100,7 @@ library. </li> <h3> Download </h3> <ul> - <li> The current released version of s6 is <a href="s6-2.5.1.0.tar.gz">2.5.1.0</a>. </li> + <li> The current released version of s6 is <a href="s6-2.6.0.0.tar.gz">2.6.0.0</a>. </li> <li> Alternatively, you can checkout a copy of the <a href="//git.skarnet.org/cgi-bin/cgit.cgi/s6/">s6 git repository</a>: diff --git a/doc/libs6/ftrigr.html b/doc/libs6/ftrigr.html index 3a32c7e..cc9e37a 100644 --- a/doc/libs6/ftrigr.html +++ b/doc/libs6/ftrigr.html @@ -266,5 +266,26 @@ times that an event happened to this identifier since the last call to <tt>ftrigr_check()</tt>. </li> </ul> +<pre> +int ftrigr_checksa (ftrigr_t *a, uint16_t id, stralloc *what) +</pre> + +<p> + Checks whether an event happened to <em>id</em>. Use after a +call to <tt>ftrigr_update()</tt>, as an alternative to <tt>ftrigr_check()</tt>. +</p> + +<ul> + <li> If an error occurred, returns -1 and sets errno. The error +number may have been transmitted from +<a href="s6-ftrigrd.html">s6-ftrigrd</a>. </li> + <li> If no notification happened yet, returns 0. </li> + <li> If something happened, appends one character to the end of the <em>what</em> +<a href="//skarnet.org/software/skalibs/libstddjb/stralloc.html">stralloc</a> +for every time a notification was triggered since the last call +to <tt>ftrigr_check()</tt>. Each character is the one that triggered +a notification. The function then returns 1. </li> +</ul> + </body> </html> diff --git a/doc/upgrade.html b/doc/upgrade.html index b9b8461..df5cb3b 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -18,6 +18,12 @@ <h1> What has changed in s6 </h1> +<h2> in 2.6.0.0 </h2> + +<ul> + <li> skalibs dependency bumped to 2.5.1.1. </li> +</ul> + <h2> in 2.5.1.0 </h2> <ul> diff --git a/package/deps.mak b/package/deps.mak index 216f8cf..8d485ca 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -50,6 +50,7 @@ src/libs6/ftrig1_free.o src/libs6/ftrig1_free.lo: src/libs6/ftrig1_free.c src/li src/libs6/ftrig1_make.o src/libs6/ftrig1_make.lo: src/libs6/ftrig1_make.c src/libs6/ftrig1.h src/libs6/ftrigr1_zero.o src/libs6/ftrigr1_zero.lo: src/libs6/ftrigr1_zero.c src/include/s6/ftrigr.h src/libs6/ftrigr_check.o src/libs6/ftrigr_check.lo: src/libs6/ftrigr_check.c src/include/s6/ftrigr.h +src/libs6/ftrigr_checksa.o src/libs6/ftrigr_checksa.lo: src/libs6/ftrigr_checksa.c src/include/s6/ftrigr.h src/libs6/ftrigr_end.o src/libs6/ftrigr_end.lo: src/libs6/ftrigr_end.c src/include/s6/ftrigr.h src/libs6/ftrigr_start.o src/libs6/ftrigr_start.lo: src/libs6/ftrigr_start.c src/include/s6/ftrigr.h src/libs6/ftrigr_startf.o src/libs6/ftrigr_startf.lo: src/libs6/ftrigr_startf.c src/include/s6/ftrigr.h @@ -205,9 +206,9 @@ s6-fdholder-transferdumpc: EXTRA_LIBS := ${SOCKET_LIB} ${TAINNOW_LIB} s6-fdholder-transferdumpc: src/fdholder/s6-fdholder-transferdumpc.o ${LIBS6} -lskarnet s6-fdholderd: EXTRA_LIBS := ${SOCKET_LIB} ${TAINNOW_LIB} s6-fdholderd: src/fdholder/s6-fdholderd.o ${LIBS6} -lskarnet -libs6.a.xyzzy: src/libs6/ftrigr1_zero.o src/libs6/ftrigr_check.o src/libs6/ftrigr_end.o src/libs6/ftrigr_start.o src/libs6/ftrigr_startf.o src/libs6/ftrigr_subscribe.o src/libs6/ftrigr_unsubscribe.o src/libs6/ftrigr_update.o src/libs6/ftrigr_wait_and.o src/libs6/ftrigr_wait_or.o src/libs6/ftrigr_zero.o src/libs6/ftrigw_clean.o src/libs6/ftrigw_fifodir_make.o src/libs6/ftrigw_notify.o src/libs6/ftrigw_notifyb.o src/libs6/ftrigw_notifyb_nosig.o src/libs6/s6_accessrules_backend_cdb.o src/libs6/s6_accessrules_backend_fs.o src/libs6/s6_accessrules_keycheck_ip4.o src/libs6/s6_accessrules_keycheck_ip6.o src/libs6/s6_accessrules_keycheck_reversedns.o src/libs6/s6_accessrules_keycheck_uidgid.o src/libs6/s6_accessrules_params_free.o src/libs6/s6_accessrules_uidgid_cdb.o src/libs6/s6_accessrules_uidgid_fs.o src/libs6/s6_supervise_lock.o src/libs6/s6_supervise_lock_mode.o src/libs6/s6_svc_ok.o src/libs6/s6_svc_write.o src/libs6/s6_svc_writectl.o src/libs6/s6_svstatus_pack.o src/libs6/s6_svstatus_read.o src/libs6/s6_svstatus_unpack.o src/libs6/s6_svstatus_write.o src/libs6/s6lock_acquire.o src/libs6/s6lock_check.o src/libs6/s6lock_end.o src/libs6/s6lock_release.o src/libs6/s6lock_start.o src/libs6/s6lock_startf.o src/libs6/s6lock_update.o src/libs6/s6lock_wait_and.o src/libs6/s6lock_wait_or.o src/libs6/s6lock_zero.o src/libs6/s6_fdholder_delete.o src/libs6/s6_fdholder_delete_async.o src/libs6/s6_fdholder_getdump.o src/libs6/s6_fdholder_list.o src/libs6/s6_fdholder_list_async.o src/libs6/s6_fdholder_list_cb.o src/libs6/s6_fdholder_retrieve.o src/libs6/s6_fdholder_retrieve_async.o src/libs6/s6_fdholder_retrieve_cb.o src/libs6/s6_fdholder_setdump.o src/libs6/s6_fdholder_store.o src/libs6/s6_fdholder_store_async.o +libs6.a.xyzzy: src/libs6/ftrigr1_zero.o src/libs6/ftrigr_check.o src/libs6/ftrigr_checksa.o src/libs6/ftrigr_end.o src/libs6/ftrigr_start.o src/libs6/ftrigr_startf.o src/libs6/ftrigr_subscribe.o src/libs6/ftrigr_unsubscribe.o src/libs6/ftrigr_update.o src/libs6/ftrigr_wait_and.o src/libs6/ftrigr_wait_or.o src/libs6/ftrigr_zero.o src/libs6/ftrigw_clean.o src/libs6/ftrigw_fifodir_make.o src/libs6/ftrigw_notify.o src/libs6/ftrigw_notifyb.o src/libs6/ftrigw_notifyb_nosig.o src/libs6/s6_accessrules_backend_cdb.o src/libs6/s6_accessrules_backend_fs.o src/libs6/s6_accessrules_keycheck_ip4.o src/libs6/s6_accessrules_keycheck_ip6.o src/libs6/s6_accessrules_keycheck_reversedns.o src/libs6/s6_accessrules_keycheck_uidgid.o src/libs6/s6_accessrules_params_free.o src/libs6/s6_accessrules_uidgid_cdb.o src/libs6/s6_accessrules_uidgid_fs.o src/libs6/s6_supervise_lock.o src/libs6/s6_supervise_lock_mode.o src/libs6/s6_svc_ok.o src/libs6/s6_svc_write.o src/libs6/s6_svc_writectl.o src/libs6/s6_svstatus_pack.o src/libs6/s6_svstatus_read.o src/libs6/s6_svstatus_unpack.o src/libs6/s6_svstatus_write.o src/libs6/s6lock_acquire.o src/libs6/s6lock_check.o src/libs6/s6lock_end.o src/libs6/s6lock_release.o src/libs6/s6lock_start.o src/libs6/s6lock_startf.o src/libs6/s6lock_update.o src/libs6/s6lock_wait_and.o src/libs6/s6lock_wait_or.o src/libs6/s6lock_zero.o src/libs6/s6_fdholder_delete.o src/libs6/s6_fdholder_delete_async.o src/libs6/s6_fdholder_getdump.o src/libs6/s6_fdholder_list.o src/libs6/s6_fdholder_list_async.o src/libs6/s6_fdholder_list_cb.o src/libs6/s6_fdholder_retrieve.o src/libs6/s6_fdholder_retrieve_async.o src/libs6/s6_fdholder_retrieve_cb.o src/libs6/s6_fdholder_setdump.o src/libs6/s6_fdholder_store.o src/libs6/s6_fdholder_store_async.o libs6.so.xyzzy: EXTRA_LIBS := -lskarnet -libs6.so.xyzzy: src/libs6/ftrigr1_zero.lo src/libs6/ftrigr_check.lo src/libs6/ftrigr_end.lo src/libs6/ftrigr_start.lo src/libs6/ftrigr_startf.lo src/libs6/ftrigr_subscribe.lo src/libs6/ftrigr_unsubscribe.lo src/libs6/ftrigr_update.lo src/libs6/ftrigr_wait_and.lo src/libs6/ftrigr_wait_or.lo src/libs6/ftrigr_zero.lo src/libs6/ftrigw_clean.lo src/libs6/ftrigw_fifodir_make.lo src/libs6/ftrigw_notify.lo src/libs6/ftrigw_notifyb.lo src/libs6/ftrigw_notifyb_nosig.lo src/libs6/s6_accessrules_backend_cdb.lo src/libs6/s6_accessrules_backend_fs.lo src/libs6/s6_accessrules_keycheck_ip4.lo src/libs6/s6_accessrules_keycheck_ip6.lo src/libs6/s6_accessrules_keycheck_reversedns.lo src/libs6/s6_accessrules_keycheck_uidgid.lo src/libs6/s6_accessrules_params_free.lo src/libs6/s6_accessrules_uidgid_cdb.lo src/libs6/s6_accessrules_uidgid_fs.lo src/libs6/s6_supervise_lock.lo src/libs6/s6_supervise_lock_mode.lo src/libs6/s6_svc_ok.lo src/libs6/s6_svc_write.lo src/libs6/s6_svc_writectl.lo src/libs6/s6_svstatus_pack.lo src/libs6/s6_svstatus_read.lo src/libs6/s6_svstatus_unpack.lo src/libs6/s6_svstatus_write.lo src/libs6/s6lock_acquire.lo src/libs6/s6lock_check.lo src/libs6/s6lock_end.lo src/libs6/s6lock_release.lo src/libs6/s6lock_start.lo src/libs6/s6lock_startf.lo src/libs6/s6lock_update.lo src/libs6/s6lock_wait_and.lo src/libs6/s6lock_wait_or.lo src/libs6/s6lock_zero.lo src/libs6/s6_fdholder_delete.lo src/libs6/s6_fdholder_delete_async.lo src/libs6/s6_fdholder_getdump.lo src/libs6/s6_fdholder_list.lo src/libs6/s6_fdholder_list_async.lo src/libs6/s6_fdholder_list_cb.lo src/libs6/s6_fdholder_retrieve.lo src/libs6/s6_fdholder_retrieve_async.lo src/libs6/s6_fdholder_retrieve_cb.lo src/libs6/s6_fdholder_setdump.lo src/libs6/s6_fdholder_store.lo src/libs6/s6_fdholder_store_async.lo +libs6.so.xyzzy: src/libs6/ftrigr1_zero.lo src/libs6/ftrigr_check.lo src/libs6/ftrigr_checksa.lo src/libs6/ftrigr_end.lo src/libs6/ftrigr_start.lo src/libs6/ftrigr_startf.lo src/libs6/ftrigr_subscribe.lo src/libs6/ftrigr_unsubscribe.lo src/libs6/ftrigr_update.lo src/libs6/ftrigr_wait_and.lo src/libs6/ftrigr_wait_or.lo src/libs6/ftrigr_zero.lo src/libs6/ftrigw_clean.lo src/libs6/ftrigw_fifodir_make.lo src/libs6/ftrigw_notify.lo src/libs6/ftrigw_notifyb.lo src/libs6/ftrigw_notifyb_nosig.lo src/libs6/s6_accessrules_backend_cdb.lo src/libs6/s6_accessrules_backend_fs.lo src/libs6/s6_accessrules_keycheck_ip4.lo src/libs6/s6_accessrules_keycheck_ip6.lo src/libs6/s6_accessrules_keycheck_reversedns.lo src/libs6/s6_accessrules_keycheck_uidgid.lo src/libs6/s6_accessrules_params_free.lo src/libs6/s6_accessrules_uidgid_cdb.lo src/libs6/s6_accessrules_uidgid_fs.lo src/libs6/s6_supervise_lock.lo src/libs6/s6_supervise_lock_mode.lo src/libs6/s6_svc_ok.lo src/libs6/s6_svc_write.lo src/libs6/s6_svc_writectl.lo src/libs6/s6_svstatus_pack.lo src/libs6/s6_svstatus_read.lo src/libs6/s6_svstatus_unpack.lo src/libs6/s6_svstatus_write.lo src/libs6/s6lock_acquire.lo src/libs6/s6lock_check.lo src/libs6/s6lock_end.lo src/libs6/s6lock_release.lo src/libs6/s6lock_start.lo src/libs6/s6lock_startf.lo src/libs6/s6lock_update.lo src/libs6/s6lock_wait_and.lo src/libs6/s6lock_wait_or.lo src/libs6/s6lock_zero.lo src/libs6/s6_fdholder_delete.lo src/libs6/s6_fdholder_delete_async.lo src/libs6/s6_fdholder_getdump.lo src/libs6/s6_fdholder_list.lo src/libs6/s6_fdholder_list_async.lo src/libs6/s6_fdholder_list_cb.lo src/libs6/s6_fdholder_retrieve.lo src/libs6/s6_fdholder_retrieve_async.lo src/libs6/s6_fdholder_retrieve_cb.lo src/libs6/s6_fdholder_setdump.lo src/libs6/s6_fdholder_store.lo src/libs6/s6_fdholder_store_async.lo s6-ftrigrd: EXTRA_LIBS := ${SOCKET_LIB} ${TAINNOW_LIB} s6-ftrigrd: src/libs6/s6-ftrigrd.o src/libs6/ftrig1_free.o src/libs6/ftrig1_make.o -lskarnet s6lockd: EXTRA_LIBS := ${SOCKET_LIB} ${TAINNOW_LIB} ${SPAWN_LIB} diff --git a/package/info b/package/info index a1967af..4cc1ef8 100644 --- a/package/info +++ b/package/info @@ -1,4 +1,4 @@ package=s6 -version=2.5.1.0 +version=2.6.0.0 category=admin package_macro_name=S6 diff --git a/src/include/s6/ftrigr.h b/src/include/s6/ftrigr.h index db91ca9..4afbc97 100644 --- a/src/include/s6/ftrigr.h +++ b/src/include/s6/ftrigr.h @@ -6,6 +6,7 @@ #include <stdint.h> #include <skalibs/config.h> #include <skalibs/tai.h> +#include <skalibs/stralloc.h> #include <skalibs/genalloc.h> #include <skalibs/gensetdyn.h> #include <skalibs/skaclient.h> @@ -40,11 +41,10 @@ typedef struct ftrigr1_s ftrigr1_t, *ftrigr1_t_ref ; struct ftrigr1_s { uint32_t options ; - unsigned int count ; fr1state_t state ; - char what ; + stralloc what ; } ; -#define FTRIGR1_ZERO { .options = 0, .count = 0, .state = FR1STATE_ERROR, .what = 0 } +#define FTRIGR1_ZERO { .options = 0, .state = FR1STATE_ERROR, .what = STRALLOC_ZERO } extern ftrigr1_t const ftrigr1_zero ; @@ -76,6 +76,7 @@ extern void ftrigr_end (ftrigr_t *) ; #define ftrigr_fd(a) skaclient_fd(&(a)->connection) extern int ftrigr_update (ftrigr_t *) ; extern int ftrigr_check (ftrigr_t *, uint16_t, char *) ; +extern int ftrigr_checksa (ftrigr_t *, uint16_t, stralloc *) ; /* Synchronous functions with timeouts */ diff --git a/src/libs6/deps-lib/s6 b/src/libs6/deps-lib/s6 index 65062e1..ace5a05 100644 --- a/src/libs6/deps-lib/s6 +++ b/src/libs6/deps-lib/s6 @@ -1,5 +1,6 @@ ftrigr1_zero.o ftrigr_check.o +ftrigr_checksa.o ftrigr_end.o ftrigr_start.o ftrigr_startf.o diff --git a/src/libs6/ftrigr_check.c b/src/libs6/ftrigr_check.c index 0a7fcdc..30be701 100644 --- a/src/libs6/ftrigr_check.c +++ b/src/libs6/ftrigr_check.c @@ -1,39 +1,20 @@ /* ISC license. */ #include <errno.h> -#include <skalibs/gensetdyn.h> +#include <skalibs/stralloc.h> #include <s6/ftrigr.h> int ftrigr_check (ftrigr_t *a, uint16_t id, char *c) { - 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) + stralloc sa = STRALLOC_ZERO ; + int r = ftrigr_checksa(a, id, &sa) ; + + if (r && sa.len) { - case FR1STATE_WAITACKDATA : - { - *c = p->what ; - *p = ftrigr1_zero ; - gensetdyn_delete(&a->data, id) ; - return 1 ; - } - case FR1STATE_LISTENING : - { - unsigned int r = p->count ; - if (r) *c = p->what ; - p->count = 0 ; - return (int)r ; - } - case FR1STATE_WAITACK : - { - errno = p->what ; - *p = ftrigr1_zero ; - gensetdyn_delete(&a->data, id) ; - return -1 ; - } - default: return (errno = EINVAL, -1) ; + int e = errno ; + *c = sa.s[sa.len - 1] ; + stralloc_free(&sa) ; + errno = e ; } - return 0 ; + return r ; } diff --git a/src/libs6/ftrigr_checksa.c b/src/libs6/ftrigr_checksa.c new file mode 100644 index 0000000..6573182 --- /dev/null +++ b/src/libs6/ftrigr_checksa.c @@ -0,0 +1,45 @@ +/* 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_subscribe.c b/src/libs6/ftrigr_subscribe.c index 3766d35..cbbde1e 100644 --- a/src/libs6/ftrigr_subscribe.c +++ b/src/libs6/ftrigr_subscribe.c @@ -7,6 +7,7 @@ #include <skalibs/uint16.h> #include <skalibs/uint32.h> #include <skalibs/tai.h> +#include <skalibs/stralloc.h> #include <skalibs/gensetdyn.h> #include <skalibs/skaclient.h> #include <s6/ftrigr.h> @@ -45,8 +46,7 @@ uint16_t ftrigr_subscribe (ftrigr_t *a, char const *path, char const *re, uint32 ftrigr1_t *p = GENSETDYN_P(ftrigr1_t, &a->data, i) ; p->options = options ; p->state = FR1STATE_LISTENING ; - p->count = 0 ; - p->what = 0 ; + p->what = stralloc_zero ; } return (uint16_t)(i+1) ; } diff --git a/src/libs6/ftrigr_unsubscribe.c b/src/libs6/ftrigr_unsubscribe.c index 4428b72..a96ddb0 100644 --- a/src/libs6/ftrigr_unsubscribe.c +++ b/src/libs6/ftrigr_unsubscribe.c @@ -2,6 +2,7 @@ #include <errno.h> #include <skalibs/uint16.h> +#include <skalibs/stralloc.h> #include <skalibs/gensetdyn.h> #include <skalibs/skaclient.h> #include <s6/ftrigr.h> @@ -30,6 +31,7 @@ int ftrigr_unsubscribe (ftrigr_t *a, uint16_t i, tain_t const *deadline, tain_t if (!skaclient_send(&a->connection, pack, 3, &skaclient_default_cb, &err, deadline, stamp)) return 0 ; if (err) return (errno = err, 0) ; } + stralloc_free(&p->what) ; *p = ftrigr1_zero ; return gensetdyn_delete(&a->data, i) ; } diff --git a/src/libs6/ftrigr_update.c b/src/libs6/ftrigr_update.c index 52f79b9..f97535d 100644 --- a/src/libs6/ftrigr_update.c +++ b/src/libs6/ftrigr_update.c @@ -35,12 +35,14 @@ static int msghandler (unixmessage_t const *m, void *context) switch (m->s[2]) { case 'd' : + if (!stralloc_catb(&p->what, m->s + 3, 1)) return 0 ; p->state = FR1STATE_WAITACK ; break ; case '!' : + if (!stralloc_catb(&p->what, m->s + 3, 1)) return 0 ; if (p->options & FTRIGR_REPEAT) { - if (p->count++ + if (p->what.len > 1 && appears(id+1, genalloc_s(uint16_t, &a->list), genalloc_len(uint16_t, &a->list))) addit = 0 ; } @@ -48,7 +50,6 @@ static int msghandler (unixmessage_t const *m, void *context) break ; default : return (errno = EPROTO, 0) ; } - p->what = m->s[3] ; if (addit) { id++ ; genalloc_append(uint16_t, &a->list, &id) ; diff --git a/src/supervision/s6_svlisten_loop.c b/src/supervision/s6_svlisten_loop.c index 5c55c81..c98fe83 100644 --- a/src/supervision/s6_svlisten_loop.c +++ b/src/supervision/s6_svlisten_loop.c @@ -5,6 +5,7 @@ #include <skalibs/bitarray.h> #include <skalibs/strerr2.h> #include <skalibs/iopause.h> +#include <skalibs/stralloc.h> #include <skalibs/djbunix.h> #include <s6/ftrigr.h> #include <s6/s6-supervise.h> @@ -48,7 +49,10 @@ int s6_svlisten_loop (s6_svlisten_t *foo, int wantup, int wantready, int or, tai { iopause_fd x[2] = { { .fd = ftrigr_fd(&foo->a), .events = IOPAUSE_READ }, { .fd = spfd, .events = IOPAUSE_READ, .revents = 0 } } ; unsigned int e = 0 ; - while (!got(foo, wantup, wantready, or)) + stralloc sa = STRALLOC_ZERO ; + + if (got(foo, wantup, wantready, or)) return 0 ; + for (;;) { int r = iopause_g(x, 1 + (spfd >= 0), deadline) ; if (r < 0) strerr_diefu1sys(111, "iopause") ; @@ -60,29 +64,36 @@ int s6_svlisten_loop (s6_svlisten_t *foo, int wantup, int wantready, int or, tai if (ftrigr_update(&foo->a) < 0) strerr_diefu1sys(111, "ftrigr_update") ; for (; i < foo->n ; i++) { - char what ; - int r = ftrigr_check(&foo->a, foo->ids[i], &what) ; + sa.len = 0 ; + r = ftrigr_checksa(&foo->a, foo->ids[i], &sa) ; if (r < 0) strerr_diefu1sys(111, "ftrigr_check") ; - if (r) + else if (r) { - if (what == 'O') + size_t j = 0 ; + for (; j < sa.len ; j++) { - if (wantup) + if (sa.s[j] == 'O') { - bitarray_poke(foo->upstate, i, wantup) ; - bitarray_poke(foo->readystate, i, wantready) ; - e++ ; + if (wantup) + { + bitarray_poke(foo->upstate, i, wantup) ; + bitarray_poke(foo->readystate, i, wantready) ; + e++ ; + } } - } - else - { - unsigned int d = byte_chr("dDuU", 4, what) ; - bitarray_poke(foo->upstate, i, d & 2) ; - bitarray_poke(foo->readystate, i, d & 1) ; + else + { + unsigned int d = byte_chr("dDuU", 4, sa.s[j]) ; + bitarray_poke(foo->upstate, i, d & 2) ; + bitarray_poke(foo->readystate, i, d & 1) ; + } + if (got(foo, wantup, wantready, or)) goto gotit ; } } } } } + gotit: + stralloc_free(&sa) ; return e ; } |