From 0445f2a3590f67441602a05fe3924ab677c79ff0 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 14 Jun 2017 04:09:00 +0000 Subject: 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() --- AUTHORS | 1 + COPYING | 2 +- INSTALL | 2 +- doc/index.html | 4 ++-- doc/libs6/ftrigr.html | 21 ++++++++++++++++++ doc/upgrade.html | 6 +++++ package/deps.mak | 5 +++-- package/info | 2 +- src/include/s6/ftrigr.h | 7 +++--- src/libs6/deps-lib/s6 | 1 + src/libs6/ftrigr_check.c | 39 +++++++++------------------------ src/libs6/ftrigr_checksa.c | 45 ++++++++++++++++++++++++++++++++++++++ src/libs6/ftrigr_subscribe.c | 4 ++-- src/libs6/ftrigr_unsubscribe.c | 2 ++ src/libs6/ftrigr_update.c | 5 +++-- src/supervision/s6_svlisten_loop.c | 41 +++++++++++++++++++++------------- 16 files changed, 129 insertions(+), 58 deletions(-) create mode 100644 src/libs6/ftrigr_checksa.c diff --git a/AUTHORS b/AUTHORS index b7fd202..3121cd1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -25,3 +25,4 @@ Thanks to: John O'Meara Michael Zuo Casper Ti. Vector + Lionel Van Bemten diff --git a/COPYING b/COPYING index f496e31..cc344f1 100644 --- a/COPYING +++ b/COPYING @@ -1,4 +1,4 @@ -Copyright (c) 2011-2016 Laurent Bercot +Copyright (c) 2011-2017 Laurent Bercot Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/INSTALL b/INSTALL index b171d44..1000c3a 100644 --- a/INSTALL +++ b/INSTALL @@ -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 POSIX-compliant system with a standard C development environment
  • GNU make, version 3.81 or later
  • skalibs 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.
  • execline version @@ -100,7 +100,7 @@ library.
  • Download

      -
    • The current released version of s6 is 2.5.1.0.
    • +
    • The current released version of s6 is 2.6.0.0.
    • Alternatively, you can checkout a copy of the s6 git repository: 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 ftrigr_check().
    +
    +int ftrigr_checksa (ftrigr_t *a, uint16_t id, stralloc *what)
    +
    + +

    + Checks whether an event happened to id. Use after a +call to ftrigr_update(), as an alternative to ftrigr_check(). +

    + +
      +
    • If an error occurred, returns -1 and sets errno. The error +number may have been transmitted from +s6-ftrigrd.
    • +
    • If no notification happened yet, returns 0.
    • +
    • If something happened, appends one character to the end of the what +stralloc +for every time a notification was triggered since the last call +to ftrigr_check(). Each character is the one that triggered +a notification. The function then returns 1.
    • +
    + 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 @@

    What has changed in s6

    +

    in 2.6.0.0

    + +
      +
    • skalibs dependency bumped to 2.5.1.1.
    • +
    +

    in 2.5.1.0

      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 #include #include +#include #include #include #include @@ -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 -#include +#include #include 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 +#include +#include +#include + +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 #include #include +#include #include #include #include @@ -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 #include +#include #include #include #include @@ -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 #include #include +#include #include #include #include @@ -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 ; } -- cgit v1.2.3