From 8a928d06e7b3e5cec336c145f15dae3efb972232 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Tue, 11 Apr 2017 06:59:03 +1000 Subject: [PATCH] oci: make ExecSync with ExitCode != 0 act properly Previously we returned an internal error result when a program had a non-zero exit code, which was incorrect. Fix this as well as change the tests to actually check the "ExitCode" response from ExecSync (rather than expecting ocic-ctr to return an internal error). Signed-off-by: Aleksa Sarai --- oci/oci.go | 11 +---------- test/seccomp.bats | 9 ++++++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/oci/oci.go b/oci/oci.go index 8c2124dc..fbfd7e56 100644 --- a/oci/oci.go +++ b/oci/oci.go @@ -380,15 +380,6 @@ func (r *Runtime) ExecSync(c *Container, command []string, timeout int64) (resp logrus.Infof("Received container exit code: %v", ec.ExitCode) - if ec.ExitCode != 0 { - return nil, ExecSyncError{ - Stdout: stdoutBuf, - Stderr: stderrBuf, - ExitCode: ec.ExitCode, - Err: fmt.Errorf("container workload exited with error %v", ec.ExitCode), - } - } - // The actual logged output is not the same as stdoutBuf and stderrBuf, // which are used for getting error information. For the actual // ExecSyncResponse we have to read the logfile. @@ -408,7 +399,7 @@ func (r *Runtime) ExecSync(c *Container, command []string, timeout int64) (resp return &ExecSyncResponse{ Stdout: outputBytes, Stderr: nil, - ExitCode: 0, + ExitCode: ec.ExitCode, }, nil } diff --git a/test/seccomp.bats b/test/seccomp.bats index 97ac125d..fa20978a 100644 --- a/test/seccomp.bats +++ b/test/seccomp.bats @@ -71,7 +71,8 @@ function teardown() { [ "$status" -eq 0 ] run ocic ctr execsync --id "$ctr_id" chmod 777 . echo "$output" - [ "$status" -ne 0 ] + [ "$status" -eq 0 ] + [[ "$output" =~ "Exit code: 1" ]] [[ "$output" =~ "Operation not permitted" ]] cleanup_ctrs @@ -158,7 +159,8 @@ function teardown() { [ "$status" -eq 0 ] run ocic ctr execsync --id "$ctr_id" chmod 777 . echo "$output" - [ "$status" -ne 0 ] + [ "$status" -eq 0 ] + [[ "$output" =~ "Exit code: 1" ]] [[ "$output" =~ "Operation not permitted" ]] cleanup_ctrs @@ -269,7 +271,8 @@ function teardown() { [ "$status" -eq 0 ] run ocic ctr execsync --id "$ctr_id" chmod 777 . echo "$output" - [ "$status" -ne 0 ] + [ "$status" -eq 0 ] + [[ "$output" =~ "Exit code: 1" ]] [[ "$output" =~ "Operation not permitted" ]] cleanup_ctrs