libs: spawn: Add forkaround for posix_spawn_file_actions_adddup2()

Summary:
- I noticed that adb shell failed when sh is spawned.
- Finally, I found that an error happened when executing dup2() action
  if the file descriptor has the O_CLOEXEC option.
- This commit fixes this issue by dropping the option in the API.

Impact:
- posix_spawn_file_actions_adddup2() only

Testing:
- adbd with sabre-6quad:netnsh (will be merged later)

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
This commit is contained in:
Masayuki Ishikawa 2022-07-20 08:47:42 +09:00 committed by Xiang Xiao
parent 2421a591a5
commit 2ce12617a1

View File

@ -28,6 +28,8 @@
#include <spawn.h>
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <nuttx/spawn.h>
@ -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,