Add options details to keyd man page
[onak.git] / keyd.c
diff --git a/keyd.c b/keyd.c
index 919b61b899a886609f29caebf86e841b725c9fce..c2d83491ea91fc6e23dcd75ee57ff0a9bbef1ec9 100644 (file)
--- a/keyd.c
+++ b/keyd.c
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -18,6 +19,7 @@
 #include <sys/un.h>
 #include <unistd.h>
 
+#include "config.h"
 #include "charfuncs.h"
 #include "cleanup.h"
 #include "keyd.h"
@@ -334,6 +336,8 @@ int sock_do(int fd)
                case KEYD_CMD_QUIT:
                        cmd = KEYD_REPLY_OK;
                        write(fd, &cmd, sizeof(cmd));
+                       logthing(LOGTHING_NOTICE,
+                               "Exiting due to quit request.");
                        ret = 1;
                        trytocleanup();
                        break;
@@ -375,6 +379,19 @@ int sock_accept(int fd)
        return 1;
 }
 
+static void usage(void)
+{
+       puts("keyd " PACKAGE_VERSION " - backend key serving daemon for the "
+               "onak PGP keyserver.\n");
+       puts("Usage:\n");
+       puts("\tkeyd [options]\n");
+       puts("\tOptions:\n:");
+       puts("-c <file> - use <file> as the config file");
+       puts("-f        - run in the foreground");
+       puts("-h        - show this help text");
+       exit(EXIT_FAILURE);
+}
+
 int main(int argc, char *argv[])
 {
        int fd = -1;
@@ -384,7 +401,7 @@ int main(int argc, char *argv[])
        bool foreground = false;
        int optchar;
 
-       while ((optchar = getopt(argc, argv, "c:f")) != -1 ) {
+       while ((optchar = getopt(argc, argv, "c:fh")) != -1 ) {
                switch (optchar) {
                case 'c':
                        configfile = strdup(optarg);
@@ -392,6 +409,10 @@ int main(int argc, char *argv[])
                case 'f':
                        foreground = true;
                        break;
+               case 'h':
+               default:
+                       usage();
+                       break;
                }
        }
 
@@ -406,7 +427,8 @@ int main(int argc, char *argv[])
        }
 
        catchsignals();
-       
+       signal(SIGPIPE, SIG_IGN);
+
        snprintf(sockname, 1023, "%s/%s", config.db_dir, KEYD_SOCKET);
        fd = sock_init(sockname);