Skip to content

Commit

Permalink
fix: Don't return errors or warnings for PID 0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vadorovsky authored and banditopazzo committed Jan 10, 2024
1 parent c2fc521 commit 475b779
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions crates/bpf-common/src/parsing/procfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ fn get_container_id_from_cgroup(cgroup_info: &str) -> Option<ContainerId> {
}

pub fn get_process_container_id(pid: Pid) -> Result<Option<ContainerId>, ProcfsError> {
if pid.as_raw() == 0 {
return Ok(None);
}

let path = format!("/proc/{pid}/cgroup");
let file = File::open(&path).map_err(|source| ProcfsError::ReadFile { source, path })?;

Expand Down
14 changes: 8 additions & 6 deletions crates/bpf-filtering/src/process_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ fn get_process_namespace(pid: Pid, ns_type: &str) -> Result<u32, Error> {
fn get_process_namespace_or_log(pid: Pid, namespace_type: &str) -> u32 {
get_process_namespace(pid, namespace_type).map_or_else(
|e| {
log::warn!(
"Failed to determine {} namespace for process {:?}: {}",
namespace_type,
pid,
e
);
if pid.as_raw() != 0 {
log::warn!(
"Failed to determine {} namespace for process {:?}: {}",
namespace_type,
pid,
e
);
}
u32::default()
},
|v| v,
Expand Down

0 comments on commit 475b779

Please sign in to comment.