Skip to content

Commit

Permalink
sched/taskspawn: fix spawn fail if enable FDCHECK
Browse files Browse the repository at this point in the history
restore file descriptor before compare

Signed-off-by: chao an <[email protected]>
  • Loading branch information
anchao committed Nov 22, 2023
1 parent e5eabbb commit ac8f7a4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions sched/task/task_spawnparms.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
#include "task/spawn.h"
#include "task/task.h"

#ifdef CONFIG_FDCHECK
# include <nuttx/fdcheck.h>
#else
# define fdcheck_restore(fd) fd
#endif

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -97,7 +103,7 @@ static inline int nxspawn_open(FAR struct tcb_s *tcb,
{
ret = fd;
}
else if (fd != action->fd)
else if (fd != fdcheck_restore(action->fd))
{
ret = nx_dup2_from_tcb(tcb, fd, action->fd);
if (ret >= 0)
Expand Down Expand Up @@ -332,27 +338,27 @@ spawn_file_is_duplicateable(FAR const posix_spawn_file_actions_t *actions,
{
case SPAWN_FILE_ACTION_CLOSE:
close = (FAR struct spawn_close_file_action_s *)entry;
if (close->fd == fd)
if (fdcheck_restore(close->fd) == fd)
{
return false;
}
break;

case SPAWN_FILE_ACTION_DUP2:
dup2 = (FAR struct spawn_dup2_file_action_s *)entry;
if (dup2->fd1 == fd)
if (fdcheck_restore(dup2->fd1) == fd)
{
return true;
}
else if (dup2->fd2 == fd)
else if (fdcheck_restore(dup2->fd2) == fd)
{
return false;
}
break;

case SPAWN_FILE_ACTION_OPEN:
open = (FAR struct spawn_open_file_action_s *)entry;
if (open->fd == fd)
if (fdcheck_restore(open->fd) == fd)
{
return false;
}
Expand Down

0 comments on commit ac8f7a4

Please sign in to comment.