From e20175362906f5bdc32899e68d65a2b23ad04079 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 9 Apr 2019 11:47:23 +0200 Subject: [PATCH] src/server/command_socket.rs: implement auto_remove flag Remove the socket file on close. --- src/server/command_socket.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/server/command_socket.rs b/src/server/command_socket.rs index 7378ed8e..07ee5fe1 100644 --- a/src/server/command_socket.rs +++ b/src/server/command_socket.rs @@ -13,18 +13,20 @@ use serde_json::Value; use std::sync::Arc; /// Listens on a Unix Socket to handle simple command asynchronously -pub fn create_control_socket(path: P, f: F) -> Result, Error> +pub fn create_control_socket(path: P, auto_remove: bool, f: F) -> Result, Error> where P: Into, F: Send + Sync +'static + Fn(Value) -> Result, { let path: PathBuf = path.into(); + let path1: PathBuf = path.clone(); + + if auto_remove { let _ = std::fs::remove_file(&path); } let socket = UnixListener::bind(&path)?; let f = Arc::new(f); - let path = Arc::new(path); - let path2 = path.clone(); - let path3 = path.clone(); + let path2 = Arc::new(path); + let path3 = path2.clone(); let control_future = socket.incoming() .map_err(move |err| { eprintln!("failed to accept on control socket {:?}: {}", path2, err); }) @@ -61,7 +63,12 @@ pub fn create_control_socket(path: P, f: F) -> Result