]> git.proxmox.com Git - pve-lxc-syscalld.git/blame - src/main.rs
switch back to tokio now that it's stable and packaged
[pve-lxc-syscalld.git] / src / main.rs
CommitLineData
9aa2a15a 1use std::future::Future;
8dd26985 2use std::io as StdIo;
9cffeac4
WB
3
4use failure::{bail, format_err, Error};
5use nix::sys::socket::SockAddr;
6
9aa2a15a
WB
7#[macro_use]
8mod macros;
9
42f25756 10pub mod apparmor;
738dbfbe 11pub mod capability;
e420f6f9 12pub mod client;
d1b1deab 13pub mod error;
e420f6f9 14pub mod fork;
8dd26985 15pub mod io;
9cffeac4 16pub mod lxcseccomp;
e420f6f9 17pub mod nsfd;
a22aece0 18pub mod poll_fn;
3bbd1db0 19pub mod process;
9cffeac4 20pub mod seccomp;
e420f6f9 21pub mod sys_mknod;
3e69a521 22pub mod sys_quotactl;
c95be5f6 23pub mod syscall;
9cffeac4
WB
24pub mod tools;
25
8dd26985 26use crate::io::seq_packet::SeqPacketListener;
9aa2a15a 27
9aa2a15a 28pub fn spawn(fut: impl Future<Output = ()> + Send + 'static) {
5bd0c562 29 tokio::spawn(fut);
9aa2a15a
WB
30}
31
32fn main() {
5bd0c562 33 let mut rt = tokio::runtime::Runtime::new().expect("failed to spawn tokio runtime");
e420f6f9 34
5bd0c562 35 if let Err(err) = rt.block_on(do_main()) {
9cffeac4
WB
36 eprintln!("error: {}", err);
37 std::process::exit(1);
38 }
39}
40
a563caf2 41async fn do_main() -> Result<(), Error> {
571dbe03 42 let socket_path = std::env::args_os()
9486338a 43 .nth(1)
571dbe03 44 .ok_or_else(|| format_err!("missing parameter: socket path to listen on"))?;
9cffeac4 45
571dbe03 46 match std::fs::remove_file(&socket_path) {
9cffeac4 47 Ok(_) => (),
8dd26985 48 Err(ref e) if e.kind() == StdIo::ErrorKind::NotFound => (), // Ok
9cffeac4
WB
49 Err(e) => bail!("failed to remove previous socket: {}", e),
50 }
51
571dbe03
WB
52 let address =
53 SockAddr::new_unix(socket_path.as_os_str()).expect("cannot create struct sockaddr_un?");
9cffeac4 54
8dd26985 55 let mut listener = SeqPacketListener::bind(&address)
9cffeac4
WB
56 .map_err(|e| format_err!("failed to create listening socket: {}", e))?;
57 loop {
58 let client = listener.accept().await?;
e420f6f9 59 let client = client::Client::new(client);
9aa2a15a 60 spawn(client.main());
9cffeac4
WB
61 }
62}