mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
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:
@@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
#include <nuttx/irq.h>
|
#include <nuttx/irq.h>
|
||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
|
#include <nuttx/signal.h>
|
||||||
#include <nuttx/binfmt/binfmt.h>
|
#include <nuttx/binfmt/binfmt.h>
|
||||||
|
|
||||||
#include "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;
|
bin->pid = pid;
|
||||||
|
|
||||||
/* Disable deliver of any signals while we muck with the list. The graceful
|
/* Disable deliver of any signals while we muck with the list. The
|
||||||
* way to do this would be block delivery of SIGCHLD would be with
|
* graceful way to do this would be block delivery of SIGCHLD would be
|
||||||
* sigprocmask. Here we do it the quick'n'dirty way by just disabling
|
* with nxsig_procmask. Here we do it the quick'n'dirty way by just
|
||||||
* interrupts.
|
* disabling interrupts.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = enter_critical_section();
|
||||||
@@ -277,13 +278,10 @@ int schedule_unload(pid_t pid, FAR struct binary_s *bin)
|
|||||||
|
|
||||||
(void)sigemptyset(&set);
|
(void)sigemptyset(&set);
|
||||||
(void)sigaddset(&set, SIGCHLD);
|
(void)sigaddset(&set, SIGCHLD);
|
||||||
ret = sigprocmask(SIG_UNBLOCK, &set, NULL);
|
ret = nxsig_procmask(SIG_UNBLOCK, &set, NULL);
|
||||||
if (ret != OK)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
/* The errno value will get trashed by the following debug output */
|
berr("ERROR: nxsig_procmask failed: %d\n", ret);
|
||||||
|
|
||||||
ret = -get_errno();
|
|
||||||
berr("ERROR: sigprocmask failed: %d\n", ret);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,48 @@
|
|||||||
|
|
||||||
struct timespec; /* Forward reference */
|
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
|
* Name: nxsig_queue
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sched/pthread/pthread_exit.c
|
* 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>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -48,6 +48,7 @@
|
|||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/signal.h>
|
||||||
|
|
||||||
#include "sched/sched.h"
|
#include "sched/sched.h"
|
||||||
#include "task/task.h"
|
#include "task/task.h"
|
||||||
@@ -90,7 +91,7 @@ void pthread_exit(FAR void *exit_value)
|
|||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
#ifndef CONFIG_DISABLE_SIGNALS
|
||||||
{
|
{
|
||||||
sigset_t set = ALL_SIGNAL_SET;
|
sigset_t set = ALL_SIGNAL_SET;
|
||||||
(void)sigprocmask(SIG_SETMASK, &set, NULL);
|
(void)nxsig_procmask(SIG_SETMASK, &set, NULL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sched/pthread/pthread_sigmask.c
|
* 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>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -52,8 +52,8 @@
|
|||||||
* Name: pthread_sigmask
|
* Name: pthread_sigmask
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function is a simple wrapper around sigprocmask().
|
* This function is a simple wrapper around nxsig_procmask().
|
||||||
* See the sigprocmask() function description for further
|
* See the nxsig_procmask() function description for further
|
||||||
* information.
|
* information.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
@@ -70,19 +70,13 @@
|
|||||||
* oset - Location to store the old signal mask
|
* oset - Location to store the old signal mask
|
||||||
*
|
*
|
||||||
* Return Value:
|
* Return Value:
|
||||||
* 0 (OK) or EINVAL if how is invalid.
|
* On success, this function will return 0 (OK). It will return EINVAL if
|
||||||
*
|
* how is invalid.
|
||||||
* Assumptions:
|
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
|
int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
|
||||||
{
|
{
|
||||||
int ret = sigprocmask(how, set, oset);
|
int ret = nxsig_procmask(how, set, oset);
|
||||||
if (ret != OK)
|
return ret < 0 ? -ret : OK;
|
||||||
{
|
|
||||||
ret = EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sched/signal/sig_mqnotempty.c
|
* 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>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
+70
-12
@@ -1,7 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sched/signal/sig_procmask.c
|
* 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>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -42,14 +43,16 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <debug.h>
|
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
#include <nuttx/irq.h>
|
#include <nuttx/irq.h>
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/wdog.h>
|
#include <nuttx/wdog.h>
|
||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
|
#include <nuttx/signal.h>
|
||||||
|
|
||||||
#include "sched/sched.h"
|
#include "sched/sched.h"
|
||||||
#include "signal/signal.h"
|
#include "signal/signal.h"
|
||||||
@@ -59,7 +62,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: sigprocmask
|
* Name: nxsig_procmask
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function allows the calling process to examine and/or change its
|
* 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
|
* signals to be used to change the currently blocked set. The value of
|
||||||
* 'how' indicates the manner in which the set is changed.
|
* 'how' indicates the manner in which the set is changed.
|
||||||
*
|
*
|
||||||
* If there any pending unblocked signals after the call to sigprocmask(),
|
* If there any pending unblocked signals after the call to
|
||||||
* those signals will be delivered before sigprocmask() returns.
|
* 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.
|
* 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:
|
* Parameters:
|
||||||
* how - How the signal mast will be changed:
|
* how - How the signal mast will be changed:
|
||||||
* SIG_BLOCK - The resulting set is the union of the current set
|
* SIG_BLOCK - The resulting set is the union of the current set
|
||||||
@@ -86,13 +93,15 @@
|
|||||||
* oset - Location to store the old signal mask
|
* oset - Location to store the old signal mask
|
||||||
*
|
*
|
||||||
* Return Value:
|
* 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();
|
FAR struct tcb_s *rtcb = this_task();
|
||||||
sigset_t oldsigprocmask;
|
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 */
|
/* Modify the current signal mask if so requested */
|
||||||
|
|
||||||
if (set)
|
if (set != NULL)
|
||||||
{
|
{
|
||||||
/* Some of these operations are non-atomic. We need to protect
|
/* Some of these operations are non-atomic. We need to protect
|
||||||
* ourselves from attempts to process signals from interrupts
|
* 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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ret = ERROR;
|
ret = -EINVAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,3 +169,52 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
|
|||||||
sched_unlock();
|
sched_unlock();
|
||||||
return ret;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sched/task/task_setup.c
|
* 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>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -47,6 +47,7 @@
|
|||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/signal.h>
|
||||||
|
|
||||||
#include "sched/sched.h"
|
#include "sched/sched.h"
|
||||||
#include "pthread/pthread.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.
|
* inherit the signal mask of the parent thread.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(void)sigprocmask(SIG_SETMASK, NULL, &tcb->sigprocmask);
|
(void)nxsig_procmask(SIG_SETMASK, NULL, &tcb->sigprocmask);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Initialize the task state. It does not get a valid state
|
/* Initialize the task state. It does not get a valid state
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sched/task/task_spawnparms.c
|
* 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>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -44,6 +44,7 @@
|
|||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/signal.h>
|
||||||
#include <nuttx/spawn.h>
|
#include <nuttx/spawn.h>
|
||||||
|
|
||||||
#include "task/spawn.h"
|
#include "task/spawn.h"
|
||||||
@@ -317,7 +318,7 @@ int spawn_proxyattrs(FAR const posix_spawnattr_t *attr,
|
|||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
#ifndef CONFIG_DISABLE_SIGNALS
|
||||||
if (attr && (attr->flags & POSIX_SPAWN_SETSIGMASK) != 0)
|
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? */
|
/* Were we also requested to perform file actions? */
|
||||||
|
|||||||
Reference in New Issue
Block a user