diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-01-10 18:31:08 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-01-10 18:31:08 +0000 |
commit | 9f8f8fc6dc5c2057f61fe04bf1109a8590ef93d0 (patch) | |
tree | 1bbfd8be66b396406a12040a2f08368f6903f24d /nuttx/libc | |
parent | 322e9d18c7371f9fb27cd57ca894191d564b75c3 (diff) | |
download | px4-firmware-9f8f8fc6dc5c2057f61fe04bf1109a8590ef93d0.tar.gz px4-firmware-9f8f8fc6dc5c2057f61fe04bf1109a8590ef93d0.tar.bz2 px4-firmware-9f8f8fc6dc5c2057f61fe04bf1109a8590ef93d0.zip |
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
Diffstat (limited to 'nuttx/libc')
-rw-r--r-- | nuttx/libc/spawn/Make.defs | 4 | ||||
-rw-r--r-- | nuttx/libc/spawn/lib_ps.c | 89 | ||||
-rw-r--r-- | nuttx/libc/spawn/lib_psa_getsigmask.c | 78 | ||||
-rw-r--r-- | nuttx/libc/spawn/lib_psa_setsigmask.c | 79 |
4 files changed, 218 insertions, 32 deletions
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 <nuttx/config.h> #include <semaphore.h> +#include <signal.h> #include <sched.h> #include <fcntl.h> #include <spawn.h> @@ -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 <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <signal.h> +#include <spawn.h> +#include <assert.h> + +#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 <errno.h>. + * + ****************************************************************************/ + +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 <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <signal.h> +#include <spawn.h> +#include <assert.h> + +#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 <errno.h>. + * + ****************************************************************************/ + +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 */ + |