summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-08-02 03:44:43 +0200
committerGitHub <noreply@github.com>2019-08-02 03:44:43 +0200
commite3240daa471dee1bbc118e6b3871c4a73890d0e0 (patch)
tree402bfadad932067a96635f799d3c3fd98282d5b2 /pkg
parente48dc506d18335b36d1ffbbc8df1890ee3b99e2c (diff)
parent8da24f2f7d3472d2be4ccde8e7b42790671d464f (diff)
downloadpodman-e3240daa471dee1bbc118e6b3871c4a73890d0e0.tar.gz
podman-e3240daa471dee1bbc118e6b3871c4a73890d0e0.tar.bz2
podman-e3240daa471dee1bbc118e6b3871c4a73890d0e0.zip
Merge pull request #3551 from mheon/fix_memory_leak
Fix memory leak with exit files
Diffstat (limited to 'pkg')
-rw-r--r--pkg/adapter/containers.go45
-rw-r--r--pkg/spec/createconfig.go3
2 files changed, 10 insertions, 38 deletions
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go
index faaef3e60..155454e21 100644
--- a/pkg/adapter/containers.go
+++ b/pkg/adapter/containers.go
@@ -9,7 +9,6 @@ import (
"io"
"io/ioutil"
"os"
- "path/filepath"
"strconv"
"strings"
"sync"
@@ -23,6 +22,7 @@ import (
"github.com/containers/libpod/cmd/podman/shared/parse"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/define"
+ "github.com/containers/libpod/libpod/events"
"github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/libpod/logs"
"github.com/containers/libpod/pkg/adapter/shortcuts"
@@ -418,14 +418,13 @@ func (r *LocalRuntime) Run(ctx context.Context, c *cliconfig.RunValues, exitCode
if ecode, err := ctr.Wait(); err != nil {
if errors.Cause(err) == define.ErrNoSuchCtr {
- // The container may have been removed
- // Go looking for an exit file
- ctrExitCode, err := ReadExitFile(config.TmpDir, ctr.ID())
+ // Check events
+ event, err := r.Runtime.GetLastContainerEvent(ctr.ID(), events.Exited)
if err != nil {
logrus.Errorf("Cannot get exit code: %v", err)
exitCode = 127
} else {
- exitCode = ctrExitCode
+ exitCode = event.ContainerExitCode
}
}
} else {
@@ -441,31 +440,6 @@ func (r *LocalRuntime) Run(ctx context.Context, c *cliconfig.RunValues, exitCode
return exitCode, nil
}
-// ReadExitFile reads a container's exit file
-func ReadExitFile(runtimeTmp, ctrID string) (int, error) {
- exitFile := filepath.Join(runtimeTmp, "exits", fmt.Sprintf("%s-old", ctrID))
-
- logrus.Debugf("Attempting to read container %s exit code from file %s", ctrID, exitFile)
-
- // Check if it exists
- if _, err := os.Stat(exitFile); err != nil {
- return 0, errors.Wrapf(err, "error getting exit file for container %s", ctrID)
- }
-
- // File exists, read it in and convert to int
- statusStr, err := ioutil.ReadFile(exitFile)
- if err != nil {
- return 0, errors.Wrapf(err, "error reading exit file for container %s", ctrID)
- }
-
- exitCode, err := strconv.Atoi(string(statusStr))
- if err != nil {
- return 0, errors.Wrapf(err, "error parsing exit code for container %s", ctrID)
- }
-
- return exitCode, nil
-}
-
// Ps ...
func (r *LocalRuntime) Ps(c *cliconfig.PsValues, opts shared.PsOptions) ([]shared.PsContainerOutput, error) {
maxWorkers := shared.Parallelize("ps")
@@ -655,18 +629,13 @@ func (r *LocalRuntime) Start(ctx context.Context, c *cliconfig.StartValues, sigP
if ecode, err := ctr.Wait(); err != nil {
if errors.Cause(err) == define.ErrNoSuchCtr {
- // The container may have been removed
- // Go looking for an exit file
- rtc, err := r.GetConfig()
- if err != nil {
- return 0, err
- }
- ctrExitCode, err := ReadExitFile(rtc.TmpDir, ctr.ID())
+ // Check events
+ event, err := r.Runtime.GetLastContainerEvent(ctr.ID(), events.Exited)
if err != nil {
logrus.Errorf("Cannot get exit code: %v", err)
exitCode = 127
} else {
- exitCode = ctrExitCode
+ exitCode = event.ContainerExitCode
}
}
} else {
diff --git a/pkg/spec/createconfig.go b/pkg/spec/createconfig.go
index 214a3c5ed..f21ae2831 100644
--- a/pkg/spec/createconfig.go
+++ b/pkg/spec/createconfig.go
@@ -168,6 +168,9 @@ func (c *CreateConfig) createExitCommand(runtime *libpod.Runtime) ([]string, err
for _, opt := range config.StorageConfig.GraphDriverOptions {
command = append(command, []string{"--storage-opt", opt}...)
}
+ if config.EventsLogger != "" {
+ command = append(command, []string{"--events-backend", config.EventsLogger}...)
+ }
if c.Syslog {
command = append(command, "--syslog", "true")