Skip to content

Commit c5ab4b6

Browse files
committed
runc pause/unpause/ps: get rid of excessive warning
This issue was originally reported in podman PR 25792. When calling runc pause/unpause for an ordinary user, podman do not provide --systemd-cgroups option, and shouldUseRootlessCgroupManager returns true. This results in a warning: $ podman pause sleeper WARN[0000] runc pause may fail if you don't have the full access to cgroups sleeper Actually, it does not make sense to call shouldUseRootlessCgroupManager at this point, because we already know if we're rootless or not, from the container state.json (same for systemd). Also, busctl binary is not available either in this context, so shouldUseRootlessCgroupManager would not work properly. Finally, it doesn't really matter if we use systemd or not, because we use fs/fs2 manager to freeze/unfreeze, and it will return something like EPERM (or tell that cgroups is not configured, for a true rootless container). So, let's only print the warning after pause/unpause failed, if the error returned looks like a permission error. Same applies to "runc ps". Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent fda034c commit c5ab4b6

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

pause.go

+2-15
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,19 +18,13 @@ 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)
23-
if err != nil {
24-
return err
25-
}
26-
if rootlessCg {
27-
logrus.Warnf("runc pause may fail if you don't have the full access to cgroups")
28-
}
2921
container, err := getContainer(context)
3022
if err != nil {
3123
return err
3224
}
3325
err = container.Pause()
3426
if err != nil {
27+
maybeLogCgroupWarning("pause", err)
3528
return err
3629
}
3730
return nil
@@ -52,19 +45,13 @@ Use runc list to identify instances of containers and their current status.`,
5245
if err := checkArgs(context, 1, exactArgs); err != nil {
5346
return err
5447
}
55-
rootlessCg, err := shouldUseRootlessCgroupManager(context)
56-
if err != nil {
57-
return err
58-
}
59-
if rootlessCg {
60-
logrus.Warn("runc resume may fail if you don't have the full access to cgroups")
61-
}
6248
container, err := getContainer(context)
6349
if err != nil {
6450
return err
6551
}
6652
err = container.Resume()
6753
if err != nil {
54+
maybeLogCgroupWarning("resume", err)
6855
return err
6956
}
7057
return nil

ps.go

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

13-
"github.com/sirupsen/logrus"
1413
"github.com/urfave/cli"
1514
)
1615

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

4032
container, err := getContainer(context)
4133
if err != nil {
@@ -44,6 +36,7 @@ var psCommand = cli.Command{
4436

4537
pids, err := container.Processes()
4638
if err != nil {
39+
maybeLogCgroupWarning("ps", err)
4740
return err
4841
}
4942

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"
@@ -448,3 +449,9 @@ func setupPidfdSocket(process *libcontainer.Process, sockpath string) (_clean fu
448449
conn.Close()
449450
}, nil
450451
}
452+
453+
func maybeLogCgroupWarning(op string, err error) {
454+
if errors.Is(err, fs.ErrPermission) {
455+
logrus.Warn("runc " + op + " failure might be caused by lack of full access to cgroups")
456+
}
457+
}

0 commit comments

Comments
 (0)