s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

commit a6af536be0d264d9e7d0e26fd07cd822d1c0331a
parent caa9746cb1e1dc6bb3e00beb5bfd36e7aa1de469
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Mon, 30 Jan 2017 16:56:03 +0000

 bugfix: ftrigr_update() could return incorrect value for repeating events (thanks jjk)

Diffstat:
Msrc/libs6/ftrigr_update.c | 23+++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/libs6/ftrigr_update.c b/src/libs6/ftrigr_update.c @@ -1,7 +1,9 @@ /* ISC license. */ +#include <sys/types.h> #include <stdint.h> #include <errno.h> +#include <skalibs/gccattributes.h> #include <skalibs/error.h> #include <skalibs/uint16.h> #include <skalibs/genalloc.h> @@ -10,10 +12,19 @@ #include <skalibs/skaclient.h> #include <s6/ftrigr.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 (unixmessage_t const *m, void *context) { ftrigr_t *a = (ftrigr_t *)context ; ftrigr1_t *p ; + int addit = 1 ; uint16_t id ; if (m->len != 4 || m->nfds) return (errno = EPROTO, 0) ; uint16_unpack_big(m->s, &id) ; @@ -27,13 +38,21 @@ static int msghandler (unixmessage_t const *m, void *context) p->state = FR1STATE_WAITACK ; break ; case '!' : - if (p->options & FTRIGR_REPEAT) p->count++ ; + if (p->options & FTRIGR_REPEAT) + { + if (p->count++ + && 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) ; } p->what = m->s[3] ; - id++ ; genalloc_append(uint16_t, &a->list, &id) ; + if (addit) + { + id++ ; genalloc_append(uint16_t, &a->list, &id) ; + } return 1 ; }