Skip to content

Commit b32f895

Browse files
committed
container: fix exit code return
do not return a negative value without an error. Closes: containers#1977 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
1 parent fe1e7d9 commit b32f895

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/libcrun/container.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,20 +3274,20 @@ libcrun_container_create (libcrun_context_t *context, libcrun_container_t *conta
32743274
waitpid_ignore_stopped (ret, NULL, 0);
32753275

32763276
ret = TEMP_FAILURE_RETRY (read (pipefd0, &exit_code, sizeof (exit_code)));
3277-
if (UNLIKELY (ret < 0))
3278-
return crun_make_error (err, errno, "waiting for container to be ready");
3279-
if (ret > 0)
3280-
{
3281-
if (exit_code != 0)
3282-
{
3283-
libcrun_debug ("Exit code is `%d`, deleting container", exit_code);
3284-
libcrun_error_t tmp_err = NULL;
3285-
libcrun_container_delete (context, def, context->id, true, &tmp_err);
3286-
crun_error_release (&tmp_err);
3287-
}
3288-
return -exit_code;
3289-
}
3290-
return 1;
3277+
if (UNLIKELY (ret <= 0))
3278+
return crun_make_error (err, ret < 0 ? errno : 0, "waiting for container to be ready");
3279+
3280+
if (ret != sizeof (exit_code) || exit_code < 0)
3281+
return crun_make_error (err, 0, "internal error: read invalid exit code");
3282+
3283+
if (exit_code == 0)
3284+
return 0;
3285+
3286+
libcrun_debug ("Exit code is `%d`, deleting container", exit_code);
3287+
libcrun_error_t tmp_err = NULL;
3288+
libcrun_container_delete (context, def, context->id, true, &tmp_err);
3289+
crun_error_release (&tmp_err);
3290+
return crun_make_error (err, 0, "error creating container");
32913291
}
32923292

32933293
/* forked process. */

0 commit comments

Comments
 (0)