Skip to main content

conmonrs/
lib.rs

1//! A pod level OCI container runtime monitor for Linux.
2//!
3//! A container engine like CRI-O starts one `conmonrs` per pod and talks to
4//! it over a Cap'n Proto RPC interface on a UNIX socket, which this crate
5//! serves. The crate is the server only, the Go client lives in the same
6//! repository under `pkg/client`. The repository holds the full
7//! documentation:
8//!
9//! - <https://github.com/containers/conmon-rs/blob/main/README.md> on what
10//!   conmon-rs does.
11//! - <https://github.com/containers/conmon-rs/blob/main/docs/architecture.md>
12//!   on how the server and the client work together.
13//! - <https://github.com/containers/conmon-rs/blob/main/docs/install.md> on
14//!   how to install, verify and build it.
15//! - <https://github.com/containers/conmon-rs/blob/main/docs/server.md> on the
16//!   command line.
17//! - <https://github.com/containers/conmon-rs/blob/main/docs/protocols.md> on
18//!   the RPCs and the attach and streaming protocols.
19//! - <https://github.com/containers/conmon-rs/blob/main/README.md#documentation>
20//!   on the other documents, like configuring CRI-O, logging and
21//!   troubleshooting.
22
23use anyhow::{Context, Result};
24use config::{Config, Verbosity};
25use server::Server;
26use version::Version;
27
28/// Run conmonrs: print the version or start the server, depending on the
29/// command line.
30pub fn run() -> Result<()> {
31    // Before the heap grows, see the function.
32    init::disable_thp();
33    let mut config = Config::parse_args();
34
35    if let Some(v) = config.version() {
36        return Version::new(v == Verbosity::Full).print();
37    }
38
39    if let Some(v) = config.version_json() {
40        return Version::new(v == Verbosity::Full).print_json();
41    }
42
43    config.validate().context("validate config")?;
44    config.make_absolute()?;
45    // Before the runtime directories get created, they would get the umask
46    // of the caller otherwise.
47    init::set_default_umask();
48    config.prepare().context("prepare runtime directories")?;
49
50    Server::new(config)
51        .context("create server")?
52        .start()
53        .context("start server")
54}
55
56/// The generated Cap'n Proto RPC interface.
57pub mod conmon_capnp {
58    #![allow(
59        clippy::all,
60        clippy::nursery,
61        clippy::pedantic,
62        clippy::restriction,
63        unused_parens,
64        reason = "generated code"
65    )]
66    include!(concat!(env!("OUT_DIR"), "/proto/conmon_capnp.rs"));
67}
68
69/// The entry points of the fuzz targets in `fuzz/`, not an API.
70#[cfg(any(test, feature = "fuzzing"))]
71#[doc(hidden)]
72pub mod fuzzing {
73    pub use crate::{
74        container_log::fuzzing::lines as log_lines, journal::fuzzing::entry as journal_entry,
75        oom_watcher::fuzzing::cgroup_files, process::fuzzing::stat as proc_stat,
76        streaming_server::fuzzing::*,
77    };
78
79    #[cfg(test)]
80    mod tests;
81}
82
83mod async_fd;
84mod attach;
85mod channel;
86mod child_reaper;
87mod config;
88mod container_io;
89mod container_log;
90mod exec_start;
91mod fs_util;
92mod init;
93mod journal;
94mod listener;
95mod mutex;
96mod oom_watcher;
97mod process;
98mod random_id;
99mod rpc;
100mod runtime_args;
101mod server;
102mod streaming_server;
103mod tail;
104#[cfg(feature = "tracing")]
105mod telemetry;
106mod terminal;
107#[cfg(test)]
108mod test_util;
109#[cfg(all(target_os = "linux", target_arch = "s390x", target_env = "musl"))]
110mod unwind;
111mod util;
112mod version;