1
0
Fork 0
forked from nuttx/nuttx-update

Add missing support for signal masks to posix_spawn.

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5505 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2013-01-10 18:31:08 +00:00
parent f6485fe177
commit b7369de8e4
7 changed files with 235 additions and 46 deletions

15
TODO
View file

@ -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/)
^^^^^^^^^^^^^^^^^^^^^^

View file

@ -45,6 +45,7 @@
#include <sys/types.h>
#include <sched.h>
#include <signal.h>
#include <errno.h>
/****************************************************************************
@ -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
}

View file

@ -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

View file

@ -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
/* Execute each file action */
/* Check if we need to change the signal mask */
for (entry = (FAR struct spawn_general_file_action_s *)*g_ps_parms.file_actions;
entry && ret == OK;
entry = entry->flink)
#ifndef CONFIG_DISABLE_SIGNALS
if (attr && (attr->flags & POSIX_SPAWN_SETSIGMASK) != 0)
{
switch (entry->action)
(void)sigprocmask(SIG_SETMASK, &attr->sigmask, NULL);
}
/* Were we also requested to perform file actions? */
if (g_ps_parms.file_actions)
#endif
{
/* 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;
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_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_OPEN:
ret = spawn_open((FAR struct spawn_open_file_action_s *)entry);
break;
case SPAWN_FILE_ACTION_NONE:
default:
ret = EINVAL;
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);
}

View file

@ -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 */

View file

@ -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 */

View file

@ -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