2013-02-02 20:31:30 +01:00
|
|
|
/****************************************************************************
|
2014-08-09 00:44:08 +02:00
|
|
|
* sched/task/task_spawn.c
|
2013-02-02 20:31:30 +01:00
|
|
|
*
|
2020-03-29 19:57:53 +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.
|
2013-02-02 20:31:30 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <spawn.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2018-01-30 18:07:36 +01:00
|
|
|
#include <nuttx/sched.h>
|
2018-01-31 23:11:54 +01:00
|
|
|
#include <nuttx/kthread.h>
|
2019-08-23 21:20:52 +02:00
|
|
|
#include <nuttx/spawn.h>
|
2018-01-30 18:07:36 +01: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"
|
2014-08-09 00:44:08 +02:00
|
|
|
#include "task/spawn.h"
|
|
|
|
#include "task/task.h"
|
2013-02-02 20:31:30 +01:00
|
|
|
|
2014-09-16 23:37:05 +02:00
|
|
|
#ifndef CONFIG_BUILD_KERNEL
|
2014-09-14 16:22:21 +02:00
|
|
|
|
2013-02-02 20:31:30 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
* Name: nxtask_spawn_exec
|
2013-02-02 20:31:30 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Execute the task from the file system.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* pidp - Upon successful completion, this will return the task ID of the
|
|
|
|
* child task in the variable pointed to by a non-NULL 'pid' argument.|
|
|
|
|
*
|
2018-12-18 14:29:01 +01:00
|
|
|
* name - The name to assign to the child task.
|
|
|
|
*
|
|
|
|
* entry - The child task's entry point (an address in memory)
|
2013-02-02 20:31:30 +01:00
|
|
|
*
|
|
|
|
* attr - If the value of the 'attr' parameter is NULL, the all default
|
|
|
|
* values for the POSIX spawn attributes will be used. Otherwise, the
|
|
|
|
* attributes will be set according to the spawn flags. The
|
|
|
|
* following spawn flags are supported:
|
|
|
|
*
|
|
|
|
* - POSIX_SPAWN_SETSCHEDPARAM: Set new tasks priority to the sched_param
|
|
|
|
* value.
|
|
|
|
* - POSIX_SPAWN_SETSCHEDULER: Set the new tasks scheduler priority to
|
|
|
|
* the sched_policy value.
|
|
|
|
*
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
* NOTE: POSIX_SPAWN_SETSIGMASK is handled in nxtask_spawn_proxy().
|
2013-02-02 20:31:30 +01:00
|
|
|
*
|
|
|
|
* argv - argv[] is the argument list for the new task. argv[] is an
|
|
|
|
* array of pointers to null-terminated strings. The list is terminated
|
|
|
|
* with a null pointer.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* This function will return zero on success. Otherwise, an error number
|
|
|
|
* will be returned as the function return value to indicate the error.
|
|
|
|
* This errno value may be that set by execv(), sched_setpolicy(), or
|
|
|
|
* sched_setparam().
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
static int nxtask_spawn_exec(FAR pid_t *pidp, FAR const char *name,
|
|
|
|
main_t entry, FAR const posix_spawnattr_t *attr,
|
|
|
|
FAR char * const *argv)
|
2013-02-02 20:31:30 +01:00
|
|
|
{
|
2013-05-09 22:23:34 +02:00
|
|
|
size_t stacksize;
|
|
|
|
int priority;
|
2013-02-02 20:31:30 +01:00
|
|
|
int pid;
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
/* Disable pre-emption so that we can modify the task parameters after
|
|
|
|
* we start the new task; the new task will not actually begin execution
|
|
|
|
* until we re-enable pre-emption.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
|
|
|
|
2020-05-02 12:36:48 +02:00
|
|
|
/* Use the default priority and stack size if no attributes are provided */
|
2013-05-09 22:23:34 +02:00
|
|
|
|
|
|
|
if (attr)
|
|
|
|
{
|
|
|
|
priority = attr->priority;
|
|
|
|
stacksize = attr->stacksize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct sched_param param;
|
|
|
|
|
|
|
|
/* Set the default priority to the same priority as this task */
|
|
|
|
|
2018-01-30 18:07:36 +01:00
|
|
|
ret = nxsched_getparam(0, ¶m);
|
2013-05-09 22:23:34 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2018-01-30 18:07:36 +01:00
|
|
|
ret = -ret;
|
2013-05-09 22:23:34 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
priority = param.sched_priority;
|
|
|
|
stacksize = CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE;
|
|
|
|
}
|
|
|
|
|
2013-02-02 20:31:30 +01:00
|
|
|
/* Start the task */
|
|
|
|
|
2018-01-31 23:11:54 +01:00
|
|
|
pid = nxtask_create(name, priority, stacksize, entry, argv);
|
2013-02-02 20:31:30 +01:00
|
|
|
if (pid < 0)
|
|
|
|
{
|
2018-01-31 23:11:54 +01:00
|
|
|
ret = -pid;
|
|
|
|
serr("ERROR: nxtask_create failed: %d\n", ret);
|
2013-02-02 20:31:30 +01:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the task ID to the caller */
|
|
|
|
|
|
|
|
if (pid)
|
|
|
|
{
|
|
|
|
*pidp = pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now set the attributes. Note that we ignore all of the return values
|
|
|
|
* here because we have already successfully started the task. If we
|
|
|
|
* return an error value, then we would also have to stop the task.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (attr)
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
spawn_execattrs(pid, attr);
|
2013-02-02 20:31:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Re-enable pre-emption and return */
|
|
|
|
|
|
|
|
errout:
|
|
|
|
sched_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
* Name: nxtask_spawn_proxy
|
2013-02-02 20:31:30 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform file_actions, then execute the task from the file system.
|
|
|
|
*
|
2013-02-03 00:56:54 +01:00
|
|
|
* Do we really need a proxy task in this case? Isn't that wasteful?
|
|
|
|
*
|
|
|
|
* Q: Why can we do what we need to do here and the just call the
|
|
|
|
* new task's entry point.
|
|
|
|
* A: This would require setting up the name, priority, and stacksize from
|
|
|
|
* the task_spawn, but it do-able. The only issue I can think of is
|
|
|
|
* that NuttX supports task_restart(), and you would never be able to
|
|
|
|
* restart a task from this point.
|
|
|
|
*
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
* Q: Why not use a starthook so that there is callout from nxtask_start()
|
2013-02-03 00:56:54 +01:00
|
|
|
* to perform these operations?
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
* A: Good idea, except that existing nxtask_starthook() implementation
|
2013-02-03 00:56:54 +01:00
|
|
|
* cannot be used here unless we get rid of task_create and, instead,
|
|
|
|
* use task_init() and task_activate(). start_taskhook() could then
|
2019-08-15 22:06:11 +02:00
|
|
|
* be called between task_init() and task_activate(). task_restart()
|
2013-02-03 00:56:54 +01:00
|
|
|
* would still be an issue.
|
|
|
|
*
|
2013-02-02 20:31:30 +01:00
|
|
|
* Input Parameters:
|
|
|
|
* Standard task start-up parameters
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Standard task return value.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
static int nxtask_spawn_proxy(int argc, FAR char *argv[])
|
2013-02-02 20:31:30 +01:00
|
|
|
{
|
2015-10-04 23:04:00 +02:00
|
|
|
int ret;
|
2013-02-02 20:31:30 +01:00
|
|
|
|
|
|
|
/* Perform file actions and/or set a custom signal mask. We get here only
|
|
|
|
* if the file_actions parameter to task_spawn[p] was non-NULL and/or the
|
|
|
|
* option to change the signal mask was selected.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(g_spawn_parms.file_actions ||
|
|
|
|
(g_spawn_parms.attr &&
|
2017-08-15 01:19:27 +02:00
|
|
|
(g_spawn_parms.attr->flags & POSIX_SPAWN_SETSIGMASK) != 0));
|
2013-02-02 20:31:30 +01:00
|
|
|
|
|
|
|
/* Set the attributes and perform the file actions as appropriate */
|
|
|
|
|
|
|
|
ret = spawn_proxyattrs(g_spawn_parms.attr, g_spawn_parms.file_actions);
|
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
/* Start the task */
|
|
|
|
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
ret = nxtask_spawn_exec(g_spawn_parms.pid, g_spawn_parms.u.task.name,
|
|
|
|
g_spawn_parms.u.task.entry, g_spawn_parms.attr,
|
|
|
|
g_spawn_parms.argv);
|
2013-02-02 20:31:30 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
/* Change of the parent of the task we just spawned to our parent.
|
|
|
|
* What should we do in the event of a failure?
|
|
|
|
*/
|
|
|
|
|
|
|
|
int tmp = task_reparent(0, *g_spawn_parms.pid);
|
|
|
|
if (tmp < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
serr("ERROR: task_reparent() failed: %d\n", tmp);
|
2013-02-02 20:31:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Post the semaphore to inform the parent task that we have completed
|
|
|
|
* what we need to do.
|
|
|
|
*/
|
|
|
|
|
|
|
|
g_spawn_parms.result = ret;
|
|
|
|
#ifndef CONFIG_SCHED_WAITPID
|
2013-02-03 19:36:46 +01:00
|
|
|
spawn_semgive(&g_spawn_execsem);
|
2013-02-02 20:31:30 +01:00
|
|
|
#endif
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: task_spawn
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The task_spawn() function will create a new, child task, where the
|
|
|
|
* entry point to the task is an address in memory.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* pid - Upon successful completion, task_spawn() will return the task ID
|
|
|
|
* of the child task to the parent task, in the variable pointed to by
|
|
|
|
* a non-NULL 'pid' argument. If the 'pid' argument is a null pointer,
|
|
|
|
* the process ID of the child is not returned to the caller.
|
|
|
|
*
|
|
|
|
* name - The name to assign to the child task.
|
|
|
|
*
|
|
|
|
* entry - The child task's entry point (an address in memory)
|
|
|
|
*
|
2014-04-13 22:32:20 +02:00
|
|
|
* file_actions - If 'file_actions' is a null pointer, then file
|
2013-02-02 20:31:30 +01:00
|
|
|
* descriptors open in the calling process will remain open in the
|
|
|
|
* child process (unless CONFIG_FDCLONE_STDIO is defined). If
|
|
|
|
* 'file_actions' is not NULL, then the file descriptors open in the
|
|
|
|
* child process will be those open in the calling process as modified
|
|
|
|
* by the spawn file actions object pointed to by file_actions.
|
|
|
|
*
|
|
|
|
* attr - If the value of the 'attr' parameter is NULL, the all default
|
|
|
|
* values for the POSIX spawn attributes will be used. Otherwise, the
|
|
|
|
* attributes will be set according to the spawn flags. The
|
|
|
|
* task_spawnattr_t spawn attributes object type is defined in spawn.h.
|
|
|
|
* It will contains these attributes, not all of which are supported by
|
|
|
|
* NuttX:
|
|
|
|
*
|
|
|
|
* - POSIX_SPAWN_SETPGROUP: Setting of the new task's process group is
|
|
|
|
* not supported. NuttX does not support process groups.
|
|
|
|
* - POSIX_SPAWN_SETSCHEDPARAM: Set new tasks priority to the sched_param
|
|
|
|
* value.
|
|
|
|
* - POSIX_SPAWN_SETSCHEDULER: Set the new task's scheduler policy to
|
|
|
|
* the sched_policy value.
|
2020-03-08 13:43:21 +01:00
|
|
|
* - POSIX_SPAWN_RESETIDS: Resetting of the effective user ID of the
|
|
|
|
* child process is not supported. NuttX does not support effective
|
|
|
|
* user IDs.
|
2013-02-02 20:31:30 +01:00
|
|
|
* - POSIX_SPAWN_SETSIGMASK: Set the new task's signal mask.
|
|
|
|
* - POSIX_SPAWN_SETSIGDEF: Resetting signal default actions is not
|
|
|
|
* supported. NuttX does not support default signal actions.
|
|
|
|
*
|
|
|
|
* And the non-standard:
|
|
|
|
*
|
|
|
|
* - TASK_SPAWN_SETSTACKSIZE: Set the stack size for the new task.
|
|
|
|
*
|
|
|
|
* argv - argv[] is the argument list for the new task. argv[] is an
|
|
|
|
* array of pointers to null-terminated strings. The list is terminated
|
|
|
|
* with a null pointer.
|
|
|
|
*
|
|
|
|
* envp - The envp[] argument is not used by NuttX and may be NULL.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* task_spawn() will return zero on success. Otherwise, an error number
|
|
|
|
* will be returned as the function return value to indicate the error:
|
|
|
|
*
|
|
|
|
* - EINVAL: The value specified by 'file_actions' or 'attr' is invalid.
|
|
|
|
* - Any errors that might have been return if vfork() and excec[l|v]()
|
|
|
|
* had been called.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int task_spawn(FAR pid_t *pid, FAR const char *name, main_t entry,
|
2017-08-15 01:19:27 +02:00
|
|
|
FAR const posix_spawn_file_actions_t *file_actions,
|
|
|
|
FAR const posix_spawnattr_t *attr,
|
2020-05-06 11:24:42 +02:00
|
|
|
FAR char * const argv[], FAR char * const envp[])
|
2013-02-02 20:31:30 +01:00
|
|
|
{
|
|
|
|
struct sched_param param;
|
|
|
|
pid_t proxy;
|
|
|
|
#ifdef CONFIG_SCHED_WAITPID
|
|
|
|
int status;
|
|
|
|
#endif
|
|
|
|
int ret;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
sinfo("pid=%p name=%s entry=%p file_actions=%p attr=%p argv=%p\n",
|
2013-02-03 00:56:54 +01:00
|
|
|
pid, name, entry, file_actions, attr, argv);
|
2013-02-02 20:31:30 +01:00
|
|
|
|
|
|
|
/* If there are no file actions to be performed and there is no change to
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
* the signal mask, then start the new child task directly from the parent
|
|
|
|
* task.
|
2013-02-02 20:31:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
if ((file_actions == NULL || *file_actions == NULL) &&
|
|
|
|
(attr == NULL || (attr->flags & POSIX_SPAWN_SETSIGMASK) == 0))
|
|
|
|
{
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
return nxtask_spawn_exec(pid, name, entry, attr, argv);
|
2013-02-02 20:31:30 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 13:43:21 +01:00
|
|
|
/* Otherwise, we will have to go through an intermediary/proxy task in
|
|
|
|
* order to perform the I/O redirection. This would be a natural place to
|
|
|
|
* fork(). However, true fork() behavior requires an MMU and most
|
|
|
|
* implementations of vfork() are not capable of these operations.
|
2013-02-02 20:31:30 +01:00
|
|
|
*
|
|
|
|
* Even without fork(), we can still do the job, but parameter passing is
|
|
|
|
* messier. Unfortunately, there is no (clean) way to pass binary values
|
|
|
|
* as a task parameter, so we will use a semaphore-protected global
|
|
|
|
* structure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Get exclusive access to the global parameter structure */
|
|
|
|
|
2020-03-29 19:57:53 +02:00
|
|
|
ret = spawn_semtake(&g_spawn_parmsem);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
serr("ERROR: spawn_semtake failed: %d\n", ret);
|
|
|
|
return -ret;
|
|
|
|
}
|
2013-02-02 20:31:30 +01:00
|
|
|
|
|
|
|
/* Populate the parameter structure */
|
|
|
|
|
|
|
|
g_spawn_parms.result = ENOSYS;
|
|
|
|
g_spawn_parms.pid = pid;
|
|
|
|
g_spawn_parms.file_actions = file_actions ? *file_actions : NULL;
|
|
|
|
g_spawn_parms.attr = attr;
|
|
|
|
g_spawn_parms.argv = argv;
|
|
|
|
g_spawn_parms.u.task.name = name;
|
|
|
|
g_spawn_parms.u.task.entry = entry;
|
|
|
|
|
|
|
|
/* Get the priority of this (parent) task */
|
|
|
|
|
2018-01-30 18:07:36 +01:00
|
|
|
ret = nxsched_getparam(0, ¶m);
|
2013-02-02 20:31:30 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2018-01-30 18:07:36 +01:00
|
|
|
serr("ERROR: nxsched_getparam failed: %d\n", ret);
|
2013-02-02 20:31:30 +01:00
|
|
|
spawn_semgive(&g_spawn_parmsem);
|
2018-01-30 18:07:36 +01:00
|
|
|
return -ret;
|
2013-02-02 20:31:30 +01:00
|
|
|
}
|
|
|
|
|
2018-08-17 22:23:38 +02:00
|
|
|
#ifdef CONFIG_SCHED_WAITPID
|
2013-02-03 00:56:54 +01:00
|
|
|
/* Disable pre-emption so that the proxy does not run until waitpid
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
* is called. This is probably unnecessary since the nxtask_spawn_proxy
|
|
|
|
* has the same priority as this thread; it should be schedule behind
|
|
|
|
* this task in the ready-to-run list.
|
2018-08-17 22:23:38 +02:00
|
|
|
*
|
|
|
|
* REVISIT: This will may not have the desired effect in SMP mode.
|
2013-02-02 20:31:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Start the intermediary/proxy task at the same priority as the parent
|
|
|
|
* task.
|
|
|
|
*/
|
|
|
|
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
proxy = nxtask_create("nxtask_spawn_proxy", param.sched_priority,
|
2018-01-31 23:11:54 +01:00
|
|
|
CONFIG_POSIX_SPAWN_PROXY_STACKSIZE,
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
(main_t)nxtask_spawn_proxy,
|
2018-01-31 23:11:54 +01:00
|
|
|
(FAR char * const *)NULL);
|
2013-02-02 20:31:30 +01:00
|
|
|
if (proxy < 0)
|
|
|
|
{
|
2018-01-31 23:11:54 +01:00
|
|
|
ret = -proxy;
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
serr("ERROR: Failed to start nxtask_spawn_proxy: %d\n", ret);
|
2013-02-02 20:31:30 +01:00
|
|
|
goto errout_with_lock;
|
|
|
|
}
|
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
/* Wait for the proxy to complete its job */
|
2013-02-02 20:31:30 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_WAITPID
|
2020-03-29 19:57:53 +02:00
|
|
|
/* REVISIT: This should not call waitpid() directly. waitpid is a
|
|
|
|
* cancellation point and modifies the errno value. It is inappropriate
|
|
|
|
* for use within the OS.
|
|
|
|
*/
|
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
ret = waitpid(proxy, &status, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2020-03-29 19:57:53 +02:00
|
|
|
ret = -get_errno();
|
|
|
|
serr("ERROR: waitpid() failed: %d\n", ret);
|
2015-10-08 03:59:14 +02:00
|
|
|
goto errout_with_lock;
|
|
|
|
}
|
2013-02-02 20:31:30 +01:00
|
|
|
#else
|
2020-03-29 19:57:53 +02:00
|
|
|
ret = spawn_semtake(&g_spawn_execsem);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
serr("ERROR: g_spawn_execsem() failed: %d\n", ret);
|
|
|
|
goto errout_with_lock;
|
|
|
|
}
|
2013-02-02 20:31:30 +01:00
|
|
|
#endif
|
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
/* Get the result and relinquish our access to the parameter structure */
|
2013-02-02 20:31:30 +01:00
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
ret = g_spawn_parms.result;
|
2013-02-02 20:31:30 +01:00
|
|
|
|
|
|
|
errout_with_lock:
|
|
|
|
#ifdef CONFIG_SCHED_WAITPID
|
|
|
|
sched_unlock();
|
|
|
|
#endif
|
|
|
|
spawn_semgive(&g_spawn_parmsem);
|
|
|
|
return ret;
|
|
|
|
}
|
2014-09-14 16:22:21 +02:00
|
|
|
|
2019-08-23 21:20:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nx_task_spawn
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function de-marshals parameters and invokes task_spawn().
|
|
|
|
*
|
|
|
|
* task_spawn() and posix_spawn() are NuttX OS interfaces. In PROTECTED
|
|
|
|
* and KERNEL build modes, then can be reached from applications only via
|
|
|
|
* a system call. Currently, the number of parameters in a system call
|
|
|
|
* is limited to six; these spawn function have seven parameters. Rather
|
|
|
|
* than extend the maximum number of parameters across all architectures,
|
|
|
|
* I opted instead to marshal the seven parameters into a structure.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* parms - The marshaled task_spawn() parameters.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, these functions return 0; on failure they return an error
|
|
|
|
* number from <errno.h> (see the comments associated with task_spawn()).
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-05-02 12:36:48 +02:00
|
|
|
#ifdef CONFIG_LIB_SYSCALL
|
2019-08-23 21:20:52 +02:00
|
|
|
int nx_task_spawn(FAR const struct spawn_syscall_parms_s *parms)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(parms != NULL);
|
|
|
|
return task_spawn(parms->pid, parms->name, parms->entry,
|
|
|
|
parms->file_actions, parms->attr,
|
|
|
|
parms->argv, parms->envp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-09-16 23:37:05 +02:00
|
|
|
#endif /* CONFIG_BUILD_KERNEL */
|