diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-01-30 16:56:03 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-01-30 16:56:03 +0000 |
commit | a6af536be0d264d9e7d0e26fd07cd822d1c0331a (patch) | |
tree | bba81e1e4dee4636fa98926e84899afa5fd884e8 /src/libs6/ftrigr_update.c | |
parent | caa9746cb1e1dc6bb3e00beb5bfd36e7aa1de469 (diff) | |
download | s6-a6af536be0d264d9e7d0e26fd07cd822d1c0331a.tar.xz |
bugfix: ftrigr_update() could return incorrect value for repeating events (thanks jjk)
Diffstat (limited to 'src/libs6/ftrigr_update.c')
-rw-r--r-- | src/libs6/ftrigr_update.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/libs6/ftrigr_update.c b/src/libs6/ftrigr_update.c index 68e3bde..132449b 100644 --- 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 ; } |