99 lines
2.9 KiB
C
99 lines
2.9 KiB
C
/****************************************************************************
|
|
* sched/group/group_setuptaskfiles.c
|
|
*
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
* this work for additional information regarding copyright ownership. The
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
* "License"); you may not use this file except in compliance with the
|
|
* License. You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
* License for the specific language governing permissions and limitations
|
|
* under the License.
|
|
*
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Included Files
|
|
****************************************************************************/
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <sched.h>
|
|
#include <assert.h>
|
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
#include "sched/sched.h"
|
|
#include "group/group.h"
|
|
|
|
/****************************************************************************
|
|
* Public Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: group_setuptaskfiles
|
|
*
|
|
* Description:
|
|
* Configure a newly allocated TCB so that it will inherit
|
|
* file descriptors and streams from the parent task.
|
|
*
|
|
* Input Parameters:
|
|
* tcb - tcb of the new task.
|
|
*
|
|
* Returned Value:
|
|
* Zero (OK) is returned on success; A negated errno value is returned on
|
|
* failure.
|
|
*
|
|
* Assumptions:
|
|
*
|
|
****************************************************************************/
|
|
|
|
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);
|
|
DEBUGASSERT(ttype != TCB_FLAG_TTYPE_PTHREAD);
|
|
|
|
/* Initialize file descriptors for the TCB */
|
|
|
|
files_initlist(&group->tg_filelist);
|
|
|
|
#ifndef CONFIG_FDCLONE_DISABLE
|
|
DEBUGASSERT(rtcb->group);
|
|
|
|
/* 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,
|
|
ttype == TCB_FLAG_TTYPE_KERNEL);
|
|
if (ret < 0)
|
|
{
|
|
return ret;
|
|
}
|
|
#endif
|
|
|
|
/* Allocate file/socket streams for the new TCB */
|
|
|
|
#ifdef CONFIG_FILE_STREAM
|
|
return group_setupstreams(tcb);
|
|
#else
|
|
return OK;
|
|
#endif
|
|
}
|