GENERATED = tokens.h tokens.c
-postlicyd_SOURCES = common.c str.c buffer.c rbl.c \
+postlicyd_SOURCES = common.c epoll.c str.c buffer.c rbl.c \
$(GENERATED) postfix.c main-postlicyd.c
postlicyd_LIBADD = -lpthread
-pfix-srsd_SOURCES = common.c buffer.c str.c main-srsd.c
+pfix-srsd_SOURCES = common.c epoll.c buffer.c str.c main-srsd.c
pfix-srsd_LIBADD = -lsrs2
tst-rbl_SOURCES = tst-rbl.c
--- /dev/null
+/******************************************************************************/
+/* pfixtools: a collection of postfix related tools */
+/* ~~~~~~~~~ */
+/* ________________________________________________________________________ */
+/* */
+/* 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 "epoll.h"
+
+int epollfd = -1;
+
+static int epoll_initialize(void)
+{
+ epollfd = epoll_create(128);
+ return epollfd < 0 ? -1 : 0;
+}
+
+static void epoll_shutdown(void)
+{
+ close(epollfd);
+}
+
+module_init(epoll_initialize);
+module_exit(epoll_shutdown);
--- /dev/null
+/******************************************************************************/
+/* pfixtools: a collection of postfix related tools */
+/* ~~~~~~~~~ */
+/* ________________________________________________________________________ */
+/* */
+/* 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 <sys/epoll.h>
+
+#include "common.h"
+
+extern int epollfd;
+
* Copyright © 2006-2007 Pierre Habouzit
*/
-#include <signal.h>
-#include <time.h>
#include <getopt.h>
#include "common.h"
+#include "epoll.h"
/* administrivia {{{ */
int fd = (intptr_t)_fd;
close(fd);
+ pthread_detach(pthread_self());
return NULL;
}
-static void main_loop(void)
+static int main_loop(void)
{
+ int exitcode = EXIT_SUCCESS;
int sock = -1;
while (!sigint) {
int fd = accept(sock, NULL, 0);
- pthread_attr_t attr;
pthread_t dummy;
if (fd < 0) {
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);
+ pthread_create(&dummy, NULL, job_run, (void *)(intptr_t)fd);
}
close(sock);
+ return exitcode;
}
-int main(void)
+int main(int argc, char *argv[])
{
- if (atexit(common_shutdown)) {
- fputs("Cannot hook my atexit function, quitting !\n", stderr);
+ const char *pidfile = NULL;
+ FILE *f = NULL;
+ int res;
+
+ common_initialize();
+ for (int c = 0; (c = getopt(argc, argv, "h" "p:")) >= 0; ) {
+ switch (c) {
+ case 'p':
+ pidfile = optarg;
+ break;
+ default:
+ //usage();
+ 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 (daemon_detach() < 0) {
+ syslog(LOG_CRIT, "unable to fork");
return EXIT_FAILURE;
}
- common_initialize();
- main_loop();
+ if (f) {
+ rewind(f);
+ ftruncate(fileno(f), 0);
+ fprintf(f, "%d\n", getpid());
+ fflush(f);
+ }
+ res = main_loop();
+ if (f) {
+ rewind(f);
+ ftruncate(fileno(f), 0);
+ fclose(f);
+ f = NULL;
+ }
syslog(LOG_INFO, "Stopping...");
- return EXIT_SUCCESS;
+ return res;
}
* Copyright © 2005-2007 Pierre Habouzit
*/
-#include <fcntl.h>
-#include <netinet/in.h>
-#include <sys/epoll.h>
-#include <sys/stat.h>
+#include "common.h"
#include <srs2.h>
-#include "common.h"
+#include "epoll.h"
#include "mem.h"
#include "buffer.h"
return 0;
}
-int start_listener(int epollfd, int port, bool decoder)
+int start_listener(int port, bool decoder)
{
struct sockaddr_in addr = {
.sin_family = AF_INET,
int main_loop(srs_t *srs, const char *domain, int port_enc, int port_dec)
{
int exitcode = EXIT_SUCCESS;
- int epollfd = epoll_create(128);
-
- if (epollfd < 0) {
- UNIXERR("epoll_create");
- exitcode = EXIT_FAILURE;
- goto error;
- }
- if (start_listener(epollfd, port_enc, false) < 0)
+ if (start_listener(port_enc, false) < 0)
return EXIT_FAILURE;
- if (start_listener(epollfd, port_dec, true) < 0)
+ if (start_listener(port_dec, true) < 0)
return EXIT_FAILURE;
while (!sigint) {
}
}
- close(epollfd);
-
- error:
return exitcode;
}
int res;
srs_t *srs;
- if (atexit(common_shutdown)) {
- fputs("Cannot hook my atexit function, quitting !\n", stderr);
- return EXIT_FAILURE;
- }
common_initialize();
- for (int c = 0; (c = getopt(argc, argv, "he:d:p:u")) >= 0; ) {
+ for (int c = 0; (c = getopt(argc, argv, "hu" "e:d:p:")) >= 0; ) {
switch (c) {
case 'e':
port_enc = atoi(optarg);