chiark / gitweb /
wip config
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Aug 2020 20:51:27 +0000 (21:51 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Aug 2020 20:51:27 +0000 (21:51 +0100)
src/bin/otter.rs
src/cmdlistener.rs
src/global.rs

index 91a1cd0cd0ec4764698493d80571c2e362452097..8d13348b7379ccf634905175823603013014942f 100644 (file)
@@ -281,7 +281,7 @@ impl ConnForGame {
 
 #[throws(E)]
 fn connect(ma: &MainOpts) -> Conn {
-  let unix = UnixStream::connect(SOCKET_PATH).context("connect to server")?;
+  let unix = UnixStream::connect(DEFAULT_COMMAND_SOCKET).context("connect to server")?; // xxx
   let chan = MgmtChannel::new(unix)?;
   let mut chan = Conn { chan };
   chan.cmd(&MgmtCommand::SetScope(ma.scope.clone().unwrap()))?;
index df9bbb77d767b2d74a31ac7c390934ecdad8aa11..652d86758194a38f5401813608887124438211bc 100644 (file)
@@ -12,8 +12,6 @@ use pwd::Passwd;
 pub use crate::from_instance_lock_error;
 pub use std::os::unix::net::UnixStream;
 
-pub const SOCKET_PATH : &str = "command.socket"; // xxx
-
 type CSE = anyhow::Error;
 
 use MgmtCommand::*;
@@ -413,7 +411,7 @@ impl CommandStream<'_> {
 impl CommandListener {
   #[throws(StartupError)]
   pub fn new() -> Self {
-    let path = SOCKET_PATH;
+    let path = &config().command_socket;
     match fs::remove_file(path) {
       Err(e) if e.kind() == io::ErrorKind::NotFound => Ok(()),
       r => r,
index efe34a75a28d2dc76d74886b25830655358f5f7f..0232c9a83d745eea585bf3d3c6596b681de4b6b8 100644 (file)
@@ -922,25 +922,34 @@ pub fn client_expire_old_clients() {
 // ========== server config ==========
 
 const DEFAULT_SAVE_DIRECTORY : &str = "save";
+pub const DEFAULT_COMMAND_SOCKET : &str = "command.socket"; // in save dir
+// ^ xxx should not be pub
 
 #[derive(Deserialize,Debug,Clone)]
 pub struct ServerConfigSpec {
   pub save_directory: Option<String>,
+  pub command_socket: Option<String>,
 }
 
 #[derive(Debug,Clone)]
 pub struct ServerConfig {
   pub save_directory: String,
+  pub command_socket: String,
 }
 
 impl TryFrom<ServerConfigSpec> for ServerConfig {
   type Error = AE;
   #[throws(Self::Error)]
   fn try_from(spec: ServerConfigSpec) -> ServerConfig {
-    let ServerConfigSpec { save_directory } = spec;
+    let ServerConfigSpec { save_directory, command_socket } = spec;
     let save_directory = save_directory
       .unwrap_or_else(|| DEFAULT_SAVE_DIRECTORY.to_owned());
-    ServerConfig { save_directory }
+    let mut command_socket = command_socket
+      .unwrap_or_else(|| DEFAULT_COMMAND_SOCKET.to_owned());
+    if !command_socket.starts_with('/') {
+      command_socket = format!("{}/{}", save_directory, command_socket);
+    }
+    ServerConfig { save_directory, command_socket }
   }
 }