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