From: Martin Johansson Date: Thu, 6 Oct 2011 15:57:04 +0000 (-0400) Subject: Add config file test flag to umurmurd. X-Git-Url: http://git.code-monkey.de/?p=umurmur.git;a=commitdiff_plain;h=00d6addea82c3c75ac784f9c7877ef61a382492b Add config file test flag to umurmurd. --- diff --git a/src/conf.c b/src/conf.c index 2873a9e..2a83e53 100644 --- a/src/conf.c +++ b/src/conf.c @@ -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() diff --git a/src/conf.h b/src/conf.h index 67d02c6..20141dc 100644 --- a/src/conf.h +++ b/src/conf.h @@ -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); diff --git a/src/main.c b/src/main.c index 1e22885..b7e5b1d 100644 --- a/src/main.c +++ b/src/main.c @@ -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 ] [-c ] [-a ] [-b ]\n"); + printf("Usage: umurmurd [-d] [-r] [-h] [-p ] [-t] [-c ] [-a ] [-b ]\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 - Write PID to this file\n"); printf(" -c - 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
- Bind to IP address\n"); printf(" -b - 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. */