Skip to content

Commit 271aa88

Browse files
committed
libct/cg/fs2: rm _defaultDirPath
The _defaultDirPath was only used for testing, and the test case is quite easy to adopt to defaultDirPath. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 7bebe68 commit 271aa88

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

libcontainer/cgroups/fs2/defaultpath.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package fs2
1919
import (
2020
"bufio"
2121
"errors"
22-
"fmt"
2322
"io"
2423
"os"
2524
"path/filepath"
@@ -33,26 +32,19 @@ const UnifiedMountpoint = "/sys/fs/cgroup"
3332

3433
func defaultDirPath(c *cgroups.Cgroup) (string, error) {
3534
if (c.Name != "" || c.Parent != "") && c.Path != "" {
36-
return "", fmt.Errorf("cgroup: either Path or Name and Parent should be used, got %+v", c)
37-
}
38-
39-
return _defaultDirPath(UnifiedMountpoint, c.Path, c.Parent, c.Name)
40-
}
41-
42-
func _defaultDirPath(root, cgPath, cgParent, cgName string) (string, error) {
43-
if (cgName != "" || cgParent != "") && cgPath != "" {
4435
return "", errors.New("cgroup: either Path or Name and Parent should be used")
4536
}
4637

4738
// XXX: Do not remove CleanPath. Path safety is important! -- cyphar
48-
innerPath := utils.CleanPath(cgPath)
39+
innerPath := utils.CleanPath(c.Path)
4940
if innerPath == "" {
50-
cgParent := utils.CleanPath(cgParent)
51-
cgName := utils.CleanPath(cgName)
41+
cgParent := utils.CleanPath(c.Parent)
42+
cgName := utils.CleanPath(c.Name)
5243
innerPath = filepath.Join(cgParent, cgName)
5344
}
45+
5446
if filepath.IsAbs(innerPath) {
55-
return filepath.Join(root, innerPath), nil
47+
return filepath.Join(UnifiedMountpoint, innerPath), nil
5648
}
5749

5850
// we don't need to use /proc/thread-self here because runc always runs
@@ -67,7 +59,7 @@ func _defaultDirPath(root, cgPath, cgParent, cgName string) (string, error) {
6759
// A parent cgroup (with no tasks in it) is what we need.
6860
ownCgroup = filepath.Dir(ownCgroup)
6961

70-
return filepath.Join(root, ownCgroup, innerPath), nil
62+
return filepath.Join(UnifiedMountpoint, ownCgroup, innerPath), nil
7163
}
7264

7365
// parseCgroupFile parses /proc/PID/cgroup file and return string

libcontainer/cgroups/fs2/defaultpath_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ func TestDefaultDirPath(t *testing.T) {
7676
},
7777
}
7878
for _, c := range cases {
79-
got, err := _defaultDirPath(UnifiedMountpoint, c.cgPath, c.cgParent, c.cgName)
79+
cg := &cgroups.Cgroup{
80+
Path: c.cgPath,
81+
Parent: c.cgParent,
82+
Name: c.cgName,
83+
}
84+
85+
got, err := defaultDirPath(cg)
8086
if err != nil {
8187
t.Fatal(err)
8288
}

0 commit comments

Comments
 (0)