diff --git a/src/admin/server/commands.rs b/src/admin/server/commands.rs index 47509bad..5c0c2a10 100644 --- a/src/admin/server/commands.rs +++ b/src/admin/server/commands.rs @@ -32,13 +32,15 @@ pub(super) async fn reload_config( &self, path: Option, ) -> Result { - let path = path.as_deref().into_iter(); - let config = Config::load(path).and_then(|raw| Config::new(&raw))?; - if config.server_name != self.services.server.name { - return Err!("You can't change the server name."); - } + use conduwuit::config::check; - let _old = self.services.server.config.update(config)?; + let path = path.as_deref().into_iter(); + let new = Config::load(path).and_then(|raw| Config::new(&raw))?; + + let old = &self.services.server.config; + check::reload(old, &new)?; + + self.services.server.config.update(new)?; Ok(RoomMessageEventContent::text_plain("Successfully reconfigured.")) } diff --git a/src/core/config/check.rs b/src/core/config/check.rs index d7be54b1..988d4143 100644 --- a/src/core/config/check.rs +++ b/src/core/config/check.rs @@ -6,8 +6,24 @@ use figment::Figment; use super::DEPRECATED_KEYS; use crate::{debug, debug_info, debug_warn, error, warn, Config, Err, Result, Server}; +/// Performs check() with additional checks specific to reloading old config +/// with new config. +pub fn reload(old: &Config, new: &Config) -> Result { + check(new)?; + + if new.server_name != old.server_name { + return Err!(Config( + "server_name", + "You can't change the server's name from {:?}.", + old.server_name + )); + } + + Ok(()) +} + #[allow(clippy::cognitive_complexity)] -pub fn check(config: &Config) -> Result<()> { +pub fn check(config: &Config) -> Result { if cfg!(debug_assertions) { warn!("Note: conduwuit was built without optimisations (i.e. debug build)"); } diff --git a/src/main/server.rs b/src/main/server.rs index 74859f2b..7376b2fc 100644 --- a/src/main/server.rs +++ b/src/main/server.rs @@ -46,14 +46,14 @@ impl Server { .and_then(|raw| crate::clap::update(raw, args)) .and_then(|raw| Config::new(&raw))?; - #[cfg(feature = "sentry_telemetry")] - let sentry_guard = crate::sentry::init(&config); - let (tracing_reload_handle, tracing_flame_guard, capture) = crate::logging::init(&config)?; config.check()?; + #[cfg(feature = "sentry_telemetry")] + let sentry_guard = crate::sentry::init(&config); + #[cfg(unix)] sys::maximize_fd_limit() .expect("Unable to increase maximum soft and hard file descriptor limit");