pipette/
main.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! This is the petri pipette agent, which runs on the guest and executes
5//! commands and other requests from the host.
6
7#![cfg_attr(not(windows), forbid(unsafe_code))]
8
9#[cfg(any(target_os = "linux", windows))]
10mod agent;
11#[cfg(any(target_os = "linux", windows))]
12mod crash;
13#[cfg(any(target_os = "linux", windows))]
14mod execute;
15#[cfg(any(target_os = "linux", windows))]
16mod shutdown;
17#[cfg(any(target_os = "linux", windows))]
18mod trace;
19#[cfg(windows)]
20mod winsvc;
21
22#[cfg(any(target_os = "linux", windows))]
23fn main() -> anyhow::Result<()> {
24    eprintln!("Pipette starting up");
25
26    let hook = std::panic::take_hook();
27    std::panic::set_hook(Box::new(move |info| {
28        eprintln!("Pipette panicked: {}", info);
29        hook(info);
30    }));
31
32    #[cfg(windows)]
33    if std::env::args().nth(1).as_deref() == Some("--service") {
34        return winsvc::start_service();
35    }
36
37    pal_async::DefaultPool::run_with(async |driver| {
38        let agent = agent::Agent::new(driver).await?;
39        agent.run().await
40    })
41}
42
43#[cfg(not(any(target_os = "linux", windows)))]
44fn main() -> anyhow::Result<()> {
45    anyhow::bail!("unsupported platform");
46}