[PATCH v2] posix: Handle negative fds in spawn's addfchdir
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Thu Mar 26 12:41:11 GMT 2026
On 26/03/26 05:23, Lucas Chollet wrote:
> This patch makes `posix_spawn_file_actions_addfchdir` return EBADF on
> negative file descriptors. This is mandated by POSIX.
>
> Signed-off-by: Lucas Chollet <lucas.chollet@free.fr>
I think we should remove __spawn_valid_fd and make the fd description
handling consistent on all posix_spawn routines (posix_spawn_file_actions_addclose,
posix_spawn_file_actions_addclosefrom, posix_spawn_file_actions_adddup2,
posix_spawn_file_actions_addopen, posix_spawn_file_actions_addtcsetpgrp_np,
and posix_spawn_file_actions_addfchdir_np).
This will also need to adjust posix/tst-posix_spawn-fd that expects
that expets sysconf (_SC_OPEN_MAX) to fail.
> ---
> v2:
> - I used fd < 0 in place of !__spawn_valid_fd (fd)
>
> posix/spawn_faction_addfchdir.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/posix/spawn_faction_addfchdir.c b/posix/spawn_faction_addfchdir.c
> index a3df6df489..e851af1722 100644
> --- a/posix/spawn_faction_addfchdir.c
> +++ b/posix/spawn_faction_addfchdir.c
> @@ -28,6 +28,9 @@ posix_spawn_file_actions_addfchdir_np (posix_spawn_file_actions_t *actions,
> {
> struct __spawn_action *rec;
>
> + if (fd < 0)
> + return EBADF;
> +
> /* Allocate more memory if needed. */
> if (actions->__used == actions->__allocated
> && __posix_spawn_file_actions_realloc (actions) != 0)
More information about the Libc-alpha
mailing list