From: Florent Bruneau Date: Mon, 8 Sep 2008 21:39:22 +0000 (+0200) Subject: Close the listeners on exit. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=5474880d98533401c2b1bc12ae0d96031e4d744b;p=apps%2Fpfixtools.git Close the listeners on exit. Signed-off-by: Florent Bruneau --- diff --git a/main-postlicyd.c b/main-postlicyd.c index b2ed86d..deb90b3 100644 --- a/main-postlicyd.c +++ b/main-postlicyd.c @@ -214,7 +214,7 @@ __attribute__((format(printf,2,0))) static void policy_answer(server_t *pcy, const char *fmt, ...) { va_list args; - query_t* query = pcy->data; + const query_t* query = pcy->data; buffer_addstr(&pcy->obuf, "action="); va_start(args, fmt); @@ -225,9 +225,17 @@ static void policy_answer(server_t *pcy, const char *fmt, ...) epoll_modify(pcy->fd, EPOLLIN | EPOLLOUT, pcy); } +static bool policy_run_filter(const query_t* query, void* filter, void* conf) +{ + return false; +} + static void policy_process(server_t *pcy) { - policy_answer(pcy, "DUNNO"); + const query_t* query = pcy->data; + if (!policy_run_filter(query, NULL, NULL)) { + policy_answer(pcy, "DUNNO"); + } } static int policy_run(server_t *pcy, void* config) diff --git a/server.c b/server.c index 0d6443c..73c2888 100644 --- a/server.c +++ b/server.c @@ -36,6 +36,10 @@ #include "server.h" #include "epoll.h" +static server_t *listeners[1024]; +static int listener_count = 0; + + static server_t* server_new(void) { server_t* server = p_new(server_t, 1); @@ -58,6 +62,15 @@ static void server_delete(server_t **server) } } +static void server_shutdown(void) +{ + for (int i = 0 ; i < listener_count ; ++i) { + server_delete(&listeners[i]); + } +} + +module_exit(server_shutdown); + int start_server(int port, start_listener_t starter, delete_client_t deleter) { struct sockaddr_in addr = { @@ -88,6 +101,7 @@ int start_server(int port, start_listener_t starter, delete_client_t deleter) tmp->data = data; tmp->clear_data = deleter; epoll_register(sock, EPOLLIN, tmp); + listeners[listener_count++] = tmp; return 0; }