Bump procfs to 0.16.0 (#11115)

Fix the breaking changes.
Get's rid of some outdated transitive dependencies.
Sadly we need to expose more of `procfs` to `nu-command` based on how
the features of `nu-system` are exposed right now.

Conditional compilation/dependencies from hell included

Supersedes #11101
This commit is contained in:
Stefan Holderbach 2023-11-20 21:22:35 +01:00 committed by GitHub
parent 869b01205c
commit 8ad5d8bb6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 36 deletions

42
Cargo.lock generated
View File

@ -2257,12 +2257,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "linux-raw-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.3.8" version = "0.3.8"
@ -2885,6 +2879,7 @@ dependencies = [
"pathdiff", "pathdiff",
"percent-encoding", "percent-encoding",
"print-positions", "print-positions",
"procfs",
"quick-xml", "quick-xml",
"quickcheck", "quickcheck",
"quickcheck_macros", "quickcheck_macros",
@ -4156,17 +4151,28 @@ dependencies = [
[[package]] [[package]]
name = "procfs" name = "procfs"
version = "0.15.1" version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "943ca7f9f29bab5844ecd8fdb3992c5969b6622bb9609b9502fef9b4310e3f1f" checksum = "731e0d9356b0c25f16f33b5be79b1c57b562f141ebfcdb0ad8ac2c13a24293b4"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 2.4.1",
"byteorder",
"chrono", "chrono",
"flate2", "flate2",
"hex", "hex",
"lazy_static", "lazy_static",
"rustix 0.36.17", "procfs-core",
"rustix 0.38.21",
]
[[package]]
name = "procfs-core"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d3554923a69f4ce04c4a754260c338f505ce22642d3830e049a399fc2059a29"
dependencies = [
"bitflags 2.4.1",
"chrono",
"hex",
] ]
[[package]] [[package]]
@ -4572,20 +4578,6 @@ dependencies = [
"semver", "semver",
] ]
[[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]] [[package]]
name = "rustix" name = "rustix"
version = "0.37.27" version = "0.37.27"

View File

@ -106,6 +106,9 @@ libc = "0.2"
umask = "2.1" umask = "2.1"
nix = { version = "0.27", default-features = false, features = ["user"] } nix = { version = "0.27", default-features = false, features = ["user"] }
[target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "android"), not(target_os = "ios")))'.dependencies]
procfs = "0.16.0"
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies.trash] [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies.trash]
optional = true optional = true
version = "3.1" version = "3.1"

View File

@ -14,6 +14,14 @@ use nu_protocol::{
Category, Example, IntoInterruptiblePipelineData, PipelineData, Record, ShellError, Signature, Category, Example, IntoInterruptiblePipelineData, PipelineData, Record, ShellError, Signature,
Type, Value, Type, Value,
}; };
#[cfg(all(
unix,
not(target_os = "macos"),
not(target_os = "windows"),
not(target_os = "android"),
not(target_os = "ios")
))]
use procfs::WithCurrentSystemInfo;
use std::time::Duration; use std::time::Duration;
@ -127,13 +135,11 @@ fn run_ps(engine_state: &EngineState, call: &Call) -> Result<PipelineData, Shell
Vec::new(), Vec::new(),
) )
})?; })?;
let proc_start = match proc_stat.starttime() { // If we can't get the start time, just use the current time
Ok(t) => t, let proc_start = proc_stat
Err(_) => { .starttime()
// If we can't get the start time, just use the current time .get()
chrono::Local::now() .unwrap_or_else(|_| chrono::Local::now());
}
};
record.push("start_time", Value::date(proc_start.into(), span)); record.push("start_time", Value::date(proc_start.into(), span));
record.push("user_id", Value::int(proc.curr_proc.owner() as i64, span)); record.push("user_id", Value::int(proc.curr_proc.owner() as i64, span));
// These work and may be helpful, but it just seemed crowded // These work and may be helpful, but it just seemed crowded

View File

@ -21,7 +21,7 @@ sysinfo = "0.29"
nix = { version = "0.27", default-features = false, features = ["fs", "term", "process", "signal"] } nix = { version = "0.27", default-features = false, features = ["fs", "term", "process", "signal"] }
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
procfs = "0.15" procfs = "0.16"
[target.'cfg(target_os = "macos")'.dependencies] [target.'cfg(target_os = "macos")'.dependencies]
libproc = "0.14" libproc = "0.14"

View File

@ -1,6 +1,6 @@
use log::info; use log::info;
use procfs::process::{FDInfo, Io, Process, Stat, Status}; use procfs::process::{FDInfo, Io, Process, Stat, Status};
use procfs::{ProcError, ProcessCgroup}; use procfs::{ProcError, ProcessCGroups, WithCurrentSystemInfo};
use std::path::PathBuf; use std::path::PathBuf;
use std::thread; use std::thread;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -25,7 +25,7 @@ impl ProcessTask {
} }
} }
pub fn cgroups(&self) -> Result<Vec<ProcessCgroup>, ProcError> { pub fn cgroups(&self) -> Result<ProcessCGroups, ProcError> {
match self { match self {
ProcessTask::Process(x) => x.cgroups(), ProcessTask::Process(x) => x.cgroups(),
_ => Err(ProcError::Other("not supported".to_string())), _ => Err(ProcError::Other("not supported".to_string())),
@ -218,7 +218,7 @@ impl ProcessInfo {
/// Memory size in number of bytes /// Memory size in number of bytes
pub fn mem_size(&self) -> u64 { pub fn mem_size(&self) -> u64 {
match self.curr_proc.stat() { match self.curr_proc.stat() {
Ok(p) => p.rss_bytes(), Ok(p) => p.rss_bytes().get(),
Err(_) => 0, Err(_) => 0,
} }
} }