Add config file test flag to umurmurd.
authorMartin Johansson <martin@fatbob.nu>
Thu, 6 Oct 2011 15:57:04 +0000 (11:57 -0400)
committerMartin Johansson <martin@fatbob.nu>
Thu, 6 Oct 2011 15:57:04 +0000 (11:57 -0400)
src/conf.c
src/conf.h
src/main.c

index 2873a9e40e7d5bd6da75a2ee9137b6d1f34b5919..2a83e53e0712025f072a3587f4d29d3bb8ff86a1 100644 (file)
@@ -58,16 +58,19 @@ void Conf_init(const char *conffile)
        }
 }
 
-void Conf_test(const char *conffile)
+bool_t Conf_ok(const char *conffile)
 {
+       bool_t rc = true;
        config_init(&configuration);
        if (conffile == NULL)
                conffile = defaultconfig;
        if (config_read_file(&configuration, conffile) != CONFIG_TRUE) {
-               fprintf(stderr, "Error in config file %s line %d: %s", conffile,
+               fprintf(stderr, "Error in config file %s line %d: %s\n", conffile,
                        config_error_line(&configuration), config_error_text(&configuration));
-               exit(1);
+               rc = false;
        }
+       config_destroy(&configuration);
+       return rc;
 }
 
 void Conf_deinit()
index 67d02c689808ad672eac5d37bcad6aca06ae116b..20141dcca468d06a8f3d242d591130c1fc6fb912 100644 (file)
@@ -65,7 +65,7 @@ typedef struct {
 
 void Conf_init(const char *conffile);
 void Conf_deinit();
-void Conf_test(const char *conffile);
+bool_t Conf_ok(const char *conffile);
 
 const char *getStrConf(param_t param);
 int getIntConf(param_t param);
index 1e22885389947ed03be9ea01508c7d36d236f0b4..b7e5b1d1596470818670403d562f167284ac60a9 100644 (file)
@@ -217,16 +217,17 @@ void setscheduler()
 void printhelp()
 {
        printf("uMurmur version %s. Mumble protocol %d.%d.%d\n", UMURMUR_VERSION, PROTVER_MAJOR, PROTVER_MINOR, PROTVER_PATCH);
-       printf("Usage: umurmurd [-d] [-r] [-h] [-p <pidfile>] [-c <conf file>] [-a <addr>] [-b <port>]\n");
+       printf("Usage: umurmurd [-d] [-r] [-h] [-p <pidfile>] [-t] [-c <conf file>] [-a <addr>] [-b <port>]\n");
        printf("       -d             - Do not daemonize - run in foreground.\n");
 #ifdef _POSIX_PRIORITY_SCHEDULING
        printf("       -r             - Run with realtime priority\n");
 #endif
-       printf("       -h             - Print this help\n");
        printf("       -p <pidfile>   - Write PID to this file\n");
        printf("       -c <conf file> - Specify configuration file (default %s)\n", DEFAULT_CONFIG);
+       printf("       -t             - Test config. Error message to stderr + non-zero exit code on error\n");
        printf("       -a <address>   - Bind to IP address\n");
        printf("       -b <port>      - Bind to port\n");
+       printf("       -h             - Print this help\n");
        exit(0);
 }
 
@@ -234,7 +235,7 @@ int main(int argc, char **argv)
 {
        bool_t nodaemon = false;
 #ifdef _POSIX_PRIORITY_SCHEDULING
-       bool_t realtime = false;
+       bool_t realtime = false, testconfig = false;
 #endif
        char *conffile = NULL, *pidfile = NULL;
        int c;
@@ -242,9 +243,9 @@ int main(int argc, char **argv)
        
        /* Arguments */
 #ifdef _POSIX_PRIORITY_SCHEDULING
-       while ((c = getopt(argc, argv, "drp:c:a:b:h")) != EOF) {
+       while ((c = getopt(argc, argv, "drp:c:a:b:ht")) != EOF) {
 #else
-       while ((c = getopt(argc, argv, "dp:c:a:b:h")) != EOF) {
+       while ((c = getopt(argc, argv, "dp:c:a:b:ht")) != EOF) {
 #endif
                switch(c) {
                case 'c':
@@ -265,6 +266,9 @@ int main(int argc, char **argv)
                case 'h':
                        printhelp();
                        break;
+               case 't':
+                       testconfig = true;
+                       break;
 #ifdef _POSIX_PRIORITY_SCHEDULING
                case 'r':
                        realtime = true;
@@ -276,7 +280,14 @@ int main(int argc, char **argv)
                        break;
                }
        }
-       
+
+       if (testconfig) {
+               if (!Conf_ok(conffile))
+                       exit(1);
+               else
+                       exit(0);
+       }
+               
        /* Initialize the config subsystem early;
         * switch_user() will need to read some config variables as well as logging.
         */