Merge pull request #4720 from kolyshkin/1.2-4709

[1.2] runc pause/unpause/ps: get rid of excessive warning
This commit is contained in:
lfbzhm
2025-04-10 07:05:05 +08:00
committed by GitHub
3 changed files with 20 additions and 25 deletions
+12 -17
View File
@@ -1,7 +1,6 @@
package main
import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@@ -19,18 +18,16 @@ Use runc list to identify instances of containers and their current status.`,
if err := checkArgs(context, 1, exactArgs); err != nil {
return err
}
rootlessCg, err := shouldUseRootlessCgroupManager(context)
if err != nil {
return err
}
if rootlessCg {
logrus.Warnf("runc pause may fail if you don't have the full access to cgroups")
}
container, err := getContainer(context)
if err != nil {
return err
}
return container.Pause()
err = container.Pause()
if err != nil {
maybeLogCgroupWarning("pause", err)
return err
}
return nil
},
}
@@ -48,17 +45,15 @@ Use runc list to identify instances of containers and their current status.`,
if err := checkArgs(context, 1, exactArgs); err != nil {
return err
}
rootlessCg, err := shouldUseRootlessCgroupManager(context)
if err != nil {
return err
}
if rootlessCg {
logrus.Warn("runc resume may fail if you don't have the full access to cgroups")
}
container, err := getContainer(context)
if err != nil {
return err
}
return container.Resume()
err = container.Resume()
if err != nil {
maybeLogCgroupWarning("resume", err)
return err
}
return nil
},
}
+1 -8
View File
@@ -9,7 +9,6 @@ import (
"strconv"
"strings"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@@ -28,13 +27,6 @@ var psCommand = cli.Command{
if err := checkArgs(context, 1, minArgs); err != nil {
return err
}
rootlessCg, err := shouldUseRootlessCgroupManager(context)
if err != nil {
return err
}
if rootlessCg {
logrus.Warn("runc ps may fail if you don't have the full access to cgroups")
}
container, err := getContainer(context)
if err != nil {
@@ -43,6 +35,7 @@ var psCommand = cli.Command{
pids, err := container.Processes()
if err != nil {
maybeLogCgroupWarning("ps", err)
return err
}
+7
View File
@@ -3,6 +3,7 @@ package main
import (
"errors"
"fmt"
"io/fs"
"net"
"os"
"path/filepath"
@@ -444,3 +445,9 @@ func setupPidfdSocket(process *libcontainer.Process, sockpath string) (_clean fu
conn.Close()
}, nil
}
func maybeLogCgroupWarning(op string, err error) {
if errors.Is(err, fs.ErrPermission) {
logrus.Warn("runc " + op + " failure might be caused by lack of full access to cgroups")
}
}