#include <getopt.h>
-#include "common.h"
#include "epoll.h"
+#include "threads.h"
+
+#define DAEMON_NAME "postlicyd"
/* administrivia {{{ */
module_init(main_initialize);
module_exit(main_shutdown);
+void usage(void)
+{
+ fputs("usage: "DAEMON_NAME" [options] config\n"
+ "\n"
+ "Options:\n"
+ " -p <pidfile> file to write our pid to\n"
+ , stderr);
+}
+
/* }}} */
-void *job_run(void *_fd)
+void *job_run(int fd, void *data)
{
- int fd = (intptr_t)_fd;
-
close(fd);
- pthread_detach(pthread_self());
return NULL;
}
while (!sigint) {
int fd = accept(sock, NULL, 0);
- pthread_t dummy;
-
if (fd < 0) {
if (errno != EINTR || errno != EAGAIN)
UNIXERR("accept");
continue;
}
- pthread_create(&dummy, NULL, job_run, (void *)(intptr_t)fd);
+ thread_launch(job_run, fd, NULL);
+ threads_join();
}
close(sock);
pidfile = optarg;
break;
default:
- //usage();
+ usage();
return EXIT_FAILURE;
}
}
+ if (argc - optind != 1) {
+ usage();
+ return EXIT_FAILURE;
+ }
+
if (pidfile) {
f = fopen(pidfile, "w");
if (!f) {