Skip to content

Commit

Permalink
Don't panic when cgroup controller multi-mounted
Browse files Browse the repository at this point in the history
This commit removes the calls to 'panic' when more than one mount
point for either the cgroupv2 controller or the cgroupv1 memory
controller is found.

It turns out that it is perfectly legal to have a cgroup controller
mounted at multiple points in the filesystem. It is now known that
some Linux security software does exactly this.

[#180668200]

Signed-off-by: Joseph Palermo <jpalermo@pivotal.io>
Co-authored-by: Joseph Palermo <jpalermo@pivotal.io>
  • Loading branch information
klakin-pivotal and jpalermo committed Jan 10, 2022
1 parent 6b64dac commit 4674909
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions sigar_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ func determineControllerMounts(sysd1, sysd2 *string) {

if mtype == "cgroup2" {
if *sysd2 != "" {
panic("Multiple cgroup v2 mount points")
return true
}
*sysd2 = mpath
return true
Expand All @@ -672,7 +672,7 @@ func determineControllerMounts(sysd1, sysd2 *string) {
options := strings.Split(moptions, ",")
if stringSliceContains(options, "memory") {
if *sysd1 != "" {
panic("Multiple cgroup v1 mount points")
return true
}
*sysd1 = mpath
return true
Expand Down
22 changes: 19 additions & 3 deletions sigar_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,25 @@ memory2 /smart/fox/jumped/by/lazy/dog cgroup2 irrelevant,options
})
})

// Note: We cannot test that the system panics when
// the file contains multiple entries for any of the
// controllers. Because, well, panic.
Describe("Multiple Mounts", func() {
var sys1, sys2 string

BeforeEach(func() {
setupFile(procd+"/self/mounts", `
device path type options
memory1 /somewhere/over/the/rainbow cgroup dummy,memory,and,other
memory2 /smart/fox/jumped/by/lazy/dog cgroup2 irrelevant,options
memory1 /somewhere/over/the/rainbow/duplicate cgroup dummy,memory,and,other
memory2 /smart/fox/jumped/by/lazy/dog/duplicate cgroup2 irrelevant,options
`)
})

It("it extracts the first matching mounts", func() {
determineControllerMounts(&sys1, &sys2)
Expect(sys1).To(Equal("/somewhere/over/the/rainbow"))
Expect(sys2).To(Equal("/smart/fox/jumped/by/lazy/dog"))
})
})
})

Describe("CPU", func() {
Expand Down

0 comments on commit 4674909

Please sign in to comment.