Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mountpoint multiple match #42

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/cgroups/mountpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
_mountInfoSep = " "
_mountInfoOptsSep = ","
_mountInfoOptionalFieldsSep = "-"
_miFieldIDMountPointSep = "/"
)

const (
Expand Down Expand Up @@ -102,7 +103,11 @@

miFieldIDFSType := _miFieldOffsetFSType + fsTypeStart
miFieldIDMountSource := _miFieldOffsetMountSource + fsTypeStart
miFieldIDSuperOptions := _miFieldOffsetSuperOptions + fsTypeStart
rootOpts := strings.Split(fields[_miFieldIDMountPoint], _miFieldIDMountPointSep)
if len(rootOpts) == 0 {
return nil, mountPointFormatInvalidError{line}

Check warning on line 108 in internal/cgroups/mountpoint.go

View check run for this annotation

Codecov / codecov/patch

internal/cgroups/mountpoint.go#L108

Added line #L108 was not covered by tests
}
superOpts := strings.Split(rootOpts[len(rootOpts)-1], _mountInfoOptsSep)

return &MountPoint{
MountID: mountID,
Expand All @@ -114,7 +119,7 @@
OptionalFields: fields[_miFieldIDOptionalFields:(fsTypeStart - 1)],
FSType: fields[miFieldIDFSType],
MountSource: fields[miFieldIDMountSource],
SuperOptions: strings.Split(fields[miFieldIDSuperOptions], _mountInfoOptsSep),
SuperOptions: superOpts,
}, nil
}
}
Expand All @@ -130,6 +135,7 @@
if err != nil {
return "", err
}

if relPath == ".." || strings.HasPrefix(relPath, "../") {
return "", pathNotExposedFromMountPointError{
mountPoint: mp.MountPoint,
Expand Down
4 changes: 2 additions & 2 deletions internal/cgroups/mountpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestNewMountPointFromLine(t *testing.T) {
OptionalFields: []string{},
FSType: "ext4",
MountSource: "/dev/dm-0",
SuperOptions: []string{"rw", "errors=remount-ro", "data=ordered"},
SuperOptions: []string{""},
},
},
{
Expand All @@ -63,7 +63,7 @@ func TestNewMountPointFromLine(t *testing.T) {
OptionalFields: []string{"shared:1"},
FSType: "cgroup",
MountSource: "cgroup",
SuperOptions: []string{"rw", "cpu"},
SuperOptions: []string{"cpu"},
},
},
}
Expand Down
1 change: 1 addition & 0 deletions internal/cgroups/testdata/proc/cgroups/mountinfo
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
6 5 0:5 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:6 - cgroup cgroup rw,cpuset
7 5 0:6 /docker /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:7 - cgroup cgroup rw,cpu,cpuacct
8 5 0:7 /docker /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime shared:8 - cgroup cgroup rw,memory
9 5 0:8 /docker/memory.vmstat /sys/fs/cgroup/vmstat rw,nosuid,nodev,noexec,relatime shared:8 - cgroup cgroup rw,memory