From 9a4a1092fee2bd10dfb7e3a4d0629dd6309533b8 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Tue, 10 Jan 2017 20:19:01 +0100 Subject: [PATCH] conmon: Return the exit status code waitpid fills its second argument with a value that contains the process exit code in the 8 least significant bits. Instead of returning the complete value and then convert it from ocid, return the exit status directly by using WEXITSTATUS from conmon. Signed-off-by: Samuel Ortiz --- conmon/conmon.c | 6 ++++-- oci/oci.go | 2 +- utils/utils.go | 5 ----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/conmon/conmon.c b/conmon/conmon.c index e33dd7bf..3ecc8f0d 100644 --- a/conmon/conmon.c +++ b/conmon/conmon.c @@ -303,10 +303,12 @@ int main(int argc, char *argv[]) /* Wait for the container process and record its exit code */ while ((pid = waitpid(-1, &status, 0)) > 0) { - printf("PID %d exited\n", pid); + int exit_status = WEXITSTATUS(status); + + printf("PID %d exited with status %d\n", pid, exit_status); if (pid == cpid) { _cleanup_free_ char *status_str = NULL; - ret = asprintf(&status_str, "%d", status); + ret = asprintf(&status_str, "%d", exit_status); if (ret < 0) { pexit("Failed to allocate memory for status"); } diff --git a/oci/oci.go b/oci/oci.go index eb0edbbb..b06ab2d3 100644 --- a/oci/oci.go +++ b/oci/oci.go @@ -335,7 +335,7 @@ func (r *Runtime) UpdateStatus(c *Container) error { if err != nil { return fmt.Errorf("status code conversion failed: %v", err) } - c.state.ExitCode = int32(utils.StatusToExitCode(statusCode)) + c.state.ExitCode = int32(statusCode) } return nil diff --git a/utils/utils.go b/utils/utils.go index fd3544fd..5323d290 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -125,8 +125,3 @@ func dockerRemove(container string) error { _, err := ExecCmd("docker", "rm", container) return err } - -// StatusToExitCode converts wait status code to an exit code -func StatusToExitCode(status int) int { - return ((status) & 0xff00) >> 8 -}