Skip to content

Commit 475b779

Browse files
vadorovskybanditopazzo
authored andcommitted
fix: Don't return errors or warnings for PID 0
The scheduler/idle task is not our object of interes and it has no cgroups or namespaces, it also never can belong to any container. Just ignore it.
1 parent c2fc521 commit 475b779

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

crates/bpf-common/src/parsing/procfs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ fn get_container_id_from_cgroup(cgroup_info: &str) -> Option<ContainerId> {
178178
}
179179

180180
pub fn get_process_container_id(pid: Pid) -> Result<Option<ContainerId>, ProcfsError> {
181+
if pid.as_raw() == 0 {
182+
return Ok(None);
183+
}
184+
181185
let path = format!("/proc/{pid}/cgroup");
182186
let file = File::open(&path).map_err(|source| ProcfsError::ReadFile { source, path })?;
183187

crates/bpf-filtering/src/process_tree.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ fn get_process_namespace(pid: Pid, ns_type: &str) -> Result<u32, Error> {
6666
fn get_process_namespace_or_log(pid: Pid, namespace_type: &str) -> u32 {
6767
get_process_namespace(pid, namespace_type).map_or_else(
6868
|e| {
69-
log::warn!(
70-
"Failed to determine {} namespace for process {:?}: {}",
71-
namespace_type,
72-
pid,
73-
e
74-
);
69+
if pid.as_raw() != 0 {
70+
log::warn!(
71+
"Failed to determine {} namespace for process {:?}: {}",
72+
namespace_type,
73+
pid,
74+
e
75+
);
76+
}
7577
u32::default()
7678
},
7779
|v| v,

0 commit comments

Comments
 (0)