From c00fce3ab1dc8b810a439e81e419d7b8ae1d97b9 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Tue, 2 Oct 2007 13:53:49 +0100 Subject: [PATCH] relax config file checking for non-server programs Organization: Straylight/Edgeware From: Richard Kettlewell --- clients/disorder.c | 4 +++- clients/test-eclient.c | 2 +- disobedience/disobedience.c | 2 +- lib/configuration.c | 21 +++++++++++++-------- lib/configuration.h | 2 +- server/cgimain.c | 2 +- server/deadlock.c | 2 +- server/disorderd.c | 2 +- server/dump.c | 2 +- server/normalize.c | 2 +- server/rescan.c | 2 +- server/speaker.c | 4 ++-- server/state.c | 2 +- server/trackname.c | 2 +- 14 files changed, 29 insertions(+), 22 deletions(-) diff --git a/clients/disorder.c b/clients/disorder.c index 0ce20aa..eae5a8f 100644 --- a/clients/disorder.c +++ b/clients/disorder.c @@ -149,6 +149,8 @@ static void cf_shutdown(disorder_client *c, static void cf_reconfigure(disorder_client *c, char attribute((unused)) **argv) { + /* Re-check configuration for server */ + if(config_read(1)) fatal(0, "cannot read configuration"); if(disorder_reconfigure(c)) exit(EXIT_FAILURE); } @@ -517,7 +519,7 @@ int main(int argc, char **argv) { default: fatal(0, "invalid option"); } } - if(config_read()) fatal(0, "cannot read configuration"); + if(config_read(0)) fatal(0, "cannot read configuration"); if(!(c = disorder_new(1))) exit(EXIT_FAILURE); s = config_get_file("socket"); if(disorder_connect(c)) exit(EXIT_FAILURE); diff --git a/clients/test-eclient.c b/clients/test-eclient.c index fa8eb5a..bae789a 100644 --- a/clients/test-eclient.c +++ b/clients/test-eclient.c @@ -165,7 +165,7 @@ int main(int argc, char **argv) { assert(argc > 0); mem_init(); debugging = 0; /* turn on for even more verbosity */ - if(config_read()) fatal(0, "config_read failed"); + if(config_read(0)) fatal(0, "config_read failed"); tracks = &argv[1]; c = disorder_eclient_new(&callbacks, &u_value); assert(c != 0); diff --git a/disobedience/disobedience.c b/disobedience/disobedience.c index c95b328..72b0720 100644 --- a/disobedience/disobedience.c +++ b/disobedience/disobedience.c @@ -377,7 +377,7 @@ int main(int argc, char **argv) { /* create the event loop */ D(("create main loop")); mainloop = g_main_loop_new(0, 0); - if(config_read()) fatal(0, "cannot read configuration"); + if(config_read(0)) fatal(0, "cannot read configuration"); /* create the clients */ if(!(client = gtkclient()) || !(logclient = gtkclient())) diff --git a/lib/configuration.c b/lib/configuration.c index ad41024..69b8bb7 100644 --- a/lib/configuration.c +++ b/lib/configuration.c @@ -1023,7 +1023,8 @@ static void config_free(struct config *c) { } /** @brief Set post-parse defaults */ -static void config_postdefaults(struct config *c) { +static void config_postdefaults(struct config *c, + int server) { struct config_state cs; const struct conf *whoami; int n; @@ -1072,10 +1073,12 @@ static void config_postdefaults(struct config *c) { #endif } } - if(c->speaker_backend == BACKEND_COMMAND && !c->speaker_command) - fatal(0, "speaker_backend is command but speaker_command is not set"); - if(c->speaker_backend == BACKEND_NETWORK && !c->broadcast.n) - fatal(0, "speaker_backend is network but broadcast is not set"); + if(server) { + if(c->speaker_backend == BACKEND_COMMAND && !c->speaker_command) + fatal(0, "speaker_backend is command but speaker_command is not set"); + if(c->speaker_backend == BACKEND_NETWORK && !c->broadcast.n) + fatal(0, "speaker_backend is network but broadcast is not set"); + } if(c->speaker_backend) { /* Override sample format */ c->sample_format.rate = 44100; @@ -1085,8 +1088,10 @@ static void config_postdefaults(struct config *c) { } } -/** @brief (Re-)read the config file */ -int config_read() { +/** @brief (Re-)read the config file + * @param server If set, do extra checking + */ +int config_read(int server) { struct config *c; char *privconf; struct passwd *pw; @@ -1118,7 +1123,7 @@ int config_read() { return -1; xfree(privconf); /* install default namepart and transform settings */ - config_postdefaults(c); + config_postdefaults(c, server); /* everything is good so we shall use the new config */ config_free(config); config = c; diff --git a/lib/configuration.h b/lib/configuration.h index e9893f0..a2033c2 100644 --- a/lib/configuration.h +++ b/lib/configuration.h @@ -240,7 +240,7 @@ struct config { extern struct config *config; /* the current configuration */ -int config_read(void); +int config_read(int server); /* re-read config, return 0 on success or non-0 on error. * Only updates @config@ if the new configuration is valid. */ diff --git a/server/cgimain.c b/server/cgimain.c index 231ece1..1abc5a4 100644 --- a/server/cgimain.c +++ b/server/cgimain.c @@ -50,7 +50,7 @@ int main(int argc, char **argv) { cgi_parse(); if((conf = getenv("DISORDER_CONFIG"))) configfile = xstrdup(conf); if(getenv("DISORDER_DEBUG")) debugging = 1; - if(config_read()) exit(EXIT_FAILURE); + if(config_read(0)) exit(EXIT_FAILURE); memset(&g, 0, sizeof g); memset(&s, 0, sizeof s); s.g = &g; diff --git a/server/deadlock.c b/server/deadlock.c index f6ae420..82e796d 100644 --- a/server/deadlock.c +++ b/server/deadlock.c @@ -94,7 +94,7 @@ int main(int argc, char **argv) { openlog(progname, LOG_PID, LOG_DAEMON); log_default = &log_syslog; } - if(config_read()) fatal(0, "cannot read configuration"); + if(config_read(0)) fatal(0, "cannot read configuration"); info("started"); trackdb_init(0); while(getppid() != 1) { diff --git a/server/disorderd.c b/server/disorderd.c index 125a005..b41dade 100644 --- a/server/disorderd.c +++ b/server/disorderd.c @@ -243,7 +243,7 @@ int main(int argc, char **argv) { ev = ev_new(); if(ev_child_setup(ev)) fatal(0, "ev_child_setup failed"); /* read config */ - if(config_read()) + if(config_read(1)) fatal(0, "cannot read configuration"); /* Start the speaker process (as root! - so it can choose its nice value) */ speaker_setup(ev); diff --git a/server/dump.c b/server/dump.c index 5809b82..25dd01e 100644 --- a/server/dump.c +++ b/server/dump.c @@ -423,7 +423,7 @@ int main(int argc, char **argv) { fatal(0, "specify only a dump file name"); path = argv[optind]; } - if(config_read()) fatal(0, "cannot read configuration"); + if(config_read(0)) fatal(0, "cannot read configuration"); trackdb_init(recover); trackdb_open(); if(dump) { diff --git a/server/normalize.c b/server/normalize.c index dc69bb5..c16c70f 100644 --- a/server/normalize.c +++ b/server/normalize.c @@ -119,7 +119,7 @@ int main(int argc, char attribute((unused)) **argv) { fatal(errno, "error calling setlocale"); if(argc > 1) fatal(0, "not intended to be invoked by users"); - if(config_read()) + if(config_read(1)) fatal(0, "cannot read configuration"); if(!isatty(2)) { openlog(progname, LOG_PID, LOG_DAEMON); diff --git a/server/rescan.c b/server/rescan.c index 1171943..8a29300 100644 --- a/server/rescan.c +++ b/server/rescan.c @@ -325,7 +325,7 @@ int main(int argc, char **argv) { openlog(progname, LOG_PID, LOG_DAEMON); log_default = &log_syslog; } - if(config_read()) fatal(0, "cannot read configuration"); + if(config_read(0)) fatal(0, "cannot read configuration"); xnice(config->nice_rescan); sa.sa_handler = signal_handler; sa.sa_flags = SA_RESTART; diff --git a/server/speaker.c b/server/speaker.c index aa09c02..70d2162 100644 --- a/server/speaker.c +++ b/server/speaker.c @@ -517,7 +517,7 @@ static void mainloop(void) { break; case SM_RELOAD: D(("SM_RELOAD")); - if(config_read()) error(0, "cannot read configuration"); + if(config_read(1)) error(0, "cannot read configuration"); info("reloaded configuration"); break; default: @@ -561,7 +561,7 @@ int main(int argc, char **argv) { openlog(progname, LOG_PID, LOG_DAEMON); log_default = &log_syslog; } - if(config_read()) fatal(0, "cannot read configuration"); + if(config_read(1)) fatal(0, "cannot read configuration"); bpf = bytes_per_frame(&config->sample_format); /* ignore SIGPIPE */ signal(SIGPIPE, SIG_IGN); diff --git a/server/state.c b/server/state.c index 455cf41..45954f0 100644 --- a/server/state.c +++ b/server/state.c @@ -143,7 +143,7 @@ int reconfigure(ev_source *ev, int reload) { if(reload) { need_another_rescan = trackdb_rescan_cancel(); trackdb_close(); - if(config_read()) + if(config_read(1)) ret = -1; else { /* Tell the speaker it needs to reload its config too. */ diff --git a/server/trackname.c b/server/trackname.c index e06df66..1e0bb45 100644 --- a/server/trackname.c +++ b/server/trackname.c @@ -78,7 +78,7 @@ int main(int argc, char **argv) { } if(argc - optind < 3) fatal(0, "not enough arguments"); if(argc - optind > 3) fatal(0, "too many arguments"); - if(config_read()) fatal(0, "cannot read configuration"); + if(config_read(0)) fatal(0, "cannot read configuration"); s = trackname_part(argv[optind], argv[optind+1], argv[optind+2]); if(!s) fatal(0, "trackname_part returned NULL"); xprintf("%s\n", nullcheck(utf82mb(s))); -- [mdw]