summaryrefslogtreecommitdiff
path: root/libpod/oci_conmon_linux.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-11-24 01:46:09 +0100
committerGitHub <noreply@github.com>2021-11-24 01:46:09 +0100
commit04be1e6485aec99d09edf3cdcf0769269ee42eb8 (patch)
tree54fee8347cdfaf931c19ac05da4f3e8ea0da988e /libpod/oci_conmon_linux.go
parent1be4c36e7ecbe05333e13320ea1e194b0c41b539 (diff)
parentdf6aa673024c96fb41e0f8170b44b6e7b12aaddb (diff)
downloadpodman-04be1e6485aec99d09edf3cdcf0769269ee42eb8.tar.gz
podman-04be1e6485aec99d09edf3cdcf0769269ee42eb8.tar.bz2
podman-04be1e6485aec99d09edf3cdcf0769269ee42eb8.zip
Merge pull request #12388 from rhatdan/test
Unset SocketLabel after system finishes checkpointing
Diffstat (limited to 'libpod/oci_conmon_linux.go')
-rw-r--r--libpod/oci_conmon_linux.go32
1 files changed, 26 insertions, 6 deletions
diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go
index baf05189c..3aab6864a 100644
--- a/libpod/oci_conmon_linux.go
+++ b/libpod/oci_conmon_linux.go
@@ -777,9 +777,6 @@ func (r *ConmonOCIRuntime) AttachResize(ctr *Container, newSize define.TerminalS
// CheckpointContainer checkpoints the given container.
func (r *ConmonOCIRuntime) CheckpointContainer(ctr *Container, options ContainerCheckpointOptions) (int64, error) {
- if err := label.SetSocketLabel(ctr.ProcessLabel()); err != nil {
- return 0, err
- }
// imagePath is used by CRIU to store the actual checkpoint files
imagePath := ctr.CheckpointPath()
if options.PreCheckPoint {
@@ -823,14 +820,37 @@ func (r *ConmonOCIRuntime) CheckpointContainer(ctr *Container, options Container
if err != nil {
return 0, err
}
+ args = append(args, ctr.ID())
+ logrus.Debugf("the args to checkpoint: %s %s", r.path, strings.Join(args, " "))
+
+ oldRuntimeDir, oldRuntimeDirSet := os.LookupEnv("XDG_RUNTIME_DIR")
if err = os.Setenv("XDG_RUNTIME_DIR", runtimeDir); err != nil {
return 0, errors.Wrapf(err, "cannot set XDG_RUNTIME_DIR")
}
- args = append(args, ctr.ID())
- logrus.Debugf("the args to checkpoint: %s %s", r.path, strings.Join(args, " "))
+ runtime.LockOSThread()
+ if err := label.SetSocketLabel(ctr.ProcessLabel()); err != nil {
+ return 0, err
+ }
+ defer func() {
+ if oldRuntimeDirSet {
+ if err := os.Setenv("XDG_RUNTIME_DIR", oldRuntimeDir); err != nil {
+ logrus.Warnf("cannot resset XDG_RUNTIME_DIR: %v", err)
+ }
+ } else {
+ if err := os.Unsetenv("XDG_RUNTIME_DIR"); err != nil {
+ logrus.Warnf("cannot unset XDG_RUNTIME_DIR: %v", err)
+ }
+ }
+ }()
runtimeCheckpointStarted := time.Now()
err = utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, nil, r.path, args...)
+ // Ignore error returned from SetSocketLabel("") call,
+ // can't recover.
+ if labelErr := label.SetSocketLabel(""); labelErr != nil {
+ logrus.Errorf("Unable to reset socket label: %q", labelErr)
+ }
+ runtime.UnlockOSThread()
runtimeCheckpointDuration := func() int64 {
if options.PrintStats {
@@ -1445,7 +1465,7 @@ func startCommandGivenSelinux(cmd *exec.Cmd, ctr *Container) error {
// Ignore error returned from SetProcessLabel("") call,
// can't recover.
if labelErr := label.SetProcessLabel(""); labelErr != nil {
- logrus.Errorf("Unable to set process label: %q", err)
+ logrus.Errorf("Unable to set process label: %q", labelErr)
}
runtime.UnlockOSThread()
return err