chiark / gitweb /
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 0ce20aa271ba5ec53a27a5e76cda4ebd28a7715d..eae5a8fb9881d1e6f7cff8b98ac48c89dbc783e3 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 fa8eb5a79d80a60ead424511428b5977560115cb..bae789a683d7b89b4eae8993fc2eafdc21f72991 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 c95b3284e32aa8a6662f7d5b8f4ac306c40b6a47..72b07200bc65ab14c55e143c94465bf31cfd7aaf 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 ad410245b5e752031b803f1f73a5e46836b5d9c5..69b8bb7e9affc261dde6774e2c5ce18b0c156bc4 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 e9893f0f0dd16bd6c6c22013ecd57ee86b6c49b6..a2033c2dde941806aa9788eff309d37f1926b8e1 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 231ece18bfc32143314970e4e4d969723610bd47..1abc5a4b1156bb61302738467d542e700b715ad0 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 f6ae42016fb85512963c02ca78fe7919ad9354e6..82e796d695a99c982a1fd9ed290055956802bf28 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 125a005b35c1d52d3784e01aa90faade9c418ded..b41dadea0809ad327d1f9bf55cc8efb580ed198e 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 5809b829c6fd0b61ea5374b9726b9f4f37fbc6ce..25dd01ebfc6d610dad2a83168a7eaed75faaf335 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 dc69bb5fc4cdb277f7e5a43541796f139b298985..c16c70fd4ba2d8f6a01105f26c03c1fa1745d955 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 1171943467af0e0ec62c0008e96b72a0b0cfb9e5..8a29300fde24a16f7d86c9d5f2d73dd750947867 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 aa09c02b1fb15067442a8e955b33faa388d4e473..70d21625c23dab914c13533bbb5f43c4b899051b 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 455cf41f09403e73cf92da3d778538843b7e4a0f..45954f05e0b5d817b017a5ad83fafa17d583a141 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 e06df66136e75c0228dadc908a5d9fcb47bda824..1e0bb45589f9b81846cd435445340ecd462ca4f6 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)));