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
|
|
|
*
|
2024-09-11 13:45:11 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
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.
|
|
|
|
*
|
2023-04-26 05:44:08 +02:00
|
|
|
* actions - The spawn file actions
|
|
|
|
*
|
2013-01-10 18:37:29 +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.
|
|
|
|
*
|
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,
|
2023-04-26 05:44:08 +02:00
|
|
|
FAR const posix_spawn_file_actions_t *actions,
|
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
|
|
|
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
|
|
|
/* Start the task */
|
|
|
|
|
2023-04-26 05:44:08 +02:00
|
|
|
pid = exec_spawn(path, argv, envp, symtab, nsymbols, actions, 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);
|
2023-10-25 09:39:17 +02:00
|
|
|
return ret;
|
2013-01-10 18:37:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the task ID to the caller */
|
|
|
|
|
|
|
|
if (pid)
|
|
|
|
{
|
|
|
|
*pidp = pid;
|
|
|
|
}
|
|
|
|
|
2013-01-17 19:32:13 +01:00
|
|
|
return ret;
|
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
|
|
|
{
|
2023-04-26 05:44:08 +02:00
|
|
|
return nxposix_spawn_exec(pid, path,
|
|
|
|
file_actions != NULL ?
|
|
|
|
*file_actions : NULL, attr, argv, envp);
|
2013-01-10 16:26:09 +01:00
|
|
|
}
|