From 7b56b91ffecb3efa85b5fd13661b827266fbaafa Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 22 Jul 2020 00:32:15 +0100 Subject: [PATCH] neatening --- src/command.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/command.rs b/src/command.rs index 67839c4c..e95d143e 100644 --- a/src/command.rs +++ b/src/command.rs @@ -4,6 +4,7 @@ use crate::imports::*; //use std::os::unix::prelude; +use std::os::unix::io::AsRawFd; pub use std::os::unix::net::UnixStream; use std::os::unix::net::UnixListener; @@ -33,7 +34,14 @@ impl CommandStream { impl CommandListener { #[throws(StartupError)] pub fn new() -> Self { - let listener = UnixListener::bind(SOCKET_PATH)?; + let path = SOCKET_PATH; + match fs::remove_file(path) { + Err(e) if e.kind() == io::ErrorKind::NotFound => Ok(()), + r => r, + } + .with_context(|| format!("remove socket {:?} before we bind", &path))?; + let listener = UnixListener::bind(path) + .with_context(|| format!("bind command socket {:?}", &path))?; CommandListener { listener } } @@ -50,8 +58,8 @@ impl CommandListener { #[throws(CSE)] fn accept_one(&mut self) { - let (conn, caller) = self.listener.accept().context("accept")?; - let mut desc = format!("conn={:?} peer={:?}", &conn, &caller); + let (conn, _caller) = self.listener.accept().context("accept")?; + let mut desc = format!("{:>5}", conn.as_raw_fd()); eprintln!("command connection {}: accepted", &desc); thread::spawn(move||{ match (||{ -- 2.30.2