Skip to content

Commit

Permalink
Merge pull request #12406 from Luap99/xdg-checkpoint
Browse files Browse the repository at this point in the history
checkpoint do not modify XDG_RUNTIME_DIR
  • Loading branch information
openshift-merge-robot authored Nov 25, 2021
2 parents 12f73d5 + bc3c5be commit 7324d94
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
27 changes: 9 additions & 18 deletions libpod/oci_conmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7324d94

Please sign in to comment.