Revert "sched: Don't duplicate caller file handler when creating kernel thread"

since the temporary kernel spawn proxy need duplicate file handler
from caller, please reference the follow source code for more info:
sched/task/task_posixspawn.c
sched/task/task_spawn.c

This reverts commit 5c5f1dec08.
This commit is contained in:
Xiang Xiao 2022-03-01 14:28:15 +08:00 committed by Petro Karashchenko
parent 7b366114c9
commit ddde41018a
3 changed files with 18 additions and 27 deletions

View File

@ -250,8 +250,7 @@ int files_allocate(FAR struct inode *inode, int oflags, off_t pos,
* *
****************************************************************************/ ****************************************************************************/
int files_duplist(FAR struct filelist *plist, int files_duplist(FAR struct filelist *plist, FAR struct filelist *clist)
FAR struct filelist *clist, bool stdio_only)
{ {
int ret; int ret;
int i; int i;
@ -265,28 +264,25 @@ int files_duplist(FAR struct filelist *plist,
return ret; return ret;
} }
#ifdef CONFIG_FDCLONE_STDIO
/* Determine how many file descriptors to clone. If
* CONFIG_FDCLONE_DISABLE is set, no file descriptors will be
* cloned. If CONFIG_FDCLONE_STDIO is set, only the first
* three descriptors (stdin, stdout, and stderr) will be
* cloned. Otherwise all file descriptors will be cloned.
*/
stdio_only = true;
#endif
for (i = 0; i < plist->fl_rows; i++) for (i = 0; i < plist->fl_rows; i++)
{ {
for (j = 0; j < CONFIG_NFILE_DESCRIPTORS_PER_BLOCK; j++) for (j = 0; j < CONFIG_NFILE_DESCRIPTORS_PER_BLOCK; j++)
{ {
FAR struct file *filep; FAR struct file *filep;
#ifdef CONFIG_FDCLONE_STDIO
if (stdio_only && i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + j >= 3) /* Determine how many file descriptors to clone. If
* CONFIG_FDCLONE_DISABLE is set, no file descriptors will be
* cloned. If CONFIG_FDCLONE_STDIO is set, only the first
* three descriptors (stdin, stdout, and stderr) will be
* cloned. Otherwise all file descriptors will be cloned.
*/
if (i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + j >= 3)
{ {
goto out; goto out;
} }
#endif
filep = &plist->fl_files[i][j]; filep = &plist->fl_files[i][j];
if (filep->f_inode == NULL || (filep->f_oflags & O_CLOEXEC) != 0) if (filep->f_inode == NULL || (filep->f_oflags & O_CLOEXEC) != 0)

View File

@ -759,8 +759,7 @@ void files_releaselist(FAR struct filelist *list);
* *
****************************************************************************/ ****************************************************************************/
int files_duplist(FAR struct filelist *plist, int files_duplist(FAR struct filelist *plist, FAR struct filelist *clist);
FAR struct filelist *clist, bool stdio_only);
/**************************************************************************** /****************************************************************************
* Name: file_dup * Name: file_dup

View File

@ -57,14 +57,16 @@
int group_setuptaskfiles(FAR struct task_tcb_s *tcb) int group_setuptaskfiles(FAR struct task_tcb_s *tcb)
{ {
FAR struct task_group_s *group = tcb->cmn.group; FAR struct task_group_s *group = tcb->cmn.group;
uint8_t ttype = tcb->cmn.flags & TCB_FLAG_TTYPE_MASK;
#ifndef CONFIG_FDCLONE_DISABLE #ifndef CONFIG_FDCLONE_DISABLE
FAR struct tcb_s *rtcb = this_task(); FAR struct tcb_s *rtcb = this_task();
int ret; int ret;
#endif #endif
DEBUGASSERT(group); DEBUGASSERT(group);
DEBUGASSERT(ttype != TCB_FLAG_TTYPE_PTHREAD); #ifndef CONFIG_DISABLE_PTHREAD
DEBUGASSERT((tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) !=
TCB_FLAG_TTYPE_PTHREAD);
#endif
/* Initialize file descriptors for the TCB */ /* Initialize file descriptors for the TCB */
@ -73,15 +75,9 @@ int group_setuptaskfiles(FAR struct task_tcb_s *tcb)
#ifndef CONFIG_FDCLONE_DISABLE #ifndef CONFIG_FDCLONE_DISABLE
DEBUGASSERT(rtcb->group); DEBUGASSERT(rtcb->group);
/* Duplicate the parent task's file descriptors. /* Duplicate the parent task's file descriptors */
* If it's a kernel thread, only the first three
* descriptors (stdin, stdout, and stderr) will
* be cloned.
*/
ret = files_duplist(&rtcb->group->tg_filelist, ret = files_duplist(&rtcb->group->tg_filelist, &group->tg_filelist);
&group->tg_filelist,
ttype == TCB_FLAG_TTYPE_KERNEL);
if (ret < 0) if (ret < 0)
{ {
return ret; return ret;