Skip to content

Commit

Permalink
refactor: adjust bpfd container runtime detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ejose19 authored and MyIgel committed Mar 21, 2022
1 parent 53b6303 commit 07a79a0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/util/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ func GetContainerRuntime(tgid, pid int) ContainerRuntime {
return runtime
}

// Check for container specific files
runtime = detectContainerFiles()
if runtime != RuntimeNotFound {
return runtime
}

return RuntimeNotFound
}

// Related implementation: https://github.com/systemd/systemd/blob/6604fb0207ee10e8dc05d67f6fe45de0b193b5c4/src/basic/virt.c#L523-L549
func detectContainerFiles() ContainerRuntime {
files := []struct {
runtime ContainerRuntime
location string
}{
// https://github.com/containers/podman/issues/6192
// https://github.com/containers/podman/issues/3586#issuecomment-661918679
{RuntimePodman, "/run/.containerenv"},
// https://github.com/moby/moby/issues/18355
{RuntimeDocker, "/.dockerenv"},
}

for i := range files {
if osFileExists(files[i].location) {
return files[i].runtime
}
}

return RuntimeNotFound
}

Expand Down

0 comments on commit 07a79a0

Please sign in to comment.