X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=postlicyd.c;fp=postlicyd.c;h=bc8eeea02b9fb56c305b785b7f360c8119d16588;hb=c0cfcd4c414bd423e4766ff6c90850ee25c9b449;hp=ebf8260d7af08deff3469543d694851296d3d235;hpb=0bfa9f900af9a4f4e65f3f580056de28380b333a;p=apps%2Fpfixtools.git diff --git a/postlicyd.c b/postlicyd.c index ebf8260..bc8eeea 100644 --- a/postlicyd.c +++ b/postlicyd.c @@ -30,29 +30,73 @@ /******************************************************************************/ /* - * Copyright © 2006 Pierre Habouzit + * Copyright © 2006-2007 Pierre Habouzit */ -#include -#include -#include -#include +#include +#include +#include -#include "job.h" +#include "postlicyd.h" -bool cleanexit = false; +static bool cleanexit = false; +static bool sigint = false; + +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) { openlog("postlicyd", LOG_PID, LOG_MAIL); - job_initialize(); + signal(SIGPIPE, SIG_IGN); + signal(SIGINT, &main_sighandler); + signal(SIGTERM, &main_sighandler); syslog(LOG_INFO, "Starting..."); } +static void main_loop(void) +{ + while (!sigint) { + int fd = accept(-1, NULL, 0); + + if (fd < 0) { + if (errno == EINTR || errno == EAGAIN) + continue; + syslog(LOG_ERR, "accept error: %m"); + return; + } + + //pthread_create(NULL, NULL, job_run, (intptr_t)fd); + } +} + static void main_shutdown(void) { syslog(LOG_INFO, cleanexit ? "Stopping..." : "Unclean exit..."); - job_shutdown(); closelog(); } @@ -60,14 +104,12 @@ int main(void) { if (atexit(main_shutdown)) { fputs("Cannot hook my atexit function, quitting !\n", stderr); - return EX_CONFIG; + return EXIT_FAILURE; } main_initialize(); - - job_loop(); - + main_loop(); cleanexit = true; main_shutdown(); - return 0; + return EXIT_SUCCESS; }