Implement usage
[apps/pfixtools.git] / main-postlicyd.c
index 01eb9e6..04172dd 100644 (file)
 
 #include <getopt.h>
 
-#include "common.h"
 #include "epoll.h"
+#include "threads.h"
+
+#define DAEMON_NAME             "postlicyd"
 
 /* administrivia {{{ */
 
@@ -59,14 +61,20 @@ static void main_shutdown(void)
 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;
 }
 
@@ -77,15 +85,14 @@ static int main_loop(void)
 
     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);
@@ -104,11 +111,16 @@ int main(int argc, char *argv[])
             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) {