Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If container exits with 125 podman should exit with 125 #11545

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions cmd/podman/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ type CliCommand struct {
Parent *cobra.Command
}

const ExecErrorCodeGeneric = 125

var (
cliCtx context.Context
containerEngine entities.ContainerEngine
exitCode = ExecErrorCodeGeneric
exitCode = 0
imageEngine entities.ImageEngine

// Commands holds the cobra.Commands to present to the user, including
Expand Down
10 changes: 3 additions & 7 deletions cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,10 @@ func init() {

func Execute() {
if err := rootCmd.ExecuteContext(registry.GetContextWithOptions()); err != nil {
if registry.GetExitCode() == 0 {
registry.SetExitCode(define.ExecErrorCodeGeneric)
}
fmt.Fprintln(os.Stderr, formatError(err))
Luap99 marked this conversation as resolved.
Show resolved Hide resolved
} else if registry.GetExitCode() == registry.ExecErrorCodeGeneric {
// The exitCode modified from registry.ExecErrorCodeGeneric,
// indicates an application
// running inside of a container failed, as opposed to the
// podman command failed. Must exit with that exit code
// otherwise command exited correctly.
registry.SetExitCode(0)
}
os.Exit(registry.GetExitCode())
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/podman/system/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/domain/infra"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -60,14 +61,14 @@ func migrate(cmd *cobra.Command, args []string) {
engine, err := infra.NewSystemEngine(entities.MigrateMode, registry.PodmanConfig())
if err != nil {
fmt.Println(err)
os.Exit(125)
os.Exit(define.ExecErrorCodeGeneric)
}
defer engine.Shutdown(registry.Context())

err = engine.Migrate(registry.Context(), cmd.Flags(), registry.PodmanConfig(), migrateOptions)
if err != nil {
fmt.Println(err)
os.Exit(125)
os.Exit(define.ExecErrorCodeGeneric)
}
os.Exit(0)
}
5 changes: 3 additions & 2 deletions cmd/podman/system/renumber.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/domain/infra"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -47,14 +48,14 @@ func renumber(cmd *cobra.Command, args []string) {
engine, err := infra.NewSystemEngine(entities.RenumberMode, registry.PodmanConfig())
if err != nil {
fmt.Println(err)
os.Exit(125)
os.Exit(define.ExecErrorCodeGeneric)
}
defer engine.Shutdown(registry.Context())

err = engine.Renumber(registry.Context(), cmd.Flags(), registry.PodmanConfig())
if err != nil {
fmt.Println(err)
os.Exit(125)
os.Exit(define.ExecErrorCodeGeneric)
}
os.Exit(0)
}
5 changes: 3 additions & 2 deletions cmd/podman/system/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/domain/infra"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -87,13 +88,13 @@ WARNING! This will remove:
engine, err := infra.NewSystemEngine(entities.ResetMode, registry.PodmanConfig())
if err != nil {
logrus.Error(err)
os.Exit(125)
os.Exit(define.ExecErrorCodeGeneric)
}
defer engine.Shutdown(registry.Context())

if err := engine.Reset(registry.Context()); err != nil {
logrus.Error(err)
os.Exit(125)
os.Exit(define.ExecErrorCodeGeneric)
}
os.Exit(0)
}
7 changes: 7 additions & 0 deletions test/e2e/run_exit_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration

import (
"fmt"
"os"

"github.com/containers/podman/v3/libpod/define"
Expand Down Expand Up @@ -63,4 +64,10 @@ var _ = Describe("Podman run exit", func() {
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(50))
})

It("podman run exit 125", func() {
result := podmanTest.Podman([]string{"run", ALPINE, "sh", "-c", fmt.Sprintf("exit %d", define.ExecErrorCodeGeneric)})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(define.ExecErrorCodeGeneric))
})
})