X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=main-postlicyd.c;h=92c20262fdb730ff9b1b541238deb26a38f95e76;hb=c78538ac1dd1f22e4b6384b6e85a153646cb90d9;hp=04172dde80d260c0e526d997abc384bc03233a9e;hpb=8504d5165f2257fe7d3899c219caaad8b8964705;p=apps%2Fpfixtools.git diff --git a/main-postlicyd.c b/main-postlicyd.c index 04172dd..92c2026 100644 --- a/main-postlicyd.c +++ b/main-postlicyd.c @@ -35,8 +35,8 @@ #include -#include "epoll.h" #include "threads.h" +#include "policy.h" #define DAEMON_NAME "postlicyd" @@ -72,12 +72,6 @@ void usage(void) /* }}} */ -void *job_run(int fd, void *data) -{ - close(fd); - return NULL; -} - static int main_loop(void) { int exitcode = EXIT_SUCCESS; @@ -91,7 +85,7 @@ static int main_loop(void) continue; } - thread_launch(job_run, fd, NULL); + thread_launch(policy_run, fd, NULL); threads_join(); } @@ -102,7 +96,6 @@ static int main_loop(void) int main(int argc, char *argv[]) { const char *pidfile = NULL; - FILE *f = NULL; int res; for (int c = 0; (c = getopt(argc, argv, "h" "p:")) >= 0; ) { @@ -121,13 +114,9 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - if (pidfile) { - f = fopen(pidfile, "w"); - if (!f) { - syslog(LOG_CRIT, "unable to write pidfile %s", pidfile); - } - fprintf(f, "%d\n", getpid()); - fflush(f); + if (pidfile_open(pidfile) < 0) { + syslog(LOG_CRIT, "unable to write pidfile %s", pidfile); + return EXIT_FAILURE; } if (daemon_detach() < 0) { @@ -135,19 +124,8 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - if (f) { - rewind(f); - ftruncate(fileno(f), 0); - fprintf(f, "%d\n", getpid()); - fflush(f); - } + pidfile_refresh(); res = main_loop(); - if (f) { - rewind(f); - ftruncate(fileno(f), 0); - fclose(f); - f = NULL; - } syslog(LOG_INFO, "Stopping..."); return res; }