diff --git a/libs/libc/spawn/lib_psfa_adddup2.c b/libs/libc/spawn/lib_psfa_adddup2.c index c05e270526..62e14b31bc 100644 --- a/libs/libc/spawn/lib_psfa_adddup2.c +++ b/libs/libc/spawn/lib_psfa_adddup2.c @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include @@ -64,6 +66,7 @@ int posix_spawn_file_actions_adddup2( int fd1, int fd2) { FAR struct spawn_dup2_file_action_s *entry; + int flags; DEBUGASSERT(file_actions && fd1 >= 0 && fd2 >= 0); @@ -83,6 +86,12 @@ int posix_spawn_file_actions_adddup2( entry->fd1 = fd1; entry->fd2 = fd2; + /* NOTE: Workaround to avoid an error when executing dup2 action */ + + flags = fcntl(fd1, F_GETFD); + flags &= ~FD_CLOEXEC; + fcntl(fd1, F_SETFD, flags); + /* And add it to the file action list */ add_file_action(file_actions,