From: Andre Noll Date: Mon, 26 Jan 2009 22:27:50 +0000 (+0100) Subject: Fix config file handling for audiod and clean up init functions. X-Git-Tag: v0.3.4~72 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=56955f95584f51709320262f7d2e0ea79301d346;p=paraslash.git Fix config file handling for audiod and clean up init functions. 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. --- diff --git a/audiod.c b/audiod.c index 6477c547..e3fd49d3 100644 --- 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, ¶ms)) { - PARA_EMERG_LOG("parse error in config file\n"); - goto err; - } + if (ret) + audiod_cmdline_parser_config_file(config_file, &conf, ¶ms); 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, ¶ms); + if (audiod_cmdline_parser_ext(argc, argv, &conf, ¶ms)) + 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"); diff --git a/filter.c b/filter.c index 96880b7d..9311a20a 100644 --- 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; diff --git a/filter.h b/filter.h index 2c546c1d..da472905 100644 --- 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); diff --git a/filter_common.c b/filter_common.c index d83629bd..285efe68 100644 --- a/filter_common.c +++ b/filter_common.c @@ -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 df8b9ce9..4f595e39 100644 --- 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 b82e04f5..dc49ef95 100644 --- 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); diff --git a/recv_common.c b/recv_common.c index 2840df00..953e2a11 100644 --- a/recv_common.c +++ b/recv_common.c @@ -15,6 +15,18 @@ #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 238f2ab9..c5a26565 100644 --- 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) diff --git a/write_common.c b/write_common.c index 8fb6c3d1..8133577b 100644 --- a/write_common.c +++ b/write_common.c @@ -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; diff --git a/write_common.h b/write_common.h index 18e5e838..5edebe11 100644 --- a/write_common.h +++ b/write_common.h @@ -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);