mirror of
https://github.com/containers/podman.git
synced 2025-06-21 17:38:12 +08:00
If container exits with 125 podman should exit with 125
fixes: https://github.com/containers/podman/issues/11540 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@ -23,12 +23,10 @@ type CliCommand struct {
|
|||||||
Parent *cobra.Command
|
Parent *cobra.Command
|
||||||
}
|
}
|
||||||
|
|
||||||
const ExecErrorCodeGeneric = 125
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cliCtx context.Context
|
cliCtx context.Context
|
||||||
containerEngine entities.ContainerEngine
|
containerEngine entities.ContainerEngine
|
||||||
exitCode = ExecErrorCodeGeneric
|
exitCode = 0
|
||||||
imageEngine entities.ImageEngine
|
imageEngine entities.ImageEngine
|
||||||
|
|
||||||
// Commands holds the cobra.Commands to present to the user, including
|
// Commands holds the cobra.Commands to present to the user, including
|
||||||
|
@ -89,14 +89,10 @@ func init() {
|
|||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
if err := rootCmd.ExecuteContext(registry.GetContextWithOptions()); err != nil {
|
if err := rootCmd.ExecuteContext(registry.GetContextWithOptions()); err != nil {
|
||||||
|
if registry.GetExitCode() == 0 {
|
||||||
|
registry.SetExitCode(define.ExecErrorCodeGeneric)
|
||||||
|
}
|
||||||
fmt.Fprintln(os.Stderr, formatError(err))
|
fmt.Fprintln(os.Stderr, formatError(err))
|
||||||
} 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())
|
os.Exit(registry.GetExitCode())
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"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/entities"
|
||||||
"github.com/containers/podman/v3/pkg/domain/infra"
|
"github.com/containers/podman/v3/pkg/domain/infra"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -60,14 +61,14 @@ func migrate(cmd *cobra.Command, args []string) {
|
|||||||
engine, err := infra.NewSystemEngine(entities.MigrateMode, registry.PodmanConfig())
|
engine, err := infra.NewSystemEngine(entities.MigrateMode, registry.PodmanConfig())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(125)
|
os.Exit(define.ExecErrorCodeGeneric)
|
||||||
}
|
}
|
||||||
defer engine.Shutdown(registry.Context())
|
defer engine.Shutdown(registry.Context())
|
||||||
|
|
||||||
err = engine.Migrate(registry.Context(), cmd.Flags(), registry.PodmanConfig(), migrateOptions)
|
err = engine.Migrate(registry.Context(), cmd.Flags(), registry.PodmanConfig(), migrateOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(125)
|
os.Exit(define.ExecErrorCodeGeneric)
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"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/entities"
|
||||||
"github.com/containers/podman/v3/pkg/domain/infra"
|
"github.com/containers/podman/v3/pkg/domain/infra"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -47,14 +48,14 @@ func renumber(cmd *cobra.Command, args []string) {
|
|||||||
engine, err := infra.NewSystemEngine(entities.RenumberMode, registry.PodmanConfig())
|
engine, err := infra.NewSystemEngine(entities.RenumberMode, registry.PodmanConfig())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(125)
|
os.Exit(define.ExecErrorCodeGeneric)
|
||||||
}
|
}
|
||||||
defer engine.Shutdown(registry.Context())
|
defer engine.Shutdown(registry.Context())
|
||||||
|
|
||||||
err = engine.Renumber(registry.Context(), cmd.Flags(), registry.PodmanConfig())
|
err = engine.Renumber(registry.Context(), cmd.Flags(), registry.PodmanConfig())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(125)
|
os.Exit(define.ExecErrorCodeGeneric)
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
"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/entities"
|
||||||
"github.com/containers/podman/v3/pkg/domain/infra"
|
"github.com/containers/podman/v3/pkg/domain/infra"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -87,13 +88,13 @@ WARNING! This will remove:
|
|||||||
engine, err := infra.NewSystemEngine(entities.ResetMode, registry.PodmanConfig())
|
engine, err := infra.NewSystemEngine(entities.ResetMode, registry.PodmanConfig())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
os.Exit(125)
|
os.Exit(define.ExecErrorCodeGeneric)
|
||||||
}
|
}
|
||||||
defer engine.Shutdown(registry.Context())
|
defer engine.Shutdown(registry.Context())
|
||||||
|
|
||||||
if err := engine.Reset(registry.Context()); err != nil {
|
if err := engine.Reset(registry.Context()); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
os.Exit(125)
|
os.Exit(define.ExecErrorCodeGeneric)
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/containers/podman/v3/libpod/define"
|
"github.com/containers/podman/v3/libpod/define"
|
||||||
@ -63,4 +64,10 @@ var _ = Describe("Podman run exit", func() {
|
|||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
Expect(result).Should(Exit(50))
|
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))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user