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