X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=secnet.c;h=7869182b51ec5a653ea967f4154d746bd163ad88;hb=8b9b7a6a06c3052930d00aeba6c2ae1e19bd6358;hp=bef236dda9a2b466fad8636e7d51749b7eaaa5e6;hpb=fe5e9cc422cd72526ccfceffbc7e5af8ac83b407;p=secnet.git diff --git a/secnet.c b/secnet.c index bef236d..7869182 100644 --- a/secnet.c +++ b/secnet.c @@ -1,7 +1,7 @@ -extern char version[]; - #include "secnet.h" #include +#include +#include #include #include #include @@ -27,26 +27,18 @@ cstring_t require_root_privileges_explanation=NULL; static pid_t secnet_pid; -/* from log.c */ -extern uint32_t message_level; -extern bool_t secnet_is_daemon; -extern struct log_if *system_log; - -/* from process.c */ -extern void start_signal_handling(void); - /* Structures dealing with poll() call */ struct poll_interest { beforepoll_fn *before; afterpoll_fn *after; void *state; - uint32_t max_nfds; - uint32_t nfds; + int32_t max_nfds; + int32_t nfds; cstring_t desc; struct poll_interest *next; }; static struct poll_interest *reg=NULL; -static uint32_t total_nfds=10; +static int32_t total_nfds=10; static bool_t finished=False; @@ -229,7 +221,7 @@ static void setup(dict_t *config) } void register_for_poll(void *st, beforepoll_fn *before, - afterpoll_fn *after, uint32_t max_nfds, cstring_t desc) + afterpoll_fn *after, int32_t max_nfds, cstring_t desc) { struct poll_interest *i; @@ -240,6 +232,7 @@ void register_for_poll(void *st, beforepoll_fn *before, i->max_nfds=max_nfds; i->nfds=0; i->desc=desc; + assert(total_nfds < INT_MAX - max_nfds); total_nfds+=max_nfds; i->next=reg; reg=i; @@ -263,10 +256,7 @@ static void run(void) int timeout; struct pollfd *fds; - fds=alloca(sizeof(*fds)*total_nfds); - if (!fds) { - fatal("run: couldn't alloca"); - } + fds=safe_malloc(sizeof(*fds)*total_nfds, "run"); Message(M_NOTICE,"%s [%d]: starting\n",version,secnet_pid); @@ -309,6 +299,7 @@ static void run(void) } } while (rv<0); } while (!finished); + free(fds); } static void droppriv(void)