X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=postlicyd.c;h=051e83baef720a962058c61644f1cc26b20e18ac;hb=1ff926eac33152aee930a454ac1d3dec6e6e5faf;hp=bd887e45a1ba9e6888545de8859f87e62d59c0d5;hpb=79ff3ad0aaa667dc9ce658460632177c8ffcf39e;p=apps%2Fpfixtools.git diff --git a/postlicyd.c b/postlicyd.c index bd887e4..051e83b 100644 --- a/postlicyd.c +++ b/postlicyd.c @@ -1,5 +1,5 @@ /******************************************************************************/ -/* postlicyd: a postfix policy daemon with a lot of features */ +/* pfixtools: a collection of postfix related tools */ /* ~~~~~~~~~ */ /* ________________________________________________________________________ */ /* */ @@ -37,46 +37,18 @@ #include #include -#include "postlicyd.h" +#include "common.h" -static sig_atomic_t cleanexit = false; -static sig_atomic_t sigint = false; -static volatile int nbthreads = 0; +volatile int nbthreads = 0; -static void main_sighandler(int sig) -{ - static time_t lastintr = 0; - time_t now = time(NULL); - - switch (sig) { - case SIGINT: - if (sigint) { - if (now - lastintr >= 1) - break; - } else { - lastintr = now; - sigint = true; - } - return; - - case SIGTERM: - break; - - default: - return; - } - - syslog(LOG_ERR, "Killed..."); - exit(-1); -} - -static void main_initialize(void) +static int main_initialize(void) { openlog("postlicyd", LOG_PID, LOG_MAIL); signal(SIGPIPE, SIG_IGN); - signal(SIGINT, &main_sighandler); - signal(SIGTERM, &main_sighandler); + signal(SIGINT, &common_sighandler); + signal(SIGTERM, &common_sighandler); syslog(LOG_INFO, "Starting..."); + return 0; } void *job_run(void *_fd) @@ -89,8 +61,10 @@ void *job_run(void *_fd) static void main_loop(void) { + int sock = -1; + while (!sigint) { - int fd = accept(-1, NULL, 0); + int fd = accept(sock, NULL, 0); pthread_attr_t attr; pthread_t dummy; @@ -105,6 +79,9 @@ static void main_loop(void) pthread_create(&dummy, &attr, job_run, (void *)(intptr_t)fd); pthread_attr_destroy(&attr); } + + cleanexit = true; + close(sock); } static void main_shutdown(void) @@ -113,16 +90,17 @@ static void main_shutdown(void) closelog(); } +module_init(main_initialize); +module_exit(main_shutdown); + int main(void) { - if (atexit(main_shutdown)) { + if (atexit(common_shutdown)) { fputs("Cannot hook my atexit function, quitting !\n", stderr); return EXIT_FAILURE; } - main_initialize(); + common_initialize(); main_loop(); - cleanexit = true; - main_shutdown(); return EXIT_SUCCESS; }