2008-01-30 07:58:39 +08:00
|
|
|
/****************************************************************************
|
2021-03-09 05:39:04 +08:00
|
|
|
* sched/group/group_setuptaskfiles.c
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2020-04-29 00:17:03 +08:00
|
|
|
* 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.
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2008-01-30 07:58:39 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2008-01-30 07:58:39 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Included Files
|
2008-01-30 07:58:39 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2007-09-02 02:06:15 +08:00
|
|
|
|
2007-02-18 07:21:28 +08:00
|
|
|
#include <sched.h>
|
2021-05-18 14:59:14 +08:00
|
|
|
#include <assert.h>
|
2007-09-02 02:06:15 +08:00
|
|
|
|
2012-03-22 02:01:07 +08:00
|
|
|
#include <nuttx/fs/fs.h>
|
2007-09-02 02:06:15 +08:00
|
|
|
|
2014-08-09 07:53:55 +08:00
|
|
|
#include "sched/sched.h"
|
2014-08-09 04:06:42 +08:00
|
|
|
#include "group/group.h"
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2008-01-30 07:58:39 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Public Functions
|
2008-01-30 07:58:39 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2008-01-30 07:58:39 +08:00
|
|
|
/****************************************************************************
|
2013-01-27 07:49:02 +08:00
|
|
|
* Name: group_setuptaskfiles
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configure a newly allocated TCB so that it will inherit
|
|
|
|
* file descriptors and streams from the parent task.
|
|
|
|
*
|
2018-03-13 23:52:27 +08:00
|
|
|
* Input Parameters:
|
2007-02-18 07:21:28 +08:00
|
|
|
* tcb - tcb of the new task.
|
|
|
|
*
|
2018-02-02 00:00:02 +08:00
|
|
|
* Returned Value:
|
2013-01-08 03:35:47 +08:00
|
|
|
* Zero (OK) is returned on success; A negated errno value is returned on
|
|
|
|
* failure.
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
2008-01-30 07:58:39 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2013-02-05 05:24:00 +08:00
|
|
|
int group_setuptaskfiles(FAR struct task_tcb_s *tcb)
|
2007-02-18 07:21:28 +08:00
|
|
|
{
|
2013-02-05 05:24:00 +08:00
|
|
|
FAR struct task_group_s *group = tcb->cmn.group;
|
2021-03-16 20:13:02 +08:00
|
|
|
#ifndef CONFIG_FDCLONE_DISABLE
|
|
|
|
FAR struct tcb_s *rtcb = this_task();
|
|
|
|
int ret;
|
|
|
|
#endif
|
2013-01-27 04:17:29 +08:00
|
|
|
|
|
|
|
DEBUGASSERT(group);
|
2013-02-05 05:24:00 +08:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2020-04-29 00:17:03 +08:00
|
|
|
DEBUGASSERT((tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) !=
|
|
|
|
TCB_FLAG_TTYPE_PTHREAD);
|
2013-02-05 05:24:00 +08:00
|
|
|
#endif
|
2013-01-27 04:17:29 +08:00
|
|
|
|
|
|
|
/* Initialize file descriptors for the TCB */
|
|
|
|
|
|
|
|
files_initlist(&group->tg_filelist);
|
2009-06-16 03:50:06 +08:00
|
|
|
|
2021-03-16 20:13:02 +08:00
|
|
|
#ifndef CONFIG_FDCLONE_DISABLE
|
|
|
|
DEBUGASSERT(rtcb->group);
|
|
|
|
|
2012-07-15 03:30:31 +08:00
|
|
|
/* Duplicate the parent task's file descriptors */
|
2009-06-16 03:50:06 +08:00
|
|
|
|
2021-03-16 20:13:02 +08:00
|
|
|
ret = files_duplist(&rtcb->group->tg_filelist, &group->tg_filelist);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
2009-06-16 03:50:06 +08:00
|
|
|
|
2012-07-15 03:30:31 +08:00
|
|
|
/* Allocate file/socket streams for the new TCB */
|
2009-06-16 03:50:06 +08:00
|
|
|
|
2020-08-13 18:17:29 +08:00
|
|
|
#ifdef CONFIG_FILE_STREAM
|
2013-01-27 07:49:02 +08:00
|
|
|
return group_setupstreams(tcb);
|
2012-07-15 03:30:31 +08:00
|
|
|
#else
|
|
|
|
return OK;
|
2009-06-16 03:50:06 +08:00
|
|
|
#endif
|
2007-02-18 07:21:28 +08:00
|
|
|
}
|