fix wait after vfork return error

vfork use waitpid hang father process,
but waitpid release child processs information by default.
So when user call wait, it return errno 10.

Signed-off-by: yangyalei <yangyalei@xiaomi.com>
This commit is contained in:
yangyalei 2023-08-16 11:45:04 +08:00 committed by Petro Karashchenko
parent eba2f163ed
commit fd776e8cee
4 changed files with 11 additions and 8 deletions

View File

@ -628,7 +628,7 @@ static int goldfish_camera_data_uninit(FAR struct imgdata_s *data)
priv->streaming = false;
nxsem_post(&priv->run);
nxsched_waitpid(priv->pid, NULL, 0, 0);
nxsched_waitpid(priv->pid, NULL, 0);
nxsem_destroy(&priv->run);
file_close(&priv->file);

View File

@ -1456,7 +1456,7 @@ void nxsched_get_stateinfo(FAR struct tcb_s *tcb, FAR char *state,
* Input Parameters:
* pid - The task ID of the thread to waid for
* stat_loc - The location to return the exit status
* options - ignored
* options - Modifiable behavior, see sys/wait.h.
*
* Returned Value:
* If nxsched_waitpid() returns because the status of a child process is

View File

@ -63,7 +63,7 @@ pid_t vfork(void)
* until running finished or performing exec
*/
ret = waitpid(pid, &status, 0);
ret = waitpid(pid, &status, WNOWAIT);
if (ret < 0)
{
serr("ERROR: waitpid failed: %d\n", get_errno());

View File

@ -61,7 +61,7 @@
* Input Parameters:
* pid - The task ID of the thread to waid for
* stat_loc - The location to return the exit status
* options - ignored
* options - Modifiable behavior, see sys/wait.h.
*
* Returned Value:
* If nxsched_waitpid() returns because the status of a child process is
@ -388,8 +388,11 @@ pid_t nxsched_waitpid(pid_t pid, int *stat_loc, int options)
/* Discard the child entry and break out of the loop */
group_remove_child(rtcb->group, pid);
group_free_child(child);
if ((options & WNOWAIT) == 0)
{
group_remove_child(rtcb->group, pid);
group_free_child(child);
}
break;
}
}
@ -475,7 +478,7 @@ pid_t nxsched_waitpid(pid_t pid, int *stat_loc, int options)
/* Discard the child entry, if we have one */
if (child != NULL)
if (child != NULL && (options & WNOWAIT) == 0)
{
group_remove_child(rtcb->group, child->ch_pid);
group_free_child(child);
@ -591,7 +594,7 @@ errout:
* Input Parameters:
* pid - The task ID of the thread to waid for
* stat_loc - The location to return the exit status
* options - ignored
* options - Modifiable behavior, see sys/wait.h.
*
* Returned Value:
* If waitpid() returns because the status of a child process is available,