>From 83c085e350fe2752b8ebc8f85fbff3556bd55c49 Mon Sep 17 00:00:00 2001 From: Olivier Brunel Date: Fri, 27 Jan 2017 18:55:18 +0100 Subject: [PATCH] ftrigr_update: ensure there's no duplicate ids Also do indeed return the number of ids for which something happened (instead of the number of messages received). Signed-off-by: Olivier Brunel --- src/libs6/ftrigr_update.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libs6/ftrigr_update.c b/src/libs6/ftrigr_update.c index ad69714..182d459 100644 --- a/src/libs6/ftrigr_update.c +++ b/src/libs6/ftrigr_update.c @@ -9,6 +9,12 @@ #include #include +static inline int is_in_list (uint16 id, uint16 *list, unsigned int len) +{ + while (len) if (list[--len] == id) return 1 ; + return 0 ; +} + static int msghandler (unixmessage_t const *m, void *context) { ftrigr_t *a = (ftrigr_t *)context ; @@ -32,12 +38,18 @@ static int msghandler (unixmessage_t const *m, void *context) default : return (errno = EPROTO, 0) ; } p->what = m->s[3] ; - id++ ; genalloc_append(uint16, &a->list, &id) ; + if (p->state != FR1STATE_LISTENING || p->count == 1 + || !is_in_list(id+1, genalloc_s(uint16, &a->list), + genalloc_len(uint16, &a->list))) { + id++ ; genalloc_append(uint16, &a->list, &id) ; + } return 1 ; } int ftrigr_update (ftrigr_t *a) { + int r ; genalloc_setlen(uint16, &a->list, 0) ; - return skaclient_update(&a->connection, &msghandler, a) ; + r = skaclient_update(&a->connection, &msghandler, a) ; + return (r < 0) ? r : genalloc_len(uint16, &a->list) ; } -- 2.11.0