Closes #8379
Signed-off-by: Doug Davis <dug@us.ibm.com>
| ... | ... |
@@ -302,6 +302,10 @@ func (container *Container) Start() (err error) {
|
| 302 | 302 |
defer func() {
|
| 303 | 303 |
if err != nil {
|
| 304 | 304 |
container.setError(err) |
| 305 |
+ // if no one else has set it, make sure we don't leave it at zero |
|
| 306 |
+ if container.ExitCode == 0 {
|
|
| 307 |
+ container.ExitCode = 128 |
|
| 308 |
+ } |
|
| 305 | 309 |
container.toDisk() |
| 306 | 310 |
container.cleanup() |
| 307 | 311 |
} |
| ... | ... |
@@ -138,6 +138,7 @@ func (m *containerMonitor) Start() error {
|
| 138 | 138 |
// if we receive an internal error from the initial start of a container then lets |
| 139 | 139 |
// return it instead of entering the restart loop |
| 140 | 140 |
if m.container.RestartCount == 0 {
|
| 141 |
+ m.container.ExitCode = exitStatus |
|
| 141 | 142 |
m.resetContainer(false) |
| 142 | 143 |
|
| 143 | 144 |
return err |
| ... | ... |
@@ -163,10 +164,12 @@ func (m *containerMonitor) Start() error {
|
| 163 | 163 |
// we need to check this before reentering the loop because the waitForNextRestart could have |
| 164 | 164 |
// been terminated by a request from a user |
| 165 | 165 |
if m.shouldStop {
|
| 166 |
+ m.container.ExitCode = exitStatus |
|
| 166 | 167 |
return err |
| 167 | 168 |
} |
| 168 | 169 |
continue |
| 169 | 170 |
} |
| 171 |
+ m.container.ExitCode = exitStatus |
|
| 170 | 172 |
m.container.LogEvent("die")
|
| 171 | 173 |
m.resetContainer(true) |
| 172 | 174 |
return err |
| ... | ... |
@@ -2538,3 +2538,33 @@ func TestRunAllowPortRangeThroughExpose(t *testing.T) {
|
| 2538 | 2538 |
} |
| 2539 | 2539 |
logDone("run - allow port range through --expose flag")
|
| 2540 | 2540 |
} |
| 2541 |
+ |
|
| 2542 |
+func TestRunUnknownCommand(t *testing.T) {
|
|
| 2543 |
+ defer deleteAllContainers() |
|
| 2544 |
+ runCmd := exec.Command(dockerBinary, "create", "busybox", "/bin/nada") |
|
| 2545 |
+ cID, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
| 2546 |
+ if err != nil {
|
|
| 2547 |
+ t.Fatalf("Failed to create container: %v, output: %q", err, cID)
|
|
| 2548 |
+ } |
|
| 2549 |
+ cID = strings.TrimSpace(cID) |
|
| 2550 |
+ |
|
| 2551 |
+ runCmd = exec.Command(dockerBinary, "start", cID) |
|
| 2552 |
+ _, _, _, err = runCommandWithStdoutStderr(runCmd) |
|
| 2553 |
+ if err == nil {
|
|
| 2554 |
+ t.Fatalf("Container should not have been able to start!")
|
|
| 2555 |
+ } |
|
| 2556 |
+ |
|
| 2557 |
+ runCmd = exec.Command(dockerBinary, "inspect", "--format={{.State.ExitCode}}", cID)
|
|
| 2558 |
+ rc, _, _, err2 := runCommandWithStdoutStderr(runCmd) |
|
| 2559 |
+ rc = strings.TrimSpace(rc) |
|
| 2560 |
+ |
|
| 2561 |
+ if err2 != nil {
|
|
| 2562 |
+ t.Fatalf("Error getting status of container: %v", err2)
|
|
| 2563 |
+ } |
|
| 2564 |
+ |
|
| 2565 |
+ if rc != "-1" {
|
|
| 2566 |
+ t.Fatalf("ExitCode(%v) was supposed to be -1", rc)
|
|
| 2567 |
+ } |
|
| 2568 |
+ |
|
| 2569 |
+ logDone("run - Unknown Command")
|
|
| 2570 |
+} |