Skip to content

Commit b28735d

Browse files
committed
Linting and error fixing
1 parent d2890ea commit b28735d

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

lading/src/observer/linux/procfs.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::io;
88

99
use metrics::{counter, gauge};
1010
use nix::errno::Errno;
11-
use nix::unistd;
1211
use procfs::process::Process;
1312
use rustc_hash::FxHashMap;
1413
use tokio::fs;
@@ -19,11 +18,13 @@ use tracing::{error, warn};
1918
/// The long-term approach is to use flag-based detection exclusively.
2019
/// The heuristic method is maintained temporarily for validation and transition.
2120
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22-
pub enum DetectionMode {
21+
pub(super) enum DetectionMode {
2322
/// TEMPORARY: Use the original heuristic (identical exe and cmdline) for backward compatibility
2423
/// This will be deprecated once flag-based detection is fully validated
24+
#[allow(dead_code)]
2525
HeuristicLegacy,
26-
/// PREFERRED: Use the PF_FORKNOEXEC flag in process flags (long-term approach)
26+
/// PREFERRED: Use the `PF_FORKNOEXEC` flag in process flags (long-term approach)
27+
#[allow(dead_code)]
2728
Flag,
2829
/// VALIDATION: Use both methods and log disagreements for validation purposes
2930
/// This helps validate the flag-based approach before full transition
@@ -55,11 +56,11 @@ const BYTES_PER_KIBIBYTE: u64 = 1024;
5556
/// actually sharing pages with the parent.
5657
///
5758
/// Returns true if the child is forked but not exec'd, false otherwise.
58-
/// Check if process has PF_FORKNOEXEC flag set
59+
/// Check if process has `PF_FORKNOEXEC` flag set
5960
#[inline]
6061
fn has_forknoexec_flag(flags: u32) -> bool {
6162
// PF_FORKNOEXEC flag is bit 0x00000040
62-
(flags & 0x00000040) != 0
63+
(flags & 0x0000_0040) != 0
6364
}
6465

6566
/// Determines if a child process is forked but not exec'd based on the configured detection mode
@@ -142,6 +143,15 @@ pub enum Error {
142143
/// Wrapper for [`vmstat::Error`]
143144
#[error("Unable to read vmstat: {0}")]
144145
Vmstat(#[from] vmstat::Error),
146+
/// Error reading /proc/[pid]/stat file
147+
#[error("Unable to read /proc/[pid]/stat: {0}")]
148+
ProcStatIo(#[source] io::Error),
149+
/// Error parsing /proc/[pid]/stat content
150+
#[error("Unable to parse /proc/[pid]/stat: {0}")]
151+
ProcStatParse(#[source] std::num::ParseIntError),
152+
/// Malformed /proc/[pid]/stat content
153+
#[error("Malformed /proc/[pid]/stat: {0}")]
154+
ProcStatMalformed(&'static str),
145155
}
146156

147157
macro_rules! report_status_field {
@@ -161,7 +171,7 @@ struct ProcessInfo {
161171
pid_s: String,
162172
stat_sampler: stat::Sampler,
163173
/// Process flags from /proc/<pid>/stat field 9
164-
/// Includes PF_FORKNOEXEC flag (0x00000040) when a process is forked but not exec'd
174+
/// Includes `PF_FORKNOEXEC` flag (0x00000040) when a process is forked but not exec'd
165175
process_flags: u32,
166176
}
167177

@@ -537,14 +547,14 @@ async fn proc_cmdline(pid: i32) -> Result<String, Error> {
537547
/// Extract process flags from /proc/<pid>/stat
538548
///
539549
/// The 9th field in /proc/<pid>/stat contains the process flags, including
540-
/// PF_FORKNOEXEC (0x00000040) which is set in a freshly forked process
550+
/// `PF_FORKNOEXEC` (0x00000040) which is set in a freshly forked process
541551
/// that hasn't executed a new program yet.
542552
async fn get_process_flags(pid: i32) -> Result<u32, Error> {
543553
// Read the stat file contents
544554
let stat_path = format!("/proc/{pid}/stat");
545555
let content = fs::read_to_string(&stat_path)
546556
.await
547-
.map_err(|e| Error::ProcStatIo(e))?;
557+
.map_err(Error::ProcStatIo)?;
548558

549559
// Parse the content - fields are space-separated, but the 2nd field (comm) can contain spaces
550560
// and is wrapped in parentheses, so we need to handle it carefully
@@ -557,9 +567,7 @@ async fn get_process_flags(pid: i32) -> Result<u32, Error> {
557567
// The flags field is now the 7th field (after skipping pid and comm)
558568
// Which is field index 6 (zero-based)
559569
if fields.len() > 6 {
560-
return fields[6]
561-
.parse::<u32>()
562-
.map_err(|e| Error::ProcStatParse(e));
570+
return fields[6].parse::<u32>().map_err(Error::ProcStatParse);
563571
}
564572
}
565573

0 commit comments

Comments
 (0)