1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

posix: fix system when a child cannot be created [BZ #32450]

POSIX states that "if a child process cannot be created, or if the
termination status for the command language interpreter cannot be
obtained, system() shall return -1 and set errno to indicate the error."

In the glibc implementation it could happen when posix_spawn fails,
which happens when the underlying fork, vfork, or clone call fails. They
could fail with EAGAIN and ENOMEM.

Resolves: BZ #32450
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
This commit is contained in:
Aurelien Jarno
2024-12-19 23:55:15 +01:00
parent 034cd67528
commit 6fd215d6ae
2 changed files with 28 additions and 3 deletions

View File

@@ -175,10 +175,14 @@ do_system (const char *line)
__libc_cleanup_region_end (0);
#endif
}
else if (ret == EAGAIN || ret == ENOMEM)
/* POSIX states that failure to create a child process should
return -1. */
status = -1;
else
/* POSIX states that failure to execute the shell should return
as if the shell had terminated using _exit(127). */
status = W_EXITCODE (127, 0);
/* POSIX states that failure to execute the shell should return
as if the shell had terminated using _exit(127). */
status = W_EXITCODE (127, 0);
/* sigaction can not fail with SIGINT/SIGQUIT used with old
disposition. Same applies for sigprocmask. */