diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-11-25 12:02:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-25 12:02:10 +0100 |
commit | 7324d94648a9987b0de2dc95cf1b6fbc20592532 (patch) | |
tree | 70b7c23eba1422ed95fc24bcea6f2782f6d38e49 | |
parent | 12f73d5f88d8646058bbb4e673b04b413732dbe2 (diff) | |
parent | bc3c5be2fb0fe652db53b931e1ae4a42da6fa014 (diff) | |
download | podman-7324d94648a9987b0de2dc95cf1b6fbc20592532.tar.gz podman-7324d94648a9987b0de2dc95cf1b6fbc20592532.tar.bz2 podman-7324d94648a9987b0de2dc95cf1b6fbc20592532.zip |
Merge pull request #12406 from Luap99/xdg-checkpoint
checkpoint do not modify XDG_RUNTIME_DIR
-rw-r--r-- | libpod/oci_conmon_linux.go | 27 | ||||
-rw-r--r-- | utils/utils.go | 4 |
2 files changed, 10 insertions, 21 deletions
diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go index 8534c9fdb..a83f166a3 100644 --- a/libpod/oci_conmon_linux.go +++ b/libpod/oci_conmon_linux.go @@ -816,35 +816,26 @@ func (r *ConmonOCIRuntime) CheckpointContainer(ctr *Container, options Container filepath.Join("..", preCheckpointDir), ) } + + args = append(args, ctr.ID()) + logrus.Debugf("the args to checkpoint: %s %s", r.path, strings.Join(args, " ")) + runtimeDir, err := util.GetRuntimeDir() 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") + env := []string{fmt.Sprintf("XDG_RUNTIME_DIR=%s", runtimeDir)} + if path, ok := os.LookupEnv("PATH"); ok { + env = append(env, fmt.Sprintf("PATH=%s", path)) } + 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...) + 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 { diff --git a/utils/utils.go b/utils/utils.go index f2e7beef9..80eed7536 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -43,9 +43,7 @@ func ExecCmdWithStdStreams(stdin io.Reader, stdout, stderr io.Writer, env []stri cmd.Stdin = stdin cmd.Stdout = stdout cmd.Stderr = stderr - if env != nil { - cmd.Env = env - } + cmd.Env = env err := cmd.Run() if err != nil { |