use anyhow::{bail, format_err, Error};
use std::collections::HashMap;
use std::future::Future;
use std::os::unix::io::AsRawFd;
use std::path::{Path, PathBuf};
use std::pin::pin;
use std::sync::Arc;
use nix::sys::socket;
use nix::unistd::Gid;
use serde::Serialize;
use serde_json::Value;
use tokio::net::UnixListener;
use tokio::sync::watch;
/// Returns the control socket path for a specific process ID.
///
/// Note: The control socket always uses @/run/proxmox-backup/ as
/// prefix for historic reason. This does not matter because the
/// generated path is unique for each ``pid`` anyways.
pub fn path_from_pid(pid: i32) -> String {
// Note: The control socket always uses @/run/proxmox-backup/ as prefix
// for historc reason.
format!("\0{}/control-{}.sock", "/run/proxmox-backup", pid)
}
/// Returns the control socket path for this server.
pub fn this_path() -> String {
path_from_pid(unsafe { libc::getpid() })
}
// Listens on a Unix Socket to handle simple command asynchronously
fn create_control_socket
(
path: P,
gid: Gid,
abort_future: W,
func: F,
) -> Result, Error>
where
P: Into,
F: Fn(Value) -> Result + Send + Sync + 'static,
W: Future