Add -c option to specify keyd config file on command line
authorJonathan McDowell <noodles@earth.li>
Wed, 16 Mar 2011 02:50:25 +0000 (02:50 +0000)
committerJonathan McDowell <noodles@earth.li>
Wed, 16 Mar 2011 02:50:25 +0000 (02:50 +0000)
  Matches the parameter the onak binary takes and allows use of
  something other than the compiled in default config file path.

keyd.c

diff --git a/keyd.c b/keyd.c
index 33af8ea0e3935768e75a021d9c2bd781db163383..05f9fe9b025742dbad205741d4f881002b446770 100644 (file)
--- a/keyd.c
+++ b/keyd.c
@@ -2,11 +2,12 @@
  * keyd.c - key retrieval daemon
  *
  * Jonathan McDowell <noodles@earth.li>
  * keyd.c - key retrieval daemon
  *
  * Jonathan McDowell <noodles@earth.li>
- * 
+ *
  * Copyright 2004 Project Purple
  */
 
 #include <fcntl.h>
  * Copyright 2004 Project Purple
  */
 
 #include <fcntl.h>
+#include <getopt.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -341,8 +342,20 @@ int main(int argc, char *argv[])
        int fd = -1;
        fd_set rfds;
        char sockname[1024];
        int fd = -1;
        fd_set rfds;
        char sockname[1024];
+       char *configfile = NULL;
+       int optchar;
 
 
-       readconfig(NULL);
+       while ((optchar = getopt(argc, argv, "c:")) != -1 ) {
+               switch (optchar) {
+               case 'c':
+                       configfile = strdup(optarg);
+                       break;
+               }
+       }
+
+       readconfig(configfile);
+       free(configfile);
+       configfile = NULL;
        initlogthing("keyd", config.logfile);
 
        catchsignals();
        initlogthing("keyd", config.logfile);
 
        catchsignals();
@@ -369,6 +382,6 @@ int main(int argc, char *argv[])
 
        cleanuplogthing();
        cleanupconfig();
 
        cleanuplogthing();
        cleanupconfig();
-       
+
        return(EXIT_SUCCESS);
 }
        return(EXIT_SUCCESS);
 }