From 4d2c72513120d8ed7d6cf4b2500e04d754b96b66 Mon Sep 17 00:00:00 2001 From: Bjørn Mork Date: Thu, 30 May 2019 11:48:35 +0200 Subject: poll will return on HUP, so we need to handle cfg read there MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also need to clear revents to continue polling... Signed-off-by: Bjørn Mork --- obinsectd.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/obinsectd.c b/obinsectd.c index f28d3a9..a8beb0e 100644 --- a/obinsectd.c +++ b/obinsectd.c @@ -1527,9 +1527,20 @@ static int read_and_parse(int fd, unsigned char *rbuf, size_t rbuflen) while (1) { ret = poll(fds, 1, -1); - if (ret == -1) + if (ret == -1 && !reread_cfg) return -errno; + /* we might have been requested to read the config file again */ + if (reread_cfg) { + fds[0].revents = 0; + reread_cfg = false; + info("reading new configuration from '%s'\n", cfgfile); + if (cfg) + json_object_put(cfg); + read_config(); + continue; + } + if (fds[0].revents & POLLIN) rlen = read(fd, cur, rbuflen + rbuf - cur); else @@ -1571,15 +1582,6 @@ nextframe: if (framelen > 0 && (cur - hdlc) < (framelen + 2)) continue; - /* we might have been requested to read the config file again */ - if (reread_cfg) { - reread_cfg = false; - info("reading new configuration from '%s'\n", cfgfile); - if (cfg) - json_object_put(cfg); - read_config(); - } - /* Yay! We got a complete frame - let's save some metadata now */ json = save_metadata(framelen, &tv); @@ -1872,6 +1874,7 @@ static void usage() static void sig_handler(int sig) { + debug("handling signal %d\n", sig); switch (sig) { case SIGHUP: reread_cfg = true; -- cgit v1.2.3