Skip to content

Commit 244d3c5

Browse files
authored
Merge pull request #4720 from kolyshkin/1.2-4709
[1.2] runc pause/unpause/ps: get rid of excessive warning
2 parents 1aa5198 + f602614 commit 244d3c5

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

pause.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"github.com/sirupsen/logrus"
54
"github.com/urfave/cli"
65
)
76

@@ -19,18 +18,16 @@ Use runc list to identify instances of containers and their current status.`,
1918
if err := checkArgs(context, 1, exactArgs); err != nil {
2019
return err
2120
}
22-
rootlessCg, err := shouldUseRootlessCgroupManager(context)
21+
container, err := getContainer(context)
2322
if err != nil {
2423
return err
2524
}
26-
if rootlessCg {
27-
logrus.Warnf("runc pause may fail if you don't have the full access to cgroups")
28-
}
29-
container, err := getContainer(context)
25+
err = container.Pause()
3026
if err != nil {
27+
maybeLogCgroupWarning("pause", err)
3128
return err
3229
}
33-
return container.Pause()
30+
return nil
3431
},
3532
}
3633

@@ -48,17 +45,15 @@ Use runc list to identify instances of containers and their current status.`,
4845
if err := checkArgs(context, 1, exactArgs); err != nil {
4946
return err
5047
}
51-
rootlessCg, err := shouldUseRootlessCgroupManager(context)
48+
container, err := getContainer(context)
5249
if err != nil {
5350
return err
5451
}
55-
if rootlessCg {
56-
logrus.Warn("runc resume may fail if you don't have the full access to cgroups")
57-
}
58-
container, err := getContainer(context)
52+
err = container.Resume()
5953
if err != nil {
54+
maybeLogCgroupWarning("resume", err)
6055
return err
6156
}
62-
return container.Resume()
57+
return nil
6358
},
6459
}

ps.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strconv"
1010
"strings"
1111

12-
"github.com/sirupsen/logrus"
1312
"github.com/urfave/cli"
1413
)
1514

@@ -28,13 +27,6 @@ var psCommand = cli.Command{
2827
if err := checkArgs(context, 1, minArgs); err != nil {
2928
return err
3029
}
31-
rootlessCg, err := shouldUseRootlessCgroupManager(context)
32-
if err != nil {
33-
return err
34-
}
35-
if rootlessCg {
36-
logrus.Warn("runc ps may fail if you don't have the full access to cgroups")
37-
}
3830

3931
container, err := getContainer(context)
4032
if err != nil {
@@ -43,6 +35,7 @@ var psCommand = cli.Command{
4335

4436
pids, err := container.Processes()
4537
if err != nil {
38+
maybeLogCgroupWarning("ps", err)
4639
return err
4740
}
4841

utils_linux.go

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"errors"
55
"fmt"
6+
"io/fs"
67
"net"
78
"os"
89
"path/filepath"
@@ -444,3 +445,9 @@ func setupPidfdSocket(process *libcontainer.Process, sockpath string) (_clean fu
444445
conn.Close()
445446
}, nil
446447
}
448+
449+
func maybeLogCgroupWarning(op string, err error) {
450+
if errors.Is(err, fs.ErrPermission) {
451+
logrus.Warn("runc " + op + " failure might be caused by lack of full access to cgroups")
452+
}
453+
}

0 commit comments

Comments
 (0)