From de62f34a961969af5add353c6b05d5411b602990 Mon Sep 17 00:00:00 2001 From: "Brian L. Troutwine" Date: Tue, 3 Dec 2024 14:27:07 -0800 Subject: [PATCH] Update procfs to 0.17 (#1119) This commit updates procfs dependency to 0.17. #1096 is now redundant. Signed-off-by: Brian L. Troutwine --- Cargo.lock | 107 +++++------------------------------ lading/Cargo.toml | 2 +- lading/src/bin/lading.rs | 6 +- lading/src/observer/linux.rs | 10 ++-- lading/src/target.rs | 24 ++++---- 5 files changed, 36 insertions(+), 113 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ccfe3aadd..75c6d2af0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1547,12 +1547,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" -[[package]] -name = "linux-raw-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" - [[package]] name = "linux-raw-sys" version = "0.3.8" @@ -2098,15 +2092,24 @@ dependencies = [ [[package]] name = "procfs" -version = "0.15.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "943ca7f9f29bab5844ecd8fdb3992c5969b6622bb9609b9502fef9b4310e3f1f" +checksum = "cc5b72d8145275d844d4b5f6d4e1eef00c8cd889edb6035c21675d1bb1f45c9f" dependencies = [ - "bitflags 1.3.2", - "byteorder", + "bitflags 2.6.0", + "hex", + "procfs-core", + "rustix 0.38.37", +] + +[[package]] +name = "procfs-core" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "239df02d8349b06fc07398a3a1697b06418223b1c7725085e801e7c0fc6a12ec" +dependencies = [ + "bitflags 2.6.0", "hex", - "lazy_static", - "rustix 0.36.17", ] [[package]] @@ -2424,20 +2427,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustix" -version = "0.36.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "305efbd14fde4139eb501df5f136994bb520b033fa9fbdce287507dc23b8c7ed" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.1.4", - "windows-sys 0.45.0", -] - [[package]] name = "rustix" version = "0.37.27" @@ -3544,15 +3533,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows-sys" version = "0.48.0" @@ -3580,21 +3560,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-targets" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - [[package]] name = "windows-targets" version = "0.48.5" @@ -3626,12 +3591,6 @@ dependencies = [ "windows_x86_64_msvc 0.52.6", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -3644,12 +3603,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - [[package]] name = "windows_aarch64_msvc" version = "0.48.5" @@ -3662,12 +3615,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - [[package]] name = "windows_i686_gnu" version = "0.48.5" @@ -3686,12 +3633,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - [[package]] name = "windows_i686_msvc" version = "0.48.5" @@ -3704,12 +3645,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - [[package]] name = "windows_x86_64_gnu" version = "0.48.5" @@ -3722,12 +3657,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" @@ -3740,12 +3669,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - [[package]] name = "windows_x86_64_msvc" version = "0.48.5" diff --git a/lading/Cargo.toml b/lading/Cargo.toml index 733826ece..b471d3174 100644 --- a/lading/Cargo.toml +++ b/lading/Cargo.toml @@ -87,7 +87,7 @@ zstd = "0.13.1" [target.'cfg(target_os = "linux")'.dependencies] cgroups-rs = { version = "0.3", default-features = false, features = [] } -procfs = { version = "0.15", default-features = false, features = [] } +procfs = { version = "0.17", default-features = false, features = [] } async-pidfd = "0.1" [dev-dependencies] diff --git a/lading/src/bin/lading.rs b/lading/src/bin/lading.rs index 9b7396b8d..16d81c4b8 100644 --- a/lading/src/bin/lading.rs +++ b/lading/src/bin/lading.rs @@ -49,7 +49,7 @@ enum Error { #[error("Failed to deserialize Lading config: {0}")] SerdeYaml(#[from] serde_yaml::Error), #[error("Lading failed to sync servers {0}")] - Send(#[from] tokio::sync::broadcast::error::SendError>), + Send(#[from] tokio::sync::broadcast::error::SendError>), #[error("Maximum RSS bytes limit exceeds u64::MAX {0}")] Meta(#[from] lading::target::MetaError), #[error("Parsing Prometheus address failed: {0}")] @@ -267,7 +267,9 @@ fn get_config(ops: &Opts, config: Option) -> Result { let target = if ops.no_target { None } else if let Some(pid) = ops.target_pid { - Some(target::Config::Pid(target::PidConfig { pid })) + Some(target::Config::Pid(target::PidConfig { + pid: pid.try_into().expect("Could not convert pid to i32"), + })) } else if let Some(name) = &ops.target_container { Some(target::Config::Docker(target::DockerConfig { name: name.clone(), diff --git a/lading/src/observer/linux.rs b/lading/src/observer/linux.rs index 9a82ebdd0..264a1b850 100644 --- a/lading/src/observer/linux.rs +++ b/lading/src/observer/linux.rs @@ -3,8 +3,8 @@ use std::{collections::VecDeque, io, path::Path, sync::atomic::Ordering}; use cgroups_rs::cgroup::Cgroup; use metrics::gauge; use nix::errno::Errno; -use procfs::process::Process; use procfs::ProcError::PermissionDenied; +use procfs::{process::Process, Current}; use rustc_hash::{FxHashMap, FxHashSet}; use tracing::{error, warn}; @@ -89,8 +89,8 @@ impl Gauge { } impl Sampler { - pub(crate) fn new(parent_pid: u32) -> Result { - let parent = Process::new(parent_pid.try_into().expect("PID coercion failed"))?; + pub(crate) fn new(parent_pid: i32) -> Result { + let parent = Process::new(parent_pid)?; Ok(Self { parent, @@ -126,9 +126,7 @@ impl Sampler { // later for calculating per-process uptime. Because we capture this one // we will be slightly out of date with each subsequent iteration of the // loop. We do not believe this to be an issue. - let uptime_seconds: f64 = procfs::Uptime::new() - .expect("could not query machine uptime") - .uptime; // seconds since boot + let uptime_seconds: f64 = procfs::Uptime::current()?.uptime; // seconds since boot let uptime_ticks: u64 = uptime_seconds.round() as u64 * self.ticks_per_second; // CPU-ticks since boot // Clear values from previous sample run. This ensures that processes diff --git a/lading/src/target.rs b/lading/src/target.rs index d2dba6852..e8b642abf 100644 --- a/lading/src/target.rs +++ b/lading/src/target.rs @@ -17,7 +17,7 @@ use std::{ io, - num::NonZeroU32, + num::NonZeroI32, path::PathBuf, process::{ExitStatus, Stdio}, sync::atomic::{AtomicU64, Ordering}, @@ -45,10 +45,10 @@ pub(crate) static RSS_BYTES_LIMIT: AtomicU64 = AtomicU64::new(u64::MAX); /// Type used to receive the target PID once it is running. #[allow(clippy::module_name_repetitions)] -pub type TargetPidReceiver = tokio::sync::broadcast::Receiver>; +pub type TargetPidReceiver = tokio::sync::broadcast::Receiver>; #[allow(clippy::module_name_repetitions)] -type TargetPidSender = tokio::sync::broadcast::Sender>; +type TargetPidSender = tokio::sync::broadcast::Sender>; /// Errors produced by [`Meta`] #[derive(thiserror::Error, Debug, Clone, Copy)] @@ -112,13 +112,13 @@ pub enum Error { SigTerm(Errno), /// The target PID does not exist or is invalid #[error("PID not found: {0}")] - PidNotFound(u32), + PidNotFound(i32), /// The target process exited unexpectedly #[error("target exited unexpectedly: {0:?}")] TargetExited(Option), /// See [`SendError`] #[error(transparent)] - Send(#[from] tokio::sync::broadcast::error::SendError>), + Send(#[from] tokio::sync::broadcast::error::SendError>), /// Process already finished error #[error("Child has already been polled to completion")] ProcessFinished, @@ -140,7 +140,7 @@ pub struct DockerConfig { #[derive(Debug, PartialEq, Eq)] pub struct PidConfig { /// PID to watch - pub pid: NonZeroU32, + pub pid: NonZeroI32, } /// Configuration for binary launch mode @@ -352,11 +352,7 @@ impl Server { ) -> Result<(), Error> { // Convert pid config value to a plain i32 (no truncation concerns; // PID_MAX_LIMIT is 2^22) - let raw_pid: i32 = config - .pid - .get() - .try_into() - .map_err(|_| Error::PidNotFound(config.pid.get()))?; + let raw_pid: i32 = config.pid.get(); let pid = Pid::from_raw(raw_pid); // Verify that the given PID is valid @@ -443,7 +439,11 @@ impl Server { .envs(config.environment_variables.iter()); let mut target_child = target_cmd.spawn().map_err(Error::TargetSpawn)?; let target_id = target_child.id().ok_or(Error::ProcessFinished)?; - pid_snd.send(Some(target_id))?; + pid_snd.send(Some( + target_id + .try_into() + .expect("could not convert target pid to i32"), + ))?; drop(pid_snd); target_running.signal();