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

kernel thread should have only the starndard file i/o just like idle thread

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-01-31 23:19:44 +08:00 committed by Masayuki Ishikawa
parent d48946063a
commit 5c5f1dec08
3 changed files with 27 additions and 18 deletions

View File

@ -250,7 +250,8 @@ int files_allocate(FAR struct inode *inode, int oflags, off_t pos,
*
****************************************************************************/
int files_duplist(FAR struct filelist *plist, FAR struct filelist *clist)
int files_duplist(FAR struct filelist *plist,
FAR struct filelist *clist, bool stdio_only)
{
int ret;
int i;
@ -264,25 +265,28 @@ int files_duplist(FAR struct filelist *plist, FAR struct filelist *clist)
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 (j = 0; j < CONFIG_NFILE_DESCRIPTORS_PER_BLOCK; j++)
{
FAR struct file *filep;
#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.
*/
if (i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + j >= 3)
if (stdio_only && i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + j >= 3)
{
goto out;
}
#endif
filep = &plist->fl_files[i][j];
if (filep->f_inode == NULL || (filep->f_oflags & O_CLOEXEC) != 0)

View File

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

View File

@ -57,16 +57,14 @@
int group_setuptaskfiles(FAR struct task_tcb_s *tcb)
{
FAR struct task_group_s *group = tcb->cmn.group;
uint8_t ttype = tcb->cmn.flags & TCB_FLAG_TTYPE_MASK;
#ifndef CONFIG_FDCLONE_DISABLE
FAR struct tcb_s *rtcb = this_task();
int ret;
#endif
DEBUGASSERT(group);
#ifndef CONFIG_DISABLE_PTHREAD
DEBUGASSERT((tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) !=
TCB_FLAG_TTYPE_PTHREAD);
#endif
DEBUGASSERT(ttype != TCB_FLAG_TTYPE_PTHREAD);
/* Initialize file descriptors for the TCB */
@ -75,9 +73,15 @@ int group_setuptaskfiles(FAR struct task_tcb_s *tcb)
#ifndef CONFIG_FDCLONE_DISABLE
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, &group->tg_filelist);
ret = files_duplist(&rtcb->group->tg_filelist,
&group->tg_filelist,
ttype == TCB_FLAG_TTYPE_KERNEL);
if (ret < 0)
{
return ret;