X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=postlicyd.c;h=051e83baef720a962058c61644f1cc26b20e18ac;hb=dc1c24f73dfe8a1e7d92897cb741c52be2a15c4d;hp=ebf8260d7af08deff3469543d694851296d3d235;hpb=0bfa9f900af9a4f4e65f3f580056de28380b333a;p=apps%2Fpfixtools.git diff --git a/postlicyd.c b/postlicyd.c index ebf8260..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 */ /* ~~~~~~~~~ */ /* ________________________________________________________________________ */ /* */ @@ -30,44 +30,77 @@ /******************************************************************************/ /* - * Copyright © 2006 Pierre Habouzit + * Copyright © 2006-2007 Pierre Habouzit */ -#include -#include -#include -#include +#include +#include +#include -#include "job.h" +#include "common.h" -bool cleanexit = false; +volatile int nbthreads = 0; -static void main_initialize(void) +static int main_initialize(void) { openlog("postlicyd", LOG_PID, LOG_MAIL); - job_initialize(); + signal(SIGPIPE, SIG_IGN); + signal(SIGINT, &common_sighandler); + signal(SIGTERM, &common_sighandler); syslog(LOG_INFO, "Starting..."); + return 0; +} + +void *job_run(void *_fd) +{ + int fd = (intptr_t)_fd; + + close(fd); + return NULL; +} + +static void main_loop(void) +{ + int sock = -1; + + while (!sigint) { + int fd = accept(sock, NULL, 0); + pthread_attr_t attr; + pthread_t dummy; + + if (fd < 0) { + if (errno != EINTR || errno != EAGAIN) + UNIXERR("accept"); + continue; + } + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_create(&dummy, &attr, job_run, (void *)(intptr_t)fd); + pthread_attr_destroy(&attr); + } + + cleanexit = true; + close(sock); } static void main_shutdown(void) { syslog(LOG_INFO, cleanexit ? "Stopping..." : "Unclean exit..."); - job_shutdown(); 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 EX_CONFIG; + return EXIT_FAILURE; } - main_initialize(); - - job_loop(); - - cleanexit = true; - main_shutdown(); - return 0; + common_initialize(); + main_loop(); + return EXIT_SUCCESS; }