1
0
Fork 0
forked from nuttx/nuttx-update

Squashed commit of the following:

Replace all calls to sigprocmask() in the OS proper with calls to nxsig_procmask().

    sched/signal:  Add internal OS interface nxsig_procmask().  This internal interface is equivalent to the standard sigprocmask() used by applications except that it does not modify the errno value.  Also fixes a problem in that the original sigprocmask() was not setting the errno.
This commit is contained in:
Gregory Nutt 2017-10-07 12:16:10 -06:00
parent 4810499d3a
commit d633c9bf8c
8 changed files with 138 additions and 42 deletions

View file

@ -45,6 +45,7 @@
#include <nuttx/irq.h>
#include <nuttx/kmalloc.h>
#include <nuttx/signal.h>
#include <nuttx/binfmt/binfmt.h>
#include "binfmt.h"
@ -100,10 +101,10 @@ static void unload_list_add(pid_t pid, FAR struct binary_s *bin)
bin->pid = pid;
/* Disable deliver of any signals while we muck with the list. The graceful
* way to do this would be block delivery of SIGCHLD would be with
* sigprocmask. Here we do it the quick'n'dirty way by just disabling
* interrupts.
/* Disable deliver of any signals while we muck with the list. The
* graceful way to do this would be block delivery of SIGCHLD would be
* with nxsig_procmask. Here we do it the quick'n'dirty way by just
* disabling interrupts.
*/
flags = enter_critical_section();
@ -277,13 +278,10 @@ int schedule_unload(pid_t pid, FAR struct binary_s *bin)
(void)sigemptyset(&set);
(void)sigaddset(&set, SIGCHLD);
ret = sigprocmask(SIG_UNBLOCK, &set, NULL);
if (ret != OK)
ret = nxsig_procmask(SIG_UNBLOCK, &set, NULL);
if (ret < 0)
{
/* The errno value will get trashed by the following debug output */
ret = -get_errno();
berr("ERROR: sigprocmask failed: %d\n", ret);
berr("ERROR: nxsig_procmask failed: %d\n", ret);
return ret;
}

View file

@ -51,6 +51,48 @@
struct timespec; /* Forward reference */
/****************************************************************************
* Name: nxsig_procmask
*
* Description:
* This function allows the calling process to examine and/or change its
* signal mask. If the 'set' is not NULL, then it points to a set of
* signals to be used to change the currently blocked set. The value of
* 'how' indicates the manner in which the set is changed.
*
* If there any pending unblocked signals after the call to
* nxsig_procmask(), those signals will be delivered before
* nxsig_procmask() returns.
*
* If nxsig_procmask() fails, the signal mask of the process is not changed
* by this function call.
*
* This is an internal OS interface. It is functionally equivalent to
* sigprocmask() except that it does not modify the errno value.
*
* Parameters:
* how - How the signal mast will be changed:
* SIG_BLOCK - The resulting set is the union of the current set
* and the signal set pointed to by 'set'.
* SIG_UNBLOCK - The resulting set is the intersection of the current
* set and the complement of the signal set pointed to
* by 'set'.
* SIG_SETMASK - The resulting set is the signal set pointed to by
* 'set'.
* set - Location of the new signal mask
* oset - Location to store the old signal mask
*
* Return Value:
* This is an internal OS interface and should not be used by applications.
* It follows the NuttX internal error return policy: Zero (OK) is
* returned on success. A negated errno value is returned on failure.
*
* EINVAL - The 'how' argument is invalid.
*
****************************************************************************/
int nxsig_procmask(int how, FAR const sigset_t *set, FAR sigset_t *oset);
/****************************************************************************
* Name: nxsig_queue
*

View file

@ -1,7 +1,7 @@
/****************************************************************************
* sched/pthread/pthread_exit.c
*
* Copyright (C) 2007, 2009, 2011-2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2011-2013, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -48,6 +48,7 @@
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/signal.h>
#include "sched/sched.h"
#include "task/task.h"
@ -90,7 +91,7 @@ void pthread_exit(FAR void *exit_value)
#ifndef CONFIG_DISABLE_SIGNALS
{
sigset_t set = ALL_SIGNAL_SET;
(void)sigprocmask(SIG_SETMASK, &set, NULL);
(void)nxsig_procmask(SIG_SETMASK, &set, NULL);
}
#endif

View file

@ -1,7 +1,7 @@
/****************************************************************************
* sched/pthread/pthread_sigmask.c
*
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -52,8 +52,8 @@
* Name: pthread_sigmask
*
* Description:
* This function is a simple wrapper around sigprocmask().
* See the sigprocmask() function description for further
* This function is a simple wrapper around nxsig_procmask().
* See the nxsig_procmask() function description for further
* information.
*
* Parameters:
@ -70,19 +70,13 @@
* oset - Location to store the old signal mask
*
* Return Value:
* 0 (OK) or EINVAL if how is invalid.
*
* Assumptions:
* On success, this function will return 0 (OK). It will return EINVAL if
* how is invalid.
*
****************************************************************************/
int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
{
int ret = sigprocmask(how, set, oset);
if (ret != OK)
{
ret = EINVAL;
}
return ret;
int ret = nxsig_procmask(how, set, oset);
return ret < 0 ? -ret : OK;
}

View file

@ -1,7 +1,8 @@
/****************************************************************************
* sched/signal/sig_mqnotempty.c
*
* Copyright (C) 2007-2009, 2013, 2015, 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2013, 2015, 2017 Gregory Nutt. All rights
* reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without

View file

@ -1,7 +1,8 @@
/****************************************************************************
* sched/signal/sig_procmask.c
*
* Copyright (C) 2007-2009, 2014, 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2014, 2016-2017 Gregory Nutt. All rights
* reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -42,14 +43,16 @@
#include <unistd.h>
#include <signal.h>
#include <time.h>
#include <assert.h>
#include <debug.h>
#include <sched.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/wdog.h>
#include <nuttx/kmalloc.h>
#include <nuttx/signal.h>
#include "sched/sched.h"
#include "signal/signal.h"
@ -59,7 +62,7 @@
****************************************************************************/
/****************************************************************************
* Name: sigprocmask
* Name: nxsig_procmask
*
* Description:
* This function allows the calling process to examine and/or change its
@ -67,12 +70,16 @@
* signals to be used to change the currently blocked set. The value of
* 'how' indicates the manner in which the set is changed.
*
* If there any pending unblocked signals after the call to sigprocmask(),
* those signals will be delivered before sigprocmask() returns.
* If there any pending unblocked signals after the call to
* nxsig_procmask(), those signals will be delivered before
* nxsig_procmask() returns.
*
* If sigprocmask() fails, the signal mask of the process is not changed
* If nxsig_procmask() fails, the signal mask of the process is not changed
* by this function call.
*
* This is an internal OS interface. It is functionally equivalent to
* sigprocmask() except that it does not modify the errno value.
*
* Parameters:
* how - How the signal mast will be changed:
* SIG_BLOCK - The resulting set is the union of the current set
@ -86,13 +93,15 @@
* oset - Location to store the old signal mask
*
* Return Value:
* 0 (OK), or -1 (ERROR) if how is invalid.
* This is an internal OS interface and should not be used by applications.
* It follows the NuttX internal error return policy: Zero (OK) is
* returned on success. A negated errno value is returned on failure.
*
* Assumptions:
* EINVAL - The 'how' argument is invalid.
*
****************************************************************************/
int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
int nxsig_procmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
{
FAR struct tcb_s *rtcb = this_task();
sigset_t oldsigprocmask;
@ -111,7 +120,7 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
/* Modify the current signal mask if so requested */
if (set)
if (set != NULL)
{
/* Some of these operations are non-atomic. We need to protect
* ourselves from attempts to process signals from interrupts
@ -146,7 +155,7 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
break;
default:
ret = ERROR;
ret = -EINVAL;
break;
}
@ -160,3 +169,52 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
sched_unlock();
return ret;
}
/****************************************************************************
* Name: sigprocmask
*
* Description:
* This function allows the calling process to examine and/or change its
* signal mask. If the 'set' is not NULL, then it points to a set of
* signals to be used to change the currently blocked set. The value of
* 'how' indicates the manner in which the set is changed.
*
* If there any pending unblocked signals after the call to sigprocmask(),
* those signals will be delivered before sigprocmask() returns.
*
* If sigprocmask() fails, the signal mask of the process is not changed
* by this function call.
*
* Parameters:
* how - How the signal mast will be changed:
* SIG_BLOCK - The resulting set is the union of the current set
* and the signal set pointed to by 'set'.
* SIG_UNBLOCK - The resulting set is the intersection of the current
* set and the complement of the signal set pointed to
* by 'set'.
* SIG_SETMASK - The resulting set is the signal set pointed to by
* 'set'.
* set - Location of the new signal mask
* oset - Location to store the old signal mask
*
* Return Value:
* This function will return 0 (OK) on success or -1 (ERROR) if how is
* invalid. In the latter case, the errno variable will be set to EINVAL.
*
****************************************************************************/
int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
{
int ret;
/* Let nxsig_procmask do all of the work */
ret = nxsig_procmask(how, set, oset);
if (ret < 0)
{
set_errno(-ret);
ret = ERROR;
}
return ret;
}

View file

@ -1,7 +1,7 @@
/****************************************************************************
* sched/task/task_setup.c
*
* Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2014, 2016-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -47,6 +47,7 @@
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/signal.h>
#include "sched/sched.h"
#include "pthread/pthread.h"
@ -406,7 +407,7 @@ static int thread_schedsetup(FAR struct tcb_s *tcb, int priority,
* inherit the signal mask of the parent thread.
*/
(void)sigprocmask(SIG_SETMASK, NULL, &tcb->sigprocmask);
(void)nxsig_procmask(SIG_SETMASK, NULL, &tcb->sigprocmask);
#endif
/* Initialize the task state. It does not get a valid state

View file

@ -1,7 +1,7 @@
/****************************************************************************
* sched/task/task_spawnparms.c
*
* Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2013, 2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -44,6 +44,7 @@
#include <spawn.h>
#include <debug.h>
#include <nuttx/signal.h>
#include <nuttx/spawn.h>
#include "task/spawn.h"
@ -317,7 +318,7 @@ int spawn_proxyattrs(FAR const posix_spawnattr_t *attr,
#ifndef CONFIG_DISABLE_SIGNALS
if (attr && (attr->flags & POSIX_SPAWN_SETSIGMASK) != 0)
{
(void)sigprocmask(SIG_SETMASK, &attr->sigmask, NULL);
(void)nxsig_procmask(SIG_SETMASK, &attr->sigmask, NULL);
}
/* Were we also requested to perform file actions? */