chiark / gitweb /
arrange to split log_config from config
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 25 Dec 2020 18:05:13 +0000 (18:05 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 25 Dec 2020 18:05:21 +0000 (18:05 +0000)
Mostly to make debug better

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/daemon-otter.rs
src/config.rs
src/global.rs

index 41cb0e6cf662b9ae953fd2171e5350861b789bcb..25cd534db430007c41eb5d27fa12484a3bdf3424 100644 (file)
@@ -213,7 +213,7 @@ fn main() {
 
   let c = config();
 
-  flexi_logger::Logger::with(c.log.clone()).start()?;
+  flexi_logger::Logger::with(log_config().clone()).start()?;
 
   debug!("resolved config: {:#?}", c);
 
index f9069d10244e9fc31815153939b365df9f1c8624..1f9bee4ea39018ea5f7608ed51927379a403fbb5 100644 (file)
@@ -36,6 +36,12 @@ pub struct ServerConfigSpec {
   pub sendmail: Option<String>,
 }
 
+#[derive(Debug,Clone)]
+pub struct WholeServerConfig {
+  server: Arc<ServerConfig>,
+  log: LogSpecification,
+}
+
 #[derive(Debug,Clone)]
 pub struct ServerConfig {
   save_dir: String,
@@ -48,16 +54,15 @@ pub struct ServerConfig {
   pub template_dir: String,
   pub nwtemplate_dir: String,
   pub wasm_dir: String,
-  pub log: LogSpecification,
   pub bundled_sources: String,
   pub shapelibs: Vec<shapelib::Config1>,
   pub sendmail: String,
 }
 
-impl TryFrom<ServerConfigSpec> for ServerConfig {
+impl TryFrom<ServerConfigSpec> for WholeServerConfig {
   type Error = AE;
   #[throws(Self::Error)]
-  fn try_from(spec: ServerConfigSpec) -> ServerConfig {
+  fn try_from(spec: ServerConfigSpec) -> WholeServerConfig {
     let ServerConfigSpec {
       base_dir, save_dir, command_socket, debug,
       http_port, public_url, sse_wildcard_url, rocket_workers,
@@ -122,21 +127,28 @@ impl TryFrom<ServerConfigSpec> for ServerConfig {
     let log = LogSpecification::from_toml(&log)
       .context("log specification")?;
 
-    ServerConfig {
+    let server = ServerConfig {
       save_dir, command_socket, debug,
       http_port, public_url, sse_wildcard_url, rocket_workers,
       template_dir, nwtemplate_dir, wasm_dir,
-      log, bundled_sources, shapelibs, sendmail,
+      bundled_sources, shapelibs, sendmail,
+    };
+    WholeServerConfig {
+      server: Arc::new(server),
+      log,
     }
   }
 }
 
 pub fn config() -> Arc<ServerConfig> {
-  GLOBAL.config.read().unwrap().clone()
+  GLOBAL.config.read().unwrap().server.clone()
+}
+pub fn log_config() -> LogSpecification {
+  GLOBAL.config.read().unwrap().log.clone()
 }
 
-fn set_config(config: ServerConfig) {
-  *GLOBAL.config.write().unwrap() = Arc::new(config)
+fn set_config(whole: WholeServerConfig) {
+  *GLOBAL.config.write().unwrap() = whole;
 }
 
 impl ServerConfig {
@@ -149,9 +161,9 @@ impl ServerConfig {
     let mut buf = String::new();
     File::open(&config_filename).with_context(||config_filename.to_string())?
       .read_to_string(&mut buf)?;
-    let config : ServerConfigSpec = toml_de::from_str(&buf)?;
-    let config = config.try_into()?;
-    set_config(config);
+    let spec : ServerConfigSpec = toml_de::from_str(&buf)?;
+    let whole = spec.try_into()?;
+    set_config(whole);
   }
 
   #[throws(AE)]
@@ -175,8 +187,8 @@ impl ServerConfig {
   }
 }
 
-impl Default for ServerConfig {
-  fn default() -> ServerConfig {
+impl Default for WholeServerConfig {
+  fn default() -> WholeServerConfig {
     let spec: ServerConfigSpec = toml_de::from_str(r#"
       public_url = "INTERNAL ERROR"
       "#)
index 025fb04552f645063eddb8403606589569d1a0cb..2c07faea882b2e46fee3b64323b7d0be89d9f289 100644 (file)
@@ -195,7 +195,7 @@ pub struct Global {
   // <- InstanceContainer ->
   // inner locks which the game needs:
   dirty: Mutex<VecDeque<InstanceRef>>,
-  pub config: RwLock<Arc<ServerConfig>>,
+  pub config: RwLock<WholeServerConfig>,
 
   // fast global lookups
   players: RwLock<TokenTable<PlayerId>>,