]> git.tue.mpg.de Git - paraslash.git/commitdiff
audiod: Implement --config-file option.
authorAndre Noll <maan@systemlinux.org>
Sun, 14 Dec 2008 12:03:48 +0000 (13:03 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 14 Dec 2008 12:03:48 +0000 (13:03 +0100)
NEWS
audiod.c
audiod.ggo

diff --git a/NEWS b/NEWS
index 3874bed194fc18785e537492725066e757504228..8418cd8a13ea75e6eec656c0beafd15f7f702a20 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ NEWS
        - Improved help/man pages: The documentation of para_audiod,
          para_recv, para_filter and para_write now also contains
          all options of the available receivers/filters/writers.
+       - new audiod option: --config-file.
 
 --------------------------------------------
 0.3.3 (2008-12-01) "axiomatic perspectivity"
index e3db6bea822d4f6fd5954e19436f28358b13d906..63d42cacb5218b92a8cea76c8a0626349437b8e6 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -214,16 +214,39 @@ __printf_2_3 void para_log(int ll, const char* fmt,...)
        va_end(argp);
 }
 
-static char *configfile_exists(void)
+static void parse_config_or_die(void)
 {
-       char *home = para_homedir();
-       char *config_file = make_message("%s/.paraslash/audiod.conf",
-               home);
-       free(home);
-       if (file_exists(config_file))
-               return config_file;
+       char *config_file;
+
+       if (conf.config_file_given)
+               config_file = para_strdup(conf.config_file_arg);
+       else {
+               char *home = para_homedir();
+               config_file = make_message("%s/.paraslash/audiod.conf", home);
+               free(home);
+       }
+       if (conf.config_file_given && !file_exists(config_file)) {
+               PARA_EMERG_LOG("can not read config file %s\n", config_file);
+               goto err;
+       }
+       if (config_file) {
+               struct audiod_cmdline_parser_params params = {
+                       .override = 0,
+                       .initialize = 0,
+                       .check_required = 1,
+                       .check_ambiguity = 0,
+                       .print_errors = 1
+               };
+               if (audiod_cmdline_parser_config_file(config_file, &conf, &params)) {
+                       PARA_EMERG_LOG("parse error in config file\n");
+                       goto err;
+               }
+       }
        free(config_file);
-       return NULL;
+       return;
+err:
+       free(config_file);
+       exit(EXIT_FAILURE);
 }
 
 static void setup_signal_handling(void)
@@ -1099,7 +1122,6 @@ __noreturn static void print_help_and_die(void)
  * */
 int main(int argc, char *argv[])
 {
-       char *config_file;
        int ret, i;
        static struct sched s;
        struct command_task command_task_struct, *cmd_task = &command_task_struct;
@@ -1115,29 +1137,17 @@ int main(int argc, char *argv[])
        audiod_cmdline_parser_ext(argc, argv, &conf, &params);
        HANDLE_VERSION_FLAG("audiod", conf);
        para_drop_privileges(conf.user_arg, conf.group_arg);
-       config_file = configfile_exists();
-       if (config_file) {
-               params.override = 0;
-               params.initialize = 0;
-               params.check_required = 1;
-               params.check_ambiguity = 0;
-               params.print_errors = 1;
-               if (audiod_cmdline_parser_config_file(config_file, &conf, &params)) {
-                       PARA_EMERG_LOG("parse error in config file\n");
-                       exit(EXIT_FAILURE);
-               }
-               free(config_file);
-       }
+       parse_config_or_die();
        if (conf.logfile_given)
                logfile = open_log(conf.logfile_arg);
        i = init_stream_io();
        if (conf.help_given || conf.detailed_help_given)
                print_help_and_die();
-       log_welcome("para_audiod", conf.loglevel_arg);
        if (i < 0) {
                PARA_EMERG_LOG("init stream io error: %s\n", para_strerror(-i));
                exit(EXIT_FAILURE);
        }
+       log_welcome("para_audiod", conf.loglevel_arg);
        server_uptime(UPTIME_SET);
        set_initial_status();
        FOR_EACH_SLOT(i)
index 3df0937e1a962a9a3f04711e7850e2f0f8d4645f..8f960c67c1cedae66a6fd9c47873cfc3ca3b1ffc 100644 (file)
@@ -14,6 +14,12 @@ int typestr="level"
 default="4"
 optional
 
+option "config_file" c
+#~~~~~~~~~~~~~~~~~~~~~
+"(default='~/.paraslash/audiod.conf'"
+string typestr="filename"
+optional
+
 option "logfile" L
 #~~~~~~~~~~~~~~~~~
 "where to write log output"