relax config file checking for non-server programs
authorRichard Kettlewell <rjk@greenend.org.uk>
Tue, 2 Oct 2007 12:53:49 +0000 (13:53 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Tue, 2 Oct 2007 12:53:49 +0000 (13:53 +0100)
14 files changed:
clients/disorder.c
clients/test-eclient.c
disobedience/disobedience.c
lib/configuration.c
lib/configuration.h
server/cgimain.c
server/deadlock.c
server/disorderd.c
server/dump.c
server/normalize.c
server/rescan.c
server/speaker.c
server/state.c
server/trackname.c

index 0ce20aa..eae5a8f 100644 (file)
@@ -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);
index fa8eb5a..bae789a 100644 (file)
@@ -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);
index c95b328..72b0720 100644 (file)
@@ -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()))
index ad41024..69b8bb7 100644 (file)
@@ -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;
index e9893f0..a2033c2 100644 (file)
@@ -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. */
 
index 231ece1..1abc5a4 100644 (file)
@@ -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;
index f6ae420..82e796d 100644 (file)
@@ -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) {
index 125a005..b41dade 100644 (file)
@@ -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);
index 5809b82..25dd01e 100644 (file)
@@ -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) {
index dc69bb5..c16c70f 100644 (file)
@@ -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);
index 1171943..8a29300 100644 (file)
@@ -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;
index aa09c02..70d2162 100644 (file)
@@ -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);
index 455cf41..45954f0 100644 (file)
@@ -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. */
index e06df66..1e0bb45 100644 (file)
@@ -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)));