X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fevent.c;h=899b62a077abb435e5327b359bacc41402ccaaf1;hb=28b7a53b693f6b4e70218a926e68a36ece54cda1;hp=c547c46d1f2f5d5a5077d83c335d823c634bb601;hpb=0912276c6467aa3ee6f570b31245367319da572a;p=tinc diff --git a/src/event.c b/src/event.c index c547c46d..899b62a0 100644 --- a/src/event.c +++ b/src/event.c @@ -1,6 +1,6 @@ /* event.c -- I/O, timeout and signal event handling - Copyright (C) 2012-2021 Guus Sliepen + Copyright (C) 2012-2022 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,12 +18,14 @@ */ #include "system.h" -#include "dropin.h" + +#include #ifdef HAVE_SYS_EPOLL_H #include #endif +#include "dropin.h" #include "event.h" #include "utils.h" #include "net.h" @@ -46,7 +48,7 @@ static DWORD event_count = 0; static bool running; #ifdef HAVE_SYS_EPOLL_H -static inline int event_epoll_init() { +static inline int event_epoll_init(void) { /* NOTE: 1024 limit is only used on ancient (pre 2.6.27) kernels. Decent kernels will ignore this value making it unlimited. epoll_create1 might be better, but these kernels would not be supported @@ -290,11 +292,14 @@ void timeout_del(timeout_t *timeout) { static io_t signalio; static int pipefd[2] = {-1, -1}; -static signal_t *signal_handle[NSIG + 1] = {}; +static signal_t *signal_handle[NSIG + 1] = {NULL}; static void signal_handler(int signum) { unsigned char num = signum; - write(pipefd[1], &num, 1); + + if(write(pipefd[1], &num, 1) != 1) { + // Pipe full or broken, nothing we can do about it. + } } static void signalio_handler(void *data, int flags) { @@ -480,6 +485,7 @@ bool event_loop(void) { } #else + assert(WSA_WAIT_EVENT_0 == 0); while(running) { struct timeval diff; @@ -541,12 +547,12 @@ bool event_loop(void) { break; } - if(result < WSA_WAIT_EVENT_0 || result >= WSA_WAIT_EVENT_0 + event_count - event_offset) { + if(result >= event_count - event_offset) { return false; } /* Look up io in the map by index. */ - event_index = result - WSA_WAIT_EVENT_0 + event_offset; + event_index = result + event_offset; io_t *io = io_map[event_index]; if(io->fd == -1) {