2013-01-10 16:26:09 +01:00
|
|
|
/****************************************************************************
|
2014-08-09 00:44:08 +02:00
|
|
|
* sched/task/task_posixspawn.c
|
2013-01-10 16:26:09 +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-01-10 16:26:09 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2013-01-17 21:25:32 +01:00
|
|
|
#include <sys/wait.h>
|
2013-01-10 16:26:09 +01:00
|
|
|
#include <spawn.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2013-01-10 18:37:29 +01:00
|
|
|
#include <debug.h>
|
2021-05-14 04:29:48 +02:00
|
|
|
#include <errno.h>
|
2013-01-10 18:37:29 +01:00
|
|
|
|
2018-01-30 18:07:36 +01:00
|
|
|
#include <nuttx/sched.h>
|
2014-09-14 16:20:40 +02:00
|
|
|
#include <nuttx/kthread.h>
|
2013-01-10 18:37:29 +01:00
|
|
|
#include <nuttx/binfmt/binfmt.h>
|
2014-09-15 18:16:20 +02:00
|
|
|
#include <nuttx/binfmt/symtab.h>
|
2013-01-10 18:37:29 +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-01-10 18:37:29 +01:00
|
|
|
|
2013-01-10 16:26:09 +01:00
|
|
|
/****************************************************************************
|
2013-01-10 18:37:29 +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: nxposix_spawn_exec
|
2013-01-10 18:37:29 +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.|
|
|
|
|
*
|
|
|
|
* path - The 'path' argument identifies the file to execute. If
|
2021-08-01 09:27:08 +02:00
|
|
|
* CONFIG_LIBC_ENVPATH is defined, this may be either a relative or
|
2013-01-10 18:37:29 +01:00
|
|
|
* or an absolute path. Otherwise, it must be an absolute path.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2013-01-10 19:31:08 +01:00
|
|
|
* NOTE: POSIX_SPAWN_SETSIGMASK is handled in ps_proxy().
|
|
|
|
*
|
2013-01-10 18:37:29 +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 nxposix_spawn_exec(FAR pid_t *pidp, FAR const char *path,
|
|
|
|
FAR const posix_spawnattr_t *attr,
|
2022-04-04 12:11:06 +02:00
|
|
|
FAR char * const argv[],
|
|
|
|
FAR char * const envp[])
|
2013-01-10 18:37:29 +01:00
|
|
|
{
|
2013-01-14 16:42:03 +01:00
|
|
|
FAR const struct symtab_s *symtab;
|
2013-01-10 21:00:08 +01:00
|
|
|
int nsymbols;
|
2013-01-10 18:37:29 +01:00
|
|
|
int pid;
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
DEBUGASSERT(path);
|
|
|
|
|
2013-01-10 21:00:08 +01:00
|
|
|
/* Get the current symbol table selection */
|
|
|
|
|
|
|
|
exec_getsymtab(&symtab, &nsymbols);
|
|
|
|
|
2013-01-10 18:37:29 +01:00
|
|
|
/* 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();
|
|
|
|
|
|
|
|
/* Start the task */
|
|
|
|
|
2022-04-04 12:11:06 +02:00
|
|
|
pid = exec_spawn(path, argv, envp, symtab, nsymbols, attr);
|
2013-01-10 18:37:29 +01:00
|
|
|
if (pid < 0)
|
|
|
|
{
|
2020-05-03 13:33:42 +02:00
|
|
|
ret = -pid;
|
2016-06-11 23:50:49 +02:00
|
|
|
serr("ERROR: exec failed: %d\n", ret);
|
2013-01-10 18:37:29 +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-01-10 18:37:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Re-enable pre-emption and return */
|
|
|
|
|
|
|
|
errout:
|
|
|
|
sched_unlock();
|
2013-01-17 19:32:13 +01:00
|
|
|
return ret;
|
2013-01-10 18:37:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
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: nxposix_spawn_proxy
|
2013-01-10 18:37:29 +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 this proxy task? Isn't that wasteful?
|
|
|
|
*
|
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 after the file is loaded from
|
|
|
|
* the file system?
|
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: That existing nxtask_starthook() implementation cannot be used in
|
|
|
|
* this context; any of nxtask_starthook() will also conflict with
|
2013-02-03 00:56:54 +01:00
|
|
|
* binfmt's use of the start hook to call C++ static initializers.
|
|
|
|
* task_restart() would also be an issue.
|
|
|
|
*
|
2013-01-10 18:37:29 +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 nxposix_spawn_proxy(int argc, FAR char *argv[])
|
2013-01-10 18:37:29 +01:00
|
|
|
{
|
2013-02-02 20:31:30 +01:00
|
|
|
int ret;
|
2013-01-10 18:37:29 +01:00
|
|
|
|
2013-01-10 19:31:08 +01:00
|
|
|
/* Perform file actions and/or set a custom signal mask. We get here only
|
|
|
|
* if the file_actions parameter to posix_spawn[p] was non-NULL and/or the
|
|
|
|
* option to change the signal mask was selected.
|
2013-01-10 18:37:29 +01:00
|
|
|
*/
|
|
|
|
|
2013-02-02 20:31:30 +01:00
|
|
|
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-01-10 19:31:08 +01:00
|
|
|
|
2013-02-02 20:31:30 +01:00
|
|
|
/* Set the attributes and perform the file actions as appropriate */
|
2013-01-10 18:37:29 +01:00
|
|
|
|
2013-02-02 20:31:30 +01:00
|
|
|
ret = spawn_proxyattrs(g_spawn_parms.attr, g_spawn_parms.file_actions);
|
2013-01-10 18:37:29 +01:00
|
|
|
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 = nxposix_spawn_exec(g_spawn_parms.pid, g_spawn_parms.u.posix.path,
|
2022-04-04 12:11:06 +02:00
|
|
|
g_spawn_parms.attr, g_spawn_parms.argv,
|
|
|
|
g_spawn_parms.envp);
|
2013-01-18 02:52:42 +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?
|
|
|
|
*/
|
|
|
|
|
2013-02-02 20:31:30 +01:00
|
|
|
int tmp = task_reparent(0, *g_spawn_parms.pid);
|
2013-01-18 02:52:42 +01:00
|
|
|
if (tmp < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
serr("ERROR: task_reparent() failed: %d\n", tmp);
|
2013-01-18 02:52:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2013-01-10 18:37:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Post the semaphore to inform the parent task that we have completed
|
|
|
|
* what we need to do.
|
|
|
|
*/
|
|
|
|
|
2013-02-02 20:31:30 +01:00
|
|
|
g_spawn_parms.result = ret;
|
2013-01-17 21:25:32 +01:00
|
|
|
#ifndef CONFIG_SCHED_WAITPID
|
2013-02-03 19:36:46 +01:00
|
|
|
spawn_semgive(&g_spawn_execsem);
|
2013-01-17 21:25:32 +01:00
|
|
|
#endif
|
2013-01-18 02:52:42 +01:00
|
|
|
return OK;
|
2013-01-10 18:37:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
2013-01-10 16:26:09 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: posix_spawn
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The posix_spawn() and posix_spawnp() functions will create a new,
|
2013-01-11 22:51:54 +01:00
|
|
|
* child task, constructed from a regular executable file.
|
2013-01-10 16:26:09 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* pid - Upon successful completion, posix_spawn() and posix_spawnp() 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.
|
|
|
|
*
|
|
|
|
* path - The 'path' argument to posix_spawn() is the absolute path that
|
|
|
|
* identifies the file to execute. The 'path' argument to posix_spawnp()
|
|
|
|
* may also be a relative path and will be used to construct a pathname
|
|
|
|
* that identifies the file to execute. In the case of a relative path,
|
|
|
|
* the path prefix for the file will be obtained by a search of the
|
|
|
|
* directories passed as the environment variable PATH.
|
|
|
|
*
|
|
|
|
* NOTE: NuttX provides only one implementation: If
|
2021-08-01 09:27:08 +02:00
|
|
|
* CONFIG_LIBC_ENVPATH is defined, then only posix_spawnp() behavior
|
2013-01-10 16:26:09 +01:00
|
|
|
* is supported; otherwise, only posix_spawn behavior is supported.
|
|
|
|
*
|
2014-04-13 22:32:20 +02:00
|
|
|
* file_actions - If 'file_actions' is a null pointer, then file
|
2013-01-10 16:26:09 +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
|
|
|
|
* posix_spawnattr_t spawn attributes object type is defined in spawn.h.
|
|
|
|
* It will contains these attributes, not all of which are supported by
|
|
|
|
* NuttX:
|
|
|
|
*
|
2013-01-10 19:31:08 +01:00
|
|
|
* - POSIX_SPAWN_SETPGROUP: Setting of the new task's process group is
|
2013-01-10 16:26:09 +01:00
|
|
|
* not supported. NuttX does not support process groups.
|
|
|
|
* - POSIX_SPAWN_SETSCHEDPARAM: Set new tasks priority to the sched_param
|
|
|
|
* value.
|
2013-01-11 22:51:54 +01:00
|
|
|
* - POSIX_SPAWN_SETSCHEDULER: Set the new task's scheduler policy to
|
2013-01-10 16:26:09 +01:00
|
|
|
* the sched_policy value.
|
2020-03-08 13:51:34 +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-01-10 19:31:08 +01:00
|
|
|
* - POSIX_SPAWN_SETSIGMASK: Set the new task's signal mask.
|
2013-01-10 16:26:09 +01:00
|
|
|
* - POSIX_SPAWN_SETSIGDEF: Resetting signal default actions is not
|
|
|
|
* supported. NuttX does not support default signal actions.
|
|
|
|
*
|
|
|
|
* argv - argv[] is the argument list for the new task. argv[] is an
|
|
|
|
* array of pointers to null-terminated strings. The list is terminated
|
2013-01-10 18:37:29 +01:00
|
|
|
* with a null pointer.
|
2013-01-10 16:26:09 +01:00
|
|
|
*
|
2022-04-20 15:45:45 +02:00
|
|
|
* envp - envp[] is an array of character pointers to null-terminated
|
|
|
|
* strings that provide the environment for the new process image.
|
2013-01-10 16:26:09 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* posix_spawn() and posix_spawnp() 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.
|
|
|
|
*
|
|
|
|
* Assumptions/Limitations:
|
|
|
|
* - NuttX provides only posix_spawn() or posix_spawnp() behavior
|
2021-08-01 09:27:08 +02:00
|
|
|
* depending upon the setting of CONFIG_LIBC_ENVPATH: If
|
|
|
|
* CONFIG_LIBC_ENVPATH is defined, then only posix_spawnp() behavior
|
2013-01-10 16:26:09 +01:00
|
|
|
* is supported; otherwise, only posix_spawn behavior is supported.
|
|
|
|
* - Process groups are not supported (POSIX_SPAWN_SETPGROUP).
|
|
|
|
* - Effective user IDs are not supported (POSIX_SPAWN_RESETIDS).
|
2013-01-11 22:51:54 +01:00
|
|
|
* - Signal default actions cannot be modified in the newly task executed
|
|
|
|
* because NuttX does not support default signal actions
|
|
|
|
* (POSIX_SPAWN_SETSIGDEF).
|
2013-01-10 16:26:09 +01:00
|
|
|
*
|
|
|
|
* POSIX Compatibility
|
|
|
|
* - The value of the argv[0] received by the child task is assigned by
|
|
|
|
* NuttX. For the caller of posix_spawn(), the provided argv[0] will
|
|
|
|
* correspond to argv[1] received by the new task.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int posix_spawn(FAR pid_t *pid, FAR const char *path,
|
|
|
|
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-01-10 16:26:09 +01:00
|
|
|
{
|
2013-01-10 18:37:29 +01:00
|
|
|
struct sched_param param;
|
2022-03-21 23:47:09 +01:00
|
|
|
int proxy;
|
2013-01-17 21:25:32 +01:00
|
|
|
#ifdef CONFIG_SCHED_WAITPID
|
|
|
|
int status;
|
|
|
|
#endif
|
2013-01-10 18:37:29 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
DEBUGASSERT(path);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
sinfo("pid=%p path=%s file_actions=%p attr=%p argv=%p\n",
|
2013-01-10 21:00:08 +01:00
|
|
|
pid, path, file_actions, attr, argv);
|
|
|
|
|
2013-01-10 19:31:08 +01:00
|
|
|
/* If there are no file actions to be performed and there is no change to
|
2018-01-27 16:37:46 +01:00
|
|
|
* the signal mask, then start the new child task directly from the parent
|
|
|
|
* task.
|
2013-01-10 18:37:29 +01:00
|
|
|
*/
|
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
if ((file_actions == NULL || *file_actions == NULL) &&
|
|
|
|
(attr == NULL || (attr->flags & POSIX_SPAWN_SETSIGMASK) == 0))
|
2013-01-10 18:37:29 +01:00
|
|
|
{
|
2022-04-04 12:11:06 +02:00
|
|
|
return nxposix_spawn_exec(pid, path, attr, argv, envp);
|
2013-01-10 18:37:29 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 13:51:34 +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-01-10 18:37:29 +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-01-10 18:37:29 +01:00
|
|
|
|
|
|
|
/* Populate the parameter structure */
|
|
|
|
|
2013-02-02 20:31:30 +01:00
|
|
|
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;
|
2022-04-04 12:11:06 +02:00
|
|
|
g_spawn_parms.envp = envp;
|
2013-02-02 20:31:30 +01:00
|
|
|
g_spawn_parms.u.posix.path = path;
|
2013-01-10 18:37:29 +01:00
|
|
|
|
|
|
|
/* Get the priority of this (parent) task */
|
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
ret = nxsched_get_param(0, ¶m);
|
2013-01-10 18:37:29 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2020-05-09 16:04:45 +02:00
|
|
|
serr("ERROR: nxsched_get_param 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-01-10 18:37:29 +01:00
|
|
|
}
|
|
|
|
|
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 nxposix_spawn_proxy
|
|
|
|
* has the same priority as this thread; it should be schedule behind
|
|
|
|
* this task in the ready-to-run list.
|
2013-01-18 02:52:42 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_WAITPID
|
|
|
|
sched_lock();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Start the intermediary/proxy task at the same priority as the parent
|
|
|
|
* task.
|
|
|
|
*/
|
2013-01-10 18:37:29 +01:00
|
|
|
|
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 = kthread_create("nxposix_spawn_proxy", param.sched_priority,
|
2017-10-16 19:38:00 +02: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)nxposix_spawn_proxy,
|
2017-10-16 19:38:00 +02:00
|
|
|
(FAR char * const *)NULL);
|
2013-01-10 18:37:29 +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 nxposix_spawn_proxy: %d\n", ret);
|
2013-01-18 02:52:42 +01:00
|
|
|
goto errout_with_lock;
|
2013-01-10 18:37:29 +01:00
|
|
|
}
|
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
/* Wait for the proxy to complete its job */
|
2013-01-10 18:37:29 +01:00
|
|
|
|
2013-01-17 21:25:32 +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.
|
|
|
|
*/
|
|
|
|
|
2022-03-21 23:47:09 +01:00
|
|
|
ret = nx_waitpid((pid_t)proxy, &status, 0);
|
2015-10-08 03:59:14 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2020-03-29 19:57:53 +02:00
|
|
|
serr("ERROR: waitpid() failed: %d\n", ret);
|
2015-10-08 03:59:14 +02:00
|
|
|
goto errout_with_lock;
|
|
|
|
}
|
2013-01-17 21:25:32 +01:00
|
|
|
#else
|
2020-03-29 19:57:53 +02:00
|
|
|
ret = spawn_semtake(&g_spawn_execsem);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
serr("ERROR: spawn_semtake() failed: %d\n", ret);
|
|
|
|
goto errout_with_lock;
|
|
|
|
}
|
2013-01-17 21:25:32 +01:00
|
|
|
#endif
|
2013-01-10 18:37:29 +01:00
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
/* Get the result and relinquish our access to the parameter structure */
|
2013-01-10 18:37:29 +01:00
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
ret = g_spawn_parms.result;
|
2013-01-18 02:52:42 +01:00
|
|
|
|
|
|
|
errout_with_lock:
|
|
|
|
#ifdef CONFIG_SCHED_WAITPID
|
|
|
|
sched_unlock();
|
|
|
|
#endif
|
2013-02-02 20:31:30 +01:00
|
|
|
spawn_semgive(&g_spawn_parmsem);
|
2013-01-18 02:52:42 +01:00
|
|
|
return ret;
|
2013-01-10 16:26:09 +01:00
|
|
|
}
|