Avoid unwanted log messages during startup.
authorAndre Noll <maan@systemlinux.org>
Mon, 1 Apr 2013 22:52:20 +0000 (22:52 +0000)
committerAndre Noll <maan@systemlinux.org>
Thu, 13 Jun 2013 16:29:03 +0000 (18:29 +0200)
Regardless of the given loglevel, para_recv currently prints log
messages like these at startup:

afh_init: initializing mp3 handler
afh_init: initializing ogg handler
afh_init: initializing aac handler
afh_init: initializing wma handler
afh_init: initializing spx handler
afh_init: initializing flac handler

That's because recv_init() is called before the command line arguments
are parsed, so the loglevel has not been set at this point. Other
programs have similar problems.

Fix these problems by always setting the loglevel right after a parser
has been called so that the init functions run *after* loglevel has
been set.

afh.c
audioc.c
audiod.c
fade.c
filter.c
gui.c
play.c
recv.c
server.c
write.c

diff --git a/afh.c b/afh.c
index 4c65d7c1f76bdc4b054461127d14b9547881d6f7..699a6d8f83896353c3a6e7eea6d1d8d8a8d5f8ac 100644 (file)
--- a/afh.c
+++ b/afh.c
@@ -72,8 +72,8 @@ int main(int argc, char **argv)
        struct afh_info afhi;
 
        afh_cmdline_parser(argc, argv, &conf);
-       HANDLE_VERSION_FLAG("afh", conf);
        loglevel = get_loglevel_by_name(conf.loglevel_arg);
+       HANDLE_VERSION_FLAG("afh", conf);
        ret = -E_AFH_SYNTAX;
        if (conf.inputs_num == 0)
                goto out;
index b0f822b733d42b3cc22eadc2515cbbb3e61439a7..6a8867182e42bb1a7d6041d4ae0e55fbcba1164d 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -287,6 +287,7 @@ int main(int argc, char *argv[])
 
        audioc_cmdline_parser(argc, argv, &conf);
        HANDLE_VERSION_FLAG("audioc", conf);
+       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        cf = configfile_exists();
        if (cf) {
                struct audioc_cmdline_parser_params params = {
@@ -299,8 +300,8 @@ int main(int argc, char *argv[])
                };
                audioc_cmdline_parser_config_file(cf, &conf, &params);
                free(cf);
+               loglevel = get_loglevel_by_name(conf.loglevel_arg);
        }
-       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        if (conf.socket_given)
                socket_name = para_strdup(conf.socket_arg);
        else {
index 4100d4144821df46a2be1c9fc6e2f96472733e2e..e3e3bd9acd9b2ccd771fc359f4e57ae24dbe5cce 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -343,10 +343,11 @@ static void parse_config_or_die(void)
                PARA_EMERG_LOG("can not read config file %s\n", config_file);
                goto err;
        }
-       if (ret)
+       if (ret) {
                audiod_cmdline_parser_config_file(config_file, &conf, &params);
+               daemon_set_loglevel(conf.loglevel_arg);
+       }
        free(config_file);
-       daemon_set_loglevel(conf.loglevel_arg);
        return;
 err:
        free(config_file);
@@ -1352,6 +1353,7 @@ int main(int argc, char *argv[])
        valid_fd_012();
        audiod_cmdline_parser_ext(argc, argv, &conf, &params);
        HANDLE_VERSION_FLAG("audiod", conf);
+       daemon_set_loglevel(conf.loglevel_arg);
        /* init receivers/filters/writers early to make help work */
        recv_init();
        filter_init();
diff --git a/fade.c b/fade.c
index d2ab8287e88973e38066ff97e80ff738a17e144b..e6f550a1c94d37806b28b25b8ac17bf5b7bd10ed 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -294,6 +294,7 @@ int main(int argc, char *argv[])
 
        fade_cmdline_parser(argc, argv, &conf);
        HANDLE_VERSION_FLAG("fade", conf);
+       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        ret = configfile_exists();
        if (!ret && conf.config_file_given) {
                PARA_EMERG_LOG("can not read config file %s\n",
@@ -310,8 +311,8 @@ int main(int argc, char *argv[])
                };
                fade_cmdline_parser_config_file(conf.config_file_arg,
                        &conf, &params);
+               loglevel = get_loglevel_by_name(conf.loglevel_arg);
        }
-       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        init_mixers();
        m = get_mixer_or_die();
        ret = m->open(conf.mixer_device_arg, &h);
index 84ad8577120daf92c338a842e0567da91fa9968b..c6af586df8cc4451413749664dd45630856d9bfa 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -60,16 +60,14 @@ __noreturn static void print_help_and_die(void)
        exit(0);
 }
 
-static int parse_config(int argc, char *argv[])
+static int parse_config(void)
 {
        static char *cf; /* config file */
        struct stat statbuf;
 
-       filter_cmdline_parser(argc, argv, &conf);
        HANDLE_VERSION_FLAG("filter", conf);
        if (conf.help_given || conf.detailed_help_given)
                print_help_and_die();
-       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        if (!cf) {
                char *home = para_homedir();
                cf = make_message("%s/.paraslash/filter.conf", home);
@@ -84,6 +82,7 @@ static int parse_config(int argc, char *argv[])
                        .print_errors = 1
                };
                filter_cmdline_parser_config_file(cf, &conf, &params);
+               loglevel = get_loglevel_by_name(conf.loglevel_arg);
        }
        if (!conf.filter_given)
                return -E_NO_FILTERS;
@@ -110,8 +109,10 @@ int main(int argc, char *argv[])
        struct btr_node *parent;
        struct filter_node **fns;
 
+       filter_cmdline_parser(argc, argv, &conf); /* aborts on errors */
+       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        filter_init();
-       ret = parse_config(argc, argv);
+       ret = parse_config();
        if (ret < 0)
                goto out;
        sit->btrn = btr_new_node(&(struct btr_node_description)
diff --git a/gui.c b/gui.c
index e157dd1ac184d18958e19f1c95b5f937cccd9f08..5092315e681f086c365f4af2644ec7e540532817 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -1521,6 +1521,7 @@ int main(int argc, char *argv[])
 
        gui_cmdline_parser(argc, argv, &conf); /* exits on errors */
        HANDLE_VERSION_FLAG("gui", conf);
+       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        cf = configfile_exists();
        if (!cf && conf.config_file_given) {
                fprintf(stderr, "can not read config file %s\n",
@@ -1536,8 +1537,8 @@ int main(int argc, char *argv[])
                        .print_errors = 1,
                };
                gui_cmdline_parser_config_file(cf, &conf, &params);
+               loglevel = get_loglevel_by_name(conf.loglevel_arg);
        }
-       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        if (check_key_map_args() < 0) {
                fprintf(stderr, "invalid key map\n");
                exit(EXIT_FAILURE);
diff --git a/play.c b/play.c
index 83d28514fb15713b35fef165e130dd923d057613..814ec16a5288cd7ba4be5c0bbea275a9fc812ef6 100644 (file)
--- a/play.c
+++ b/play.c
@@ -178,9 +178,9 @@ static void parse_config_or_die(int argc, char *argv[])
 
        play_cmdline_parser_ext(argc, argv, &conf, &params);
        HANDLE_VERSION_FLAG("play", conf);
+       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        if (conf.help_given || conf.detailed_help_given)
                print_help_and_die();
-       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        if (conf.config_file_given)
                config_file = para_strdup(conf.config_file_arg);
        else {
@@ -197,6 +197,7 @@ static void parse_config_or_die(int argc, char *argv[])
                params.initialize = 0;
                params.check_required = 1;
                play_cmdline_parser_config_file(config_file, &conf, &params);
+               loglevel = get_loglevel_by_name(conf.loglevel_arg);
        }
        for (i = 0; i < conf.key_map_given; i++) {
                char *s = strchr(conf.key_map_arg[i] + 1, ':');
diff --git a/recv.c b/recv.c
index b03c5714b23b23c305b5b0e1114ea5326cd1f841..bc727de0cb65a102c8f1861d75d31c713b748a19 100644 (file)
--- a/recv.c
+++ b/recv.c
@@ -52,16 +52,6 @@ __noreturn static void print_help_and_die(void)
        exit(0);
 }
 
-static void *parse_config(int argc, char *argv[], int *receiver_num)
-{
-       recv_cmdline_parser(argc, argv, &conf);
-       HANDLE_VERSION_FLAG("recv", conf);
-       if (conf.help_given || conf.detailed_help_given)
-               print_help_and_die();
-       loglevel = get_loglevel_by_name(conf.loglevel_arg);
-       return check_receiver_arg(conf.receiver_arg, receiver_num);
-}
-
 /**
  * The main function of para_recv.
  *
@@ -81,16 +71,18 @@ int main(int argc, char *argv[])
        struct stdout_task sot;
        static struct sched s;
 
-       s.default_timeout.tv_sec = 1;
-       s.default_timeout.tv_usec = 0;
+       recv_cmdline_parser(argc, argv, &conf);
+       loglevel = get_loglevel_by_name(conf.loglevel_arg);
+       HANDLE_VERSION_FLAG("recv", conf);
+       recv_init();
+       if (conf.help_given || conf.detailed_help_given)
+               print_help_and_die();
 
-       memset(&sot, 0, sizeof(struct stdout_task));
        memset(&rn, 0, sizeof(struct receiver_node));
-       recv_init();
-       ret = -E_RECV_SYNTAX;
-       rn.conf = parse_config(argc, argv, &receiver_num);
+       rn.conf = check_receiver_arg(conf.receiver_arg, &receiver_num);
        if (!rn.conf) {
-               PARA_EMERG_LOG("parse failed\n");
+               PARA_EMERG_LOG("invalid receiver specifier\n");
+               ret = -E_RECV_SYNTAX;
                goto out;
        }
        r = &receivers[receiver_num];
@@ -102,6 +94,7 @@ int main(int argc, char *argv[])
                goto out;
        r_opened = 1;
 
+       memset(&sot, 0, sizeof(struct stdout_task));
        sot.btrn = btr_new_node(&(struct btr_node_description)
                EMBRACE(.parent = rn.btrn, .name = "stdout"));
        stdout_set_defaults(&sot);
@@ -112,6 +105,8 @@ int main(int argc, char *argv[])
        sprintf(rn.task.status, "%s", r->name);
        register_task(&s, &rn.task);
 
+       s.default_timeout.tv_sec = 1;
+       s.default_timeout.tv_usec = 0;
        ret = schedule(&s);
 out:
        if (r_opened)
index f3d5237f19cfbc69e01ca17851f698fda1b41779..31d29c73dc5595c881173abe4eea892854b1f6a3 100644 (file)
--- a/server.c
+++ b/server.c
@@ -236,13 +236,13 @@ void parse_config_or_die(int override)
                        .print_errors = !conf.daemon_given
                };
                server_cmdline_parser_config_file(cf, &conf, &params);
+               daemon_set_loglevel(conf.loglevel_arg);
                conf.daemon_given = tmp;
        }
        if (conf.logfile_given) {
                daemon_set_logfile(conf.logfile_arg);
                daemon_open_log_or_die();
        }
-       daemon_set_loglevel(conf.loglevel_arg);
        init_colors_or_die();
        daemon_set_flag(DF_LOG_PID);
        daemon_set_flag(DF_LOG_LL);
@@ -490,6 +490,7 @@ static void server_init(int argc, char **argv)
        server_cmdline_parser_ext(argc, argv, &conf, &params);
        HANDLE_VERSION_FLAG("server", conf);
        drop_privileges_or_die(conf.user_arg, conf.group_arg);
+       daemon_set_loglevel(conf.loglevel_arg);
        /* parse config file, open log and set defaults */
        parse_config_or_die(0);
        log_welcome("para_server");
diff --git a/write.c b/write.c
index 866ea43327b3d1389993e18b7277e29201a223da..f4f757fff2957f75876df33a83b41fd91aad3571 100644 (file)
--- a/write.c
+++ b/write.c
@@ -107,7 +107,6 @@ static int setup_and_schedule(void)
                },
        };
 
-       loglevel = get_loglevel_by_name(conf.loglevel_arg);
        sit.btrn = btr_new_node(&(struct btr_node_description)
                EMBRACE(.name = "stdin"));
        stdin_set_defaults(&sit);
@@ -173,8 +172,9 @@ int main(int argc, char *argv[])
 {
        int ret;
 
-       writer_init();
        write_cmdline_parser(argc, argv, &conf);
+       loglevel = get_loglevel_by_name(conf.loglevel_arg);
+       writer_init();
        HANDLE_VERSION_FLAG("write", conf);
        if (conf.help_given || conf.detailed_help_given)
                print_help_and_die();