summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorDoug Rabson <dfr@rabson.org>2022-08-17 10:30:30 +0100
committerDoug Rabson <dfr@rabson.org>2022-08-18 08:05:42 +0100
commit93bad904864aa71c45b6b72d217a752c05eb254b (patch)
treef9bca7725ff7c1d59099155751778afcf713d404 /libpod
parent6791cdbdf153a0b3103810679995cc09ea8db340 (diff)
downloadpodman-93bad904864aa71c45b6b72d217a752c05eb254b.tar.gz
podman-93bad904864aa71c45b6b72d217a752c05eb254b.tar.bz2
podman-93bad904864aa71c45b6b72d217a752c05eb254b.zip
libpod: Move socket label handling from oci_conmon_common.go to oci_conmon_linux.go
[NO NEW TESTS NEEDED] Signed-off-by: Doug Rabson <dfr@rabson.org>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/oci_conmon_common.go24
-rw-r--r--libpod/oci_conmon_linux.go21
2 files changed, 26 insertions, 19 deletions
diff --git a/libpod/oci_conmon_common.go b/libpod/oci_conmon_common.go
index 4ca2d6e34..aee0c36c8 100644
--- a/libpod/oci_conmon_common.go
+++ b/libpod/oci_conmon_common.go
@@ -16,7 +16,6 @@ import (
"os"
"os/exec"
"path/filepath"
- "runtime"
"strconv"
"strings"
"sync"
@@ -42,7 +41,6 @@ import (
"github.com/containers/podman/v4/utils"
"github.com/containers/storage/pkg/homedir"
spec "github.com/opencontainers/runtime-spec/specs-go"
- "github.com/opencontainers/selinux/go-selinux/label"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
@@ -763,23 +761,11 @@ func (r *ConmonOCIRuntime) CheckpointContainer(ctr *Container, options Container
env = append(env, fmt.Sprintf("PATH=%s", path))
}
- runtime.LockOSThread()
- if err := label.SetSocketLabel(ctr.ProcessLabel()); err != nil {
- return 0, err
- }
-
- runtimeCheckpointStarted := time.Now()
- err = utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, env, r.path, args...)
- // Ignore error returned from SetSocketLabel("") call,
- // can't recover.
- if labelErr := label.SetSocketLabel(""); labelErr == nil {
- // Unlock the thread only if the process label could be restored
- // successfully. Otherwise leave the thread locked and the Go runtime
- // will terminate it once it returns to the threads pool.
- runtime.UnlockOSThread()
- } else {
- logrus.Errorf("Unable to reset socket label: %q", labelErr)
- }
+ var runtimeCheckpointStarted time.Time
+ err = r.withContainerSocketLabel(ctr, func() error {
+ runtimeCheckpointStarted = time.Now()
+ return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, env, r.path, args...)
+ })
runtimeCheckpointDuration := func() int64 {
if options.PrintStats {
diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go
index 4e8bbafd6..ce6eaf32a 100644
--- a/libpod/oci_conmon_linux.go
+++ b/libpod/oci_conmon_linux.go
@@ -8,6 +8,7 @@ import (
"github.com/containers/podman/v4/pkg/errorhandling"
pmount "github.com/containers/storage/pkg/mount"
+ "github.com/opencontainers/selinux/go-selinux/label"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
@@ -68,3 +69,23 @@ func (r *ConmonOCIRuntime) createRootlessContainer(ctr *Container, restoreOption
res := <-ch
return res.restoreDuration, res.err
}
+
+// Run the closure with the container's socket label set
+func (r *ConmonOCIRuntime) withContainerSocketLabel(ctr *Container, closure func() error) error {
+ runtime.LockOSThread()
+ if err := label.SetSocketLabel(ctr.ProcessLabel()); err != nil {
+ return err
+ }
+ err := closure()
+ // Ignore error returned from SetSocketLabel("") call,
+ // can't recover.
+ if labelErr := label.SetSocketLabel(""); labelErr == nil {
+ // Unlock the thread only if the process label could be restored
+ // successfully. Otherwise leave the thread locked and the Go runtime
+ // will terminate it once it returns to the threads pool.
+ runtime.UnlockOSThread()
+ } else {
+ logrus.Errorf("Unable to reset socket label: %q", labelErr)
+ }
+ return err
+}