From 9f8f8fc6dc5c2057f61fe04bf1109a8590ef93d0 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 10 Jan 2013 18:31:08 +0000 Subject: Add missing support for signal masks to posix_spawn. git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5505 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/TODO | 15 +----- nuttx/include/spawn.h | 18 ++++++- nuttx/libc/spawn/Make.defs | 4 ++ nuttx/libc/spawn/lib_ps.c | 89 ++++++++++++++++++++++------------- nuttx/libc/spawn/lib_psa_getsigmask.c | 78 ++++++++++++++++++++++++++++++ nuttx/libc/spawn/lib_psa_setsigmask.c | 79 +++++++++++++++++++++++++++++++ nuttx/sched/task_setup.c | 4 +- 7 files changed, 238 insertions(+), 49 deletions(-) create mode 100644 nuttx/libc/spawn/lib_psa_getsigmask.c create mode 100644 nuttx/libc/spawn/lib_psa_setsigmask.c (limited to 'nuttx') diff --git a/nuttx/TODO b/nuttx/TODO index c10b101cc..9295f6206 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated January 8, 2013) +NuttX TODO List (Last updated January 10, 2013) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -6,7 +6,7 @@ standards, things that could be improved, and ideas for enhancements. nuttx/ - (12) Task/Scheduler (sched/) + (11) Task/Scheduler (sched/) (1) Memory Managment (mm/) (2) Signals (sched/, arch/) (2) pthreads (sched/) @@ -189,17 +189,6 @@ o Task/Scheduler (sched/) Status: Open Priority: Medium Low for now - Title: INHERITANCE of sigmask - Description: New tasks/threads do not inherit the parent's signal mask. - This behavior is required under POSIX. - - Also, related: Setting of the initial sigmask was not - implemented in posix_spawn (libc/spawn) because of this. - Status: Open - Priority: Low, make medium-low. These kinds of behaviors are not - common in tiny embedded RTOSs. And it has always been - like this and no one has complained so far. - o Memory Managment (mm/) ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/nuttx/include/spawn.h b/nuttx/include/spawn.h index 91092eeb0..3978424fb 100644 --- a/nuttx/include/spawn.h +++ b/nuttx/include/spawn.h @@ -45,6 +45,7 @@ #include #include +#include #include /**************************************************************************** @@ -77,6 +78,9 @@ struct posix_spawnattr_s uint8_t flags; uint8_t priority; uint8_t policy; +#ifndef CONFIG_DISABLE_SIGNALS + sigset_t sigmask; +#endif }; typedef struct posix_spawnattr_s posix_spawnattr_t; @@ -155,7 +159,12 @@ int posix_spawnattr_getschedparam(FAR const posix_spawnattr_t *attr, int posix_spawnattr_getschedpolicy(FAR const posix_spawnattr_t *attr, FAR int *policy); #define posix_spawnattr_getsigdefault(attr,sigdefault) (ENOSYS) -#define posix_spawnattr_getsigmask(attr,sigmask) (ENOSYS) +#ifndef CONFIG_DISABLE_SIGNALS +int posix_spawnattr_getsigmask(FAR const posix_spawnattr_t *attr, + FAR sigset_t *sigmask); +#else +# define posix_spawnattr_getsigmask(attr,sigmask) (ENOSYS) +#endif /* Set spawn attributes interfaces */ @@ -165,7 +174,12 @@ int posix_spawnattr_setschedparam(FAR posix_spawnattr_t *attr, FAR const struct sched_param *param); int posix_spawnattr_setschedpolicy(FAR posix_spawnattr_t *attr, int policy); #define posix_spawnattr_setsigdefault(attr,sigdefault) (ENOSYS) -#define posix_spawnattr_setsigmask(attr,sigmask) (ENOSYS) +#ifndef CONFIG_DISABLE_SIGNALS +int posix_spawnattr_setsigmask(FAR posix_spawnattr_t *attr, + FAR const sigset_t *sigmask); +#else +# define posix_spawnattr_setsigmask(attr,sigmask) (ENOSYS) +#endif #ifdef __cplusplus } diff --git a/nuttx/libc/spawn/Make.defs b/nuttx/libc/spawn/Make.defs index 21bc316fa..2cf75c410 100644 --- a/nuttx/libc/spawn/Make.defs +++ b/nuttx/libc/spawn/Make.defs @@ -46,6 +46,10 @@ CSRCS += lib_psa_getflags.c lib_psa_getschedparam.c lib_psa_getschedpolicy.c CSRCS += lib_psa_init.c lib_psa_setflags.c lib_psa_setschedparam.c CSRCS += lib_psa_setschedpolicy.c +ifneq ($(CONFIG_DISABLE_SIGNALS),y) +CSRCS += lib_psa_getsigmask.c lib_psa_setsigmask.c +endif + # Add the spawn directory to the build DEPPATH += --dep-path spawn diff --git a/nuttx/libc/spawn/lib_ps.c b/nuttx/libc/spawn/lib_ps.c index e73d1eef0..b0f6e1b07 100644 --- a/nuttx/libc/spawn/lib_ps.c +++ b/nuttx/libc/spawn/lib_ps.c @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -137,6 +138,8 @@ static void ps_semtake(FAR sem_t *sem) * - POSIX_SPAWN_SETSCHEDULER: Set the new tasks scheduler priority to * the sched_policy value. * + * NOTE: POSIX_SPAWN_SETSIGMASK is handled in ps_proxy(). + * * 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. @@ -326,38 +329,59 @@ static inline int spawn_open(FAR struct spawn_open_file_action_s *action) static int spawn_proxy(int argc, char *argv[]) { FAR struct spawn_general_file_action_s *entry; + FAR const posix_spawnattr_t *attr = g_ps_parms.attr; int ret; - /* Perform I/O redirection. We get here only if the file_actions parameter - * to posix_spawn[p] was non-NULL. + /* 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. */ +#ifndef CONFIG_DISABLE_SIGNALS + DEBUGASSERT(g_ps_parms.file_actions || + (attr && (attr->flags & POSIX_SPAWN_SETSIGMASK) != 0)); +#else DEBUGASSERT(g_ps_parms.file_actions); +#endif + + /* Check if we need to change the signal mask */ + +#ifndef CONFIG_DISABLE_SIGNALS + if (attr && (attr->flags & POSIX_SPAWN_SETSIGMASK) != 0) + { + (void)sigprocmask(SIG_SETMASK, &attr->sigmask, NULL); + } - /* Execute each file action */ + /* Were we also requested to perform file actions? */ - for (entry = (FAR struct spawn_general_file_action_s *)*g_ps_parms.file_actions; - entry && ret == OK; - entry = entry->flink) + if (g_ps_parms.file_actions) +#endif { - switch (entry->action) + /* Execute each file action */ + + for (entry = (FAR struct spawn_general_file_action_s *)*g_ps_parms.file_actions; + entry && ret == OK; + entry = entry->flink) { - case SPAWN_FILE_ACTION_CLOSE: - ret = spawn_close((FAR struct spawn_close_file_action_s *)entry); - break; - - case SPAWN_FILE_ACTION_DUP2: - ret = spawn_dup2((FAR struct spawn_dup2_file_action_s *)entry); - break; - - case SPAWN_FILE_ACTION_OPEN: - ret = spawn_open((FAR struct spawn_open_file_action_s *)entry); - break; - - case SPAWN_FILE_ACTION_NONE: - default: - ret = EINVAL; - break; + switch (entry->action) + { + case SPAWN_FILE_ACTION_CLOSE: + ret = spawn_close((FAR struct spawn_close_file_action_s *)entry); + break; + + case SPAWN_FILE_ACTION_DUP2: + ret = spawn_dup2((FAR struct spawn_dup2_file_action_s *)entry); + break; + + case SPAWN_FILE_ACTION_OPEN: + ret = spawn_open((FAR struct spawn_open_file_action_s *)entry); + break; + + case SPAWN_FILE_ACTION_NONE: + default: + ret = EINVAL; + break; + } } } @@ -367,8 +391,7 @@ static int spawn_proxy(int argc, char *argv[]) { /* Start the task */ - ret = ps_exec(g_ps_parms.pid, g_ps_parms.path, g_ps_parms.attr, - g_ps_parms.argv); + ret = ps_exec(g_ps_parms.pid, g_ps_parms.path, attr, g_ps_parms.argv); } /* Post the semaphore to inform the parent task that we have completed @@ -424,18 +447,16 @@ static int spawn_proxy(int argc, char *argv[]) * It will contains these attributes, not all of which are supported by * NuttX: * - * - POSIX_SPAWN_SETPGROUP: Setting of the new tasks process group is + * - 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 tasks scheduler priority to + * - POSIX_SPAWN_SETSCHEDULER: Set the new task's scheduler priority to * the sched_policy value. * - POSIX_SPAWN_RESETIDS: Resetting of effective user ID of the child * process is not supported. NuttX does not support effective user * IDs. - * - POSIX_SPAWN_SETSIGMASK: Setting the initial signal mask of the new - * task is not supported. NuttX does support signal masks, but there - * is no mechanism in place now to do this. + * - 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. * @@ -496,11 +517,15 @@ int posix_spawn(FAR pid_t *pid, FAR const char *path, DEBUGASSERT(path); - /* If there are no file actions to be performed, then start the new child - * task directory form the parent task. + /* If there are no file actions to be performed and there is no change to + * the signal mask, then start the new child task directly from the parent task. */ +#ifndef CONFIG_DISABLE_SIGNALS + if (!file_actions && (attr->flags & POSIX_SPAWN_SETSIGMASK) == 0) +#else if (!file_actions) +#endif { return ps_exec(pid, path, attr, argv); } diff --git a/nuttx/libc/spawn/lib_psa_getsigmask.c b/nuttx/libc/spawn/lib_psa_getsigmask.c new file mode 100644 index 000000000..3c831075e --- /dev/null +++ b/nuttx/libc/spawn/lib_psa_getsigmask.c @@ -0,0 +1,78 @@ +/**************************************************************************** + * libc/string/lib_psa_getsigmask.c + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#ifndef CONFIG_DISABLE_SIGNALS + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: posix_spawnattr_getsigmask + * + * Description: + * The posix_spawnattr_getsigdefault() function will obtain the value of + * the spawn-sigmask attribute from the attributes object referenced + * by attr. + * + * Input Parameters: + * attr - The address spawn attributes to be queried. + * sigmask - The location to return the spawn flags + * + * Returned Value: + * On success, these functions return 0; on failure they return an error + * number from . + * + ****************************************************************************/ + +int posix_spawnattr_getsigmask(FAR const posix_spawnattr_t *attr, + FAR sigset_t *sigmask) +{ + DEBUGASSERT(attr && sigmask); + *sigmask = attr->sigmask; + return OK; +} + +#endif /* !CONFIG_DISABLE_SIGNALS */ diff --git a/nuttx/libc/spawn/lib_psa_setsigmask.c b/nuttx/libc/spawn/lib_psa_setsigmask.c new file mode 100644 index 000000000..28b7daf77 --- /dev/null +++ b/nuttx/libc/spawn/lib_psa_setsigmask.c @@ -0,0 +1,79 @@ +/**************************************************************************** + * libc/string/lib_psa_setsigmask.c + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#ifndef CONFIG_DISABLE_SIGNALS + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: posix_spawnattr_setsigmask + * + * Description: + * The posix_spawnattr_setsigmask() function will set the spawn- + * sigmask attribute in an initialized attributes object referenced + * by attr. + * + * Input Parameters: + * attr - The address spawn attributes to be used. + * flags - The new value of the default signal set + * + * Returned Value: + * On success, these functions return 0; on failure they return an error + * number from . + * + ****************************************************************************/ + +int posix_spawnattr_setsigmask(FAR posix_spawnattr_t *attr, + FAR const sigset_t *sigmask) +{ + DEBUGASSERT(attr && sigmask); + attr->sigmask = *sigmask; + return OK; +} + +#endif /* !CONFIG_DISABLE_SIGNALS */ + diff --git a/nuttx/sched/task_setup.c b/nuttx/sched/task_setup.c index a37fb165a..8721b39ec 100644 --- a/nuttx/sched/task_setup.c +++ b/nuttx/sched/task_setup.c @@ -231,8 +231,8 @@ int task_schedsetup(FAR _TCB *tcb, int priority, start_t start, main_t main) tcb->start = start; tcb->entry.main = main; - /* exec() and pthread_create() inherit the signal mask of the - * parent thread. I suppose that task_create() should as well. + /* exec(), pthread_create(), task_create(), and vfork() all + * inherit the signal mask of the parent thread. */ #ifndef CONFIG_DISABLE_SIGNALS -- cgit v1.2.3