]> git.tue.mpg.de Git - paraslash.git/commitdiff
Fix config file handling for audiod and clean up init functions.
authorAndre Noll <maan@systemlinux.org>
Mon, 26 Jan 2009 22:27:50 +0000 (23:27 +0100)
committerAndre Noll <maan@systemlinux.org>
Mon, 26 Jan 2009 22:27:50 +0000 (23:27 +0100)
As noted by Gerrit Renker, audiod refused to start if the --config_file
option was not given and the default config file does not exist.

Fix this bug and rename some of the init functions to make the naming
more consistent.

audiod.c
filter.c
filter.h
filter_common.c
recv.c
recv.h
recv_common.c
write.c
write_common.c
write_common.h

index 6477c5474b60d83d557bce7239a5ac31451491de..e3fd49d3ba3666c29efd1bcbf0d43fa7089e9de0 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -193,6 +193,7 @@ static int want_colors(void)
 
 static void parse_config_or_die(void)
 {
+       int ret;
        char *config_file;
        struct audiod_cmdline_parser_params params = {
                .override = 0,
@@ -209,14 +210,13 @@ static void parse_config_or_die(void)
                config_file = make_message("%s/.paraslash/audiod.conf", home);
                free(home);
        }
-       if (conf.config_file_given && !file_exists(config_file)) {
+       ret = file_exists(config_file);
+       if (conf.config_file_given && !ret) {
                PARA_EMERG_LOG("can not read config file %s\n", config_file);
                goto err;
        }
-       if (audiod_cmdline_parser_config_file(config_file, &conf, &params)) {
-               PARA_EMERG_LOG("parse error in config file\n");
-               goto err;
-       }
+       if (ret)
+               audiod_cmdline_parser_config_file(config_file, &conf, &params);
        free(config_file);
        daemon_set_loglevel(conf.loglevel_arg);
        return;
@@ -596,13 +596,12 @@ static int add_filter(int format, char *cmdline)
        return filter_num;
 }
 
-static int init_writers(void)
+static int parse_writer_args(void)
 {
        int i, ret, nw;
        char *cmd;
        struct audio_format_info *a;
 
-       init_supported_writers();
        nw = PARA_MAX(1U, conf.writer_given);
        PARA_INFO_LOG("maximal number of writers: %d\n", nw);
        FOR_EACH_AUDIO_FORMAT(i) {
@@ -635,16 +634,12 @@ out:
        return ret;
 }
 
-static int init_receivers(void)
+static int parse_receiver_args(void)
 {
        int i, ret, receiver_num;
        char *cmd = NULL;
        struct audio_format_info *a;
 
-       for (i = 0; receivers[i].name; i++) {
-               PARA_INFO_LOG("initializing %s receiver\n", receivers[i].name);
-               receivers[i].init(&receivers[i]);
-       }
        for (i = conf.receiver_given - 1; i >= 0; i--) {
                char *arg = conf.receiver_arg[i];
                char *recv_arg = strchr(arg, ':');
@@ -715,11 +710,10 @@ out:
        return ret;
 }
 
-static int init_filters(void)
+static int parse_filter_args(void)
 {
        int i, ret, nf;
 
-       filter_init(filters);
        nf = PARA_MAX(1U, conf.filter_given);
        PARA_INFO_LOG("maximal number of filters: %d\n", nf);
        FOR_EACH_AUDIO_FORMAT(i) {
@@ -748,17 +742,17 @@ out:
        return ret;
 }
 
-static int init_stream_io(void)
+static int parse_stream_args(void)
 {
        int ret;
 
-       ret = init_writers();
+       ret = parse_receiver_args();
        if (ret < 0)
                return ret;
-       ret = init_receivers();
+       ret = parse_filter_args();
        if (ret < 0)
                return ret;
-       ret = init_filters();
+       ret = parse_writer_args();
        if (ret < 0)
                return ret;
        return 1;
@@ -1124,12 +1118,18 @@ int main(int argc, char *argv[])
        };
 
        valid_fd_012();
-       audiod_cmdline_parser_ext(argc, argv, &conf, &params);
+       if (audiod_cmdline_parser_ext(argc, argv, &conf, &params))
+               exit(EXIT_FAILURE);
        HANDLE_VERSION_FLAG("audiod", conf);
+       /* init receivers/filters/writers early to make help work */
+       recv_init();
+       filter_init();
+       writer_init();
        if (conf.help_given || conf.detailed_help_given)
                print_help_and_die();
        drop_privileges_or_die(conf.user_arg, conf.group_arg);
        parse_config_or_die();
+       init_colors_or_die();
        daemon_set_flag(DF_LOG_TIME);
        daemon_set_flag(DF_LOG_HOSTNAME);
        daemon_set_flag(DF_LOG_LL);
@@ -1137,10 +1137,9 @@ int main(int argc, char *argv[])
                daemon_set_logfile(conf.logfile_arg);
                daemon_open_log_or_die();
        }
-       init_colors_or_die();
-       i = init_stream_io();
-       if (i < 0) {
-               PARA_EMERG_LOG("init stream io error: %s\n", para_strerror(-i));
+       ret = parse_stream_args();
+       if (ret < 0) {
+               PARA_EMERG_LOG("%s\n", para_strerror(-ret));
                exit(EXIT_FAILURE);
        }
        log_welcome("para_audiod");
index 96880b7d31922221b9eb90e25a52a258a60d3245..9311a20a6f0ef035f9491c2d3856006a8cd2f3f5 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -159,7 +159,7 @@ int main(int argc, char *argv[])
        stdin_set_defaults(sit);
        sit->buf = para_malloc(sit->bufsize),
 
-       filter_init(filters);
+       filter_init();
        ret = parse_config(argc, argv);
        if (ret < 0)
                goto out;
index 2c546c1d21f281529fcda364987e8802b4b52036..da4729056a7cf8cd5c08800dc3b2ee617416d234 100644 (file)
--- a/filter.h
+++ b/filter.h
@@ -202,7 +202,7 @@ struct filter {
 };
 
 void close_filters(struct filter_chain *fc);
-void filter_init(struct filter *all_filters);
+void filter_init(void);
 int check_filter_arg(char *filter_arg, void **conf);
 void filter_pre_select(__a_unused struct sched *s, struct task *t);
 void print_filter_helps(int detailed);
index d83629bd4bf9d2b3f609ba71d36b5c7afcfc04a8..285efe68d56cefac4ea05dc3f6102db4cda89fa4 100644 (file)
@@ -28,12 +28,12 @@ struct filter filters[NUM_SUPPORTED_FILTERS] = {FILTER_ARRAY};
  *
  * \sa filter::init
  */
-void filter_init(struct filter *all_filters)
+void filter_init(void)
 {
        int i;
 
        FOR_EACH_SUPPORTED_FILTER(i)
-               all_filters[i].init(all_filters + i);
+               filters[i].init(filters + i);
 }
 
 /**
diff --git a/recv.c b/recv.c
index df8b9ce99e445f3acce568486c02878276f03576..4f595e39aae21cbef207fc1418c5973d0fbd68a1 100644 (file)
--- a/recv.c
+++ b/recv.c
@@ -79,8 +79,7 @@ int main(int argc, char *argv[])
 
        memset(&sot, 0, sizeof(struct stdout_task));
        memset(&rn, 0, sizeof(struct receiver_node));
-       FOR_EACH_RECEIVER(ret)
-               receivers[ret].init(&receivers[ret]);
+       recv_init();
        ret = -E_RECV_SYNTAX;
        rn.conf = parse_config(argc, argv, &receiver_num);
        if (!rn.conf) {
diff --git a/recv.h b/recv.h
index b82e04f506c3dcad9ac43ad8796d0786aa2f1d9b..dc49ef956e69779f518ad235c6c25e76b1761498 100644 (file)
--- a/recv.h
+++ b/recv.h
@@ -131,5 +131,6 @@ extern struct receiver receivers[];
 /** Iterate over all available receivers. */
 #define FOR_EACH_RECEIVER(i) for (i = 0; receivers[i].name; i++)
 
+void recv_init(void);
 void *check_receiver_arg(char *ra, int *receiver_num);
 void print_receiver_helps(int detailed);
index 2840df00b4317d143bcadec5637e0ca4d1200ef7..953e2a1143ebd28424fb09a978611eaf52bf28d6 100644 (file)
 #include "string.h"
 
 DEFINE_RECEIVER_ARRAY;
+
+/**
+ * Call the init function of each paraslash receiver.
+ */
+void recv_init(void)
+{
+       int i;
+
+       FOR_EACH_RECEIVER(i)
+               receivers[i].init(&receivers[i]);
+}
+
 static void *parse_receiver_args(int receiver_num, char *options)
 {
        struct receiver *r = &receivers[receiver_num];
@@ -100,7 +112,6 @@ void print_receiver_helps(int detailed)
        printf_or_die("\n\n");
        FOR_EACH_RECEIVER(i) {
                struct receiver *r = receivers + i;
-
                if (!r->help.short_help)
                        continue;
                printf_or_die("Options for %s:\n", r->name);
diff --git a/write.c b/write.c
index 238f2ab9d4d1c39f4b4b0e0bca46632c6c44762c..c5a265652ec68c3b92e87f9ed93bbea9fcbc8364 100644 (file)
--- a/write.c
+++ b/write.c
@@ -196,7 +196,7 @@ int main(int argc, char *argv[])
        struct check_wav_task *cwt = &the_check_wav_task;
        struct initial_delay_task *idt = &the_initial_delay_task;
 
-       init_supported_writers();
+       writer_init();
        write_cmdline_parser(argc, argv, &conf);
        HANDLE_VERSION_FLAG("write", conf);
        if (conf.help_given || conf.detailed_help_given)
index 8fb6c3d10797c4fc7ea4119de5c990271f177482..8133577b91fbfdf9665b4d3b1b54dd3ac6fb014f 100644 (file)
@@ -144,9 +144,9 @@ struct writer_node_group *wng_new(unsigned num_writers)
 }
 
 /**
- * call the init function of each supported paraslash writer
+ * Call the init function of each supported paraslash writer.
  */
-void init_supported_writers(void)
+void writer_init(void)
 {
        int i;
 
index 18e5e838fee3843852d424e60af62f1205f960e4..5edebe1173accfecfd96f0cad186b6335627e9b6 100644 (file)
@@ -9,7 +9,7 @@
 int wng_open(struct writer_node_group *g);
 void wng_close(struct writer_node_group *g);
 struct writer_node_group *wng_new(unsigned num_writers);
-void init_supported_writers(void);
+void writer_init(void);
 void *check_writer_arg(const char *wa, int *writer_num);
 struct writer_node_group *setup_default_wng(void);
 void print_writer_helps(int detailed);