From 0bfa9f900af9a4f4e65f3f580056de28380b333a Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 18 Aug 2007 12:27:30 +0200 Subject: [PATCH] Fix build system, drop gai things, we will go with threads as policy processes are long lived. Signed-off-by: Pierre Habouzit --- Makefile | 12 +-- gai.c | 205 ---------------------------------------------------- gai.h | 56 -------------- job.c | 3 - postlicyd.c | 3 - 5 files changed, 6 insertions(+), 273 deletions(-) delete mode 100644 gai.c delete mode 100644 gai.h diff --git a/Makefile b/Makefile index ef55441..3be13e3 100644 --- a/Makefile +++ b/Makefile @@ -40,11 +40,11 @@ PROGRAMS = postlicyd GENERATED = tokens.h tokens.c postlicyd_SOURCES = \ - str.h buffer.h job.h postfix.h gai.h \ - str.c buffer.c job.c postfix.c gai.c \ + str.h buffer.h job.h postfix.h \ + str.c buffer.c job.c postfix.c \ postlicyd.c $(GENERATED) -postlicyd_LIBADD = -lanl +postlicyd_LIBADD = -lpthread # RULES ###################################################################{{{ @@ -52,7 +52,7 @@ all: $(PROGRAMS) $(GENERATED) | $(GENERATED) clean: $(RM) $(PROGRAMS) - $(RM) .*.o + $(RM) .*.o .*.dep distclean: clean $(RM) $(GENERATED) @@ -76,8 +76,8 @@ headers: .%.o: %.c Makefile $(CC) $(CFLAGS) -MMD -MT ".$*.dep $@" -MF .$*.dep -g -c -o $@ $< -%.dep: %.c Makefile - $(CC) $(CFLAGS) -MM -MT ".$*.dep $@" -MF .$*.dep $< +.%.dep: %.c Makefile + $(CC) $(CFLAGS) -MM -MT ".$*.o $@" -MF .$*.dep $< .SECONDEXPANSION: diff --git a/gai.c b/gai.c deleted file mode 100644 index ce91e8b..0000000 --- a/gai.c +++ /dev/null @@ -1,205 +0,0 @@ -/******************************************************************************/ -/* postlicyd: a postfix policy daemon with a lot of features */ -/* ~~~~~~~~~ */ -/* ________________________________________________________________________ */ -/* */ -/* Redistribution and use in source and binary forms, with or without */ -/* modification, are permitted provided that the following conditions */ -/* are met: */ -/* */ -/* 1. Redistributions of source code must retain the above copyright */ -/* notice, this list of conditions and the following disclaimer. */ -/* 2. Redistributions in binary form must reproduce the above copyright */ -/* notice, this list of conditions and the following disclaimer in the */ -/* documentation and/or other materials provided with the distribution. */ -/* 3. The names of its contributors may not be used to endorse or promote */ -/* products derived from this software without specific prior written */ -/* permission. */ -/* */ -/* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND */ -/* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE */ -/* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ -/* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS */ -/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR */ -/* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF */ -/* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS */ -/* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ -/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */ -/* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF */ -/* THE POSSIBILITY OF SUCH DAMAGE. */ -/******************************************************************************/ - -/* - * Copyright © 2007 Pierre Habouzit - */ - -#include -#include -#include -#include -#include - -#include "gai.h" - -#define GAI_SIGNO (SIGRTMIN+0) - -static struct { - gai_req **ring; - int start, len, size; -} fifo = { - .ring = NULL, - .start = 0, - .len = 0, - .size = 0, -}; - -static int gai_fifo_end(void) -{ - int res = fifo.start + fifo.len; - return res >= fifo.size ? res - fifo.size : fifo.size; -} - -static void gai_fifo_append(gai_req *rq) -{ - if (fifo.len >= fifo.size) { - p_realloc(&fifo.ring, fifo.size += 16); - } - - fifo.ring[gai_fifo_end()] = rq; - fifo.len++; -} - -static gai_req *gai_fifo_pop(void) -{ - gai_req *res = NULL; - - while (!res && fifo.len) { - res = fifo.ring[fifo.start]; - fifo.start++, fifo.len--; - if (fifo.start >= fifo.size) - fifo.start = 0; - } - - return res; -} - -static void gai_fifo_remove(gai_req *rq) -{ - int i, end = gai_fifo_end(); - - if (fifo.start + fifo.len <= fifo.size) { - for (i = fifo.start; i < end; i++) { - if (fifo.ring[i] == rq) - fifo.ring[i] = NULL; - } - } else { - for (i = fifo.start; i < fifo.size; i++) { - if (fifo.ring[i] == rq) - fifo.ring[i] = NULL; - } - for (i = 0; i < end; i++) { - if (fifo.ring[i] == rq) - fifo.ring[i] = NULL; - } - } -} - -static gai_req *gai_req_new(void) -{ - gai_req *rq = p_new(gai_req, 1); - rq->cbp = &rq->cb; - return rq; -} -static void gai_req_delete(gai_req **rqp) -{ - if (*rqp) { - gai_req *rq = *rqp; - - switch (gai_error(rq->cbp)) { - case EAI_INPROGRESS: - if (gai_cancel(rq->cbp) == EAI_NOTCANCELED) { - rq->caller = NULL; - *rqp = NULL; - return; - } - break; - - case EAI_CANCELED: - break; - - default: /* we are likely in the notify list remove us ! */ - if (rq->caller) { - gai_fifo_remove(rq); - } - } - - p_delete((char **)&rq->cb.ar_name); - freeaddrinfo(rq->cb.ar_result); - rq->cb.ar_result = NULL; - p_delete(rqp); - } -} - -gai_req *gai_query(job_t *caller, const char *lookup) -{ - struct sigevent se = { - .sigev_signo = GAI_SIGNO, - .sigev_notify = SIGEV_SIGNAL, - }; - gai_req *res; - - se.sigev_value.sival_ptr = res = gai_req_new(); - res->cb.ar_name = strdup(lookup); - res->caller = caller; - getaddrinfo_a(GAI_NOWAIT, &res->cbp, 1, &se); - - return res; -} - -void gai_abort(gai_req **rqp) -{ - gai_req_delete(rqp); -} - - -static void gai_sigaction(int sig, siginfo_t *si, void *ctx) -{ - gai_req *req = si->_sifields._rt.si_sigval.sival_ptr; - - assert (sig == GAI_SIGNO); - assert (req && gai_error(req->cbp) != EAI_INPROGRESS); - - if (req->caller) { - gai_fifo_append(req); - } else { - gai_req_delete(&req); - } -} - -void gai_initialize(void) -{ - struct sigaction sa = { - .sa_sigaction = &gai_sigaction, - .sa_flags = SA_SIGINFO, - }; - if (sigaction(GAI_SIGNO, &sa, NULL) < 0) { - syslog(LOG_ERR, "cannot hook SIGRTMIN+0: %m"); - exit(EX_OSERR); - } -} - -void gai_process(void) -{ - gai_req *req; - - while ((req = gai_fifo_pop())) { - assert (req->caller && req->caller->process); - req->caller->process(req->caller); - req->caller = NULL; /* make delete faster: avoid gai_fifo_remove() */ - } -} - -void gai_shutdown(void) -{ - /* TODO: deallocate the fifo properly */ -} diff --git a/gai.h b/gai.h deleted file mode 100644 index decc0ea..0000000 --- a/gai.h +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************/ -/* postlicyd: a postfix policy daemon with a lot of features */ -/* ~~~~~~~~~ */ -/* ________________________________________________________________________ */ -/* */ -/* Redistribution and use in source and binary forms, with or without */ -/* modification, are permitted provided that the following conditions */ -/* are met: */ -/* */ -/* 1. Redistributions of source code must retain the above copyright */ -/* notice, this list of conditions and the following disclaimer. */ -/* 2. Redistributions in binary form must reproduce the above copyright */ -/* notice, this list of conditions and the following disclaimer in the */ -/* documentation and/or other materials provided with the distribution. */ -/* 3. The names of its contributors may not be used to endorse or promote */ -/* products derived from this software without specific prior written */ -/* permission. */ -/* */ -/* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND */ -/* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE */ -/* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ -/* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS */ -/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR */ -/* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF */ -/* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS */ -/* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ -/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */ -/* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF */ -/* THE POSSIBILITY OF SUCH DAMAGE. */ -/******************************************************************************/ - -/* - * Copyright © 2007 Pierre Habouzit - */ - -#ifndef POSTLICYD_GAI_H -#define POSTLICYD_GAI_H - -#include - -#include "job.h" - -typedef struct gai_req { - struct gaicb cb; - struct gaicb *cbp; /* points to cb */ - job_t *caller; -} gai_req; - -gai_req *gai_query(job_t *, const char *lookup); -void gai_abort(gai_req **); - -void gai_initialize(void); -void gai_process(void); -void gai_shutdown(void); - -#endif diff --git a/job.c b/job.c index 454b35b..3d99a8f 100644 --- a/job.c +++ b/job.c @@ -55,7 +55,6 @@ #endif #include "job.h" -#include "gai.h" static int epollfd = -1; static bool sigint = false; @@ -202,8 +201,6 @@ void job_loop(void) job_delete(&job); } } - - gai_process(); } } diff --git a/postlicyd.c b/postlicyd.c index c20973e..ebf8260 100644 --- a/postlicyd.c +++ b/postlicyd.c @@ -39,14 +39,12 @@ #include #include "job.h" -#include "gai.h" bool cleanexit = false; static void main_initialize(void) { openlog("postlicyd", LOG_PID, LOG_MAIL); - gai_initialize(); job_initialize(); syslog(LOG_INFO, "Starting..."); } @@ -55,7 +53,6 @@ static void main_shutdown(void) { syslog(LOG_INFO, cleanexit ? "Stopping..." : "Unclean exit..."); job_shutdown(); - gai_shutdown(); closelog(); } -- 2.20.1