src/server/worker_task.rs: use abstract socket
This commit is contained in:
parent
5f550fd99f
commit
9b002cbc5f
|
@ -13,15 +13,13 @@ use serde_json::Value;
|
|||
use std::sync::Arc;
|
||||
|
||||
/// Listens on a Unix Socket to handle simple command asynchronously
|
||||
pub fn create_control_socket<P, F>(path: P, auto_remove: bool, f: F) -> Result<impl Future<Item=(), Error=()>, Error>
|
||||
pub fn create_control_socket<P, F>(path: P, f: F) -> Result<impl Future<Item=(), Error=()>, Error>
|
||||
where P: Into<PathBuf>,
|
||||
F: Send + Sync +'static + Fn(Value) -> Result<Value, Error>,
|
||||
{
|
||||
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);
|
||||
|
@ -64,10 +62,7 @@ pub fn create_control_socket<P, F>(path: P, auto_remove: bool, f: F) -> Result<i
|
|||
|
||||
let abort_future = super::last_worker_future().map_err(|_| {});
|
||||
let task = control_future.select(abort_future)
|
||||
.then(move |_| {
|
||||
if auto_remove { let _ = std::fs::remove_file(path1); }
|
||||
Ok(())
|
||||
});
|
||||
.then(move |_| { Ok(()) });
|
||||
|
||||
Ok(task)
|
||||
}
|
||||
|
|
|
@ -52,9 +52,9 @@ pub fn worker_is_active(upid: &UPID) -> bool {
|
|||
pub fn create_task_control_socket() -> Result<(), Error> {
|
||||
|
||||
let socketname = format!(
|
||||
"{}/proxmox-task-control-{}.sock", PROXMOX_BACKUP_VAR_RUN_DIR, *MY_PID);
|
||||
"\0{}/proxmox-task-control-{}.sock", PROXMOX_BACKUP_VAR_RUN_DIR, *MY_PID);
|
||||
|
||||
let control_future = super::create_control_socket(socketname, true, |param| {
|
||||
let control_future = super::create_control_socket(socketname, |param| {
|
||||
let param = param.as_object()
|
||||
.ok_or(format_err!("unable to parse parameters (expected json object)"))?;
|
||||
if param.keys().count() != 2 { bail!("worng number of parameters"); }
|
||||
|
|
Loading…
Reference in New Issue