2018-08-27 19:40:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* sched/signal/sig_default.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 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>
|
|
|
|
|
2018-09-02 23:36:25 +02:00
|
|
|
#include <sys/wait.h>
|
2018-08-29 15:33:28 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2018-08-27 19:40:09 +02:00
|
|
|
#include <string.h>
|
2018-08-29 15:33:28 +02:00
|
|
|
#include <pthread.h>
|
2018-08-27 19:40:09 +02:00
|
|
|
#include <signal.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <nuttx/sched.h>
|
2018-08-28 06:32:57 +02:00
|
|
|
#include <nuttx/irq.h>
|
2018-08-30 18:27:18 +02:00
|
|
|
#include <nuttx/signal.h>
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-29 13:49:42 +02:00
|
|
|
#include "group/group.h"
|
|
|
|
#include "sched/sched.h"
|
2018-08-27 19:40:09 +02:00
|
|
|
#include "signal/signal.h"
|
|
|
|
|
2018-08-28 20:39:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Bit definitions for the struct nxsig_defaction_s 'flags' field */
|
|
|
|
|
|
|
|
#define SIG_FLAG_NOCATCH (1 << 0) /* Signal cannot be caught or ignored */
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This type provides the default action associated with a signal */
|
|
|
|
|
|
|
|
struct nxsig_defaction_s
|
|
|
|
{
|
|
|
|
uint8_t signo; /* Signal number. Range 1..MAX_SIGNO */
|
2018-08-28 20:39:03 +02:00
|
|
|
uint8_t flags; /* See SIG_FLAG_ definitions */
|
2018-08-27 23:37:43 +02:00
|
|
|
_sa_handler_t action; /* Default signal action */
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Default actions */
|
|
|
|
|
2018-08-30 18:27:18 +02:00
|
|
|
static void nxsig_null_action(int signo);
|
2018-08-27 23:37:43 +02:00
|
|
|
static void nxsig_abnormal_termination(int signo);
|
2018-08-30 18:27:18 +02:00
|
|
|
static void nxsig_stop_task(int signo);
|
2018-08-27 23:37:43 +02:00
|
|
|
|
|
|
|
/* Helpers */
|
|
|
|
|
|
|
|
static _sa_handler_t nxsig_default_action(int signo);
|
|
|
|
static void nxsig_setup_default_action(FAR struct task_group_s *group,
|
|
|
|
FAR const struct nxsig_defaction_s *info);
|
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
/* NOTE: Default actions are not currently supported for very many signals.
|
|
|
|
* However, this array is set up to support an indefinite number of default
|
|
|
|
* signal actions.
|
|
|
|
*/
|
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
/* This table is used to make the default action for a signal to the correct
|
2018-08-27 23:37:43 +02:00
|
|
|
* signal handler. Signals whose default action is be ignored do not need
|
|
|
|
* to be in this table (e.g., SIGCHLD).
|
2018-08-27 19:40:09 +02:00
|
|
|
*/
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
static const struct nxsig_defaction_s g_defactions[] =
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2018-08-27 23:37:43 +02:00
|
|
|
#ifdef CONFIG_SIG_SIGUSR1_ACTION
|
2018-08-28 20:39:03 +02:00
|
|
|
{ SIGUSR1, 0, nxsig_abnormal_termination },
|
2018-08-27 23:37:43 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SIG_SIGUSR2_ACTION
|
2018-08-28 20:39:03 +02:00
|
|
|
{ SIGUSR2, 0, nxsig_abnormal_termination },
|
2018-08-27 23:37:43 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SIG_SIGALRM_ACTION
|
2018-08-28 20:39:03 +02:00
|
|
|
{ SIGALRM, 0, nxsig_abnormal_termination },
|
2018-08-27 19:40:09 +02:00
|
|
|
#endif
|
2018-08-27 23:37:43 +02:00
|
|
|
#ifdef CONFIG_SIG_SIGPOLL_ACTION
|
2018-08-28 20:39:03 +02:00
|
|
|
{ SIGPOLL, 0, nxsig_abnormal_termination },
|
2018-08-27 23:37:43 +02:00
|
|
|
#endif
|
2018-08-30 18:27:18 +02:00
|
|
|
#ifdef CONFIG_SIG_SIGSTOP_ACTION
|
|
|
|
{ SIGSTOP, SIG_FLAG_NOCATCH, nxsig_stop_task },
|
|
|
|
{ SIGSTP, 0, nxsig_stop_task },
|
|
|
|
{ SIGCONT, SIG_FLAG_NOCATCH, nxsig_null_action },
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SIG_SIGKILL_ACTION
|
2018-08-28 20:39:03 +02:00
|
|
|
{ SIGINT, 0, nxsig_abnormal_termination },
|
|
|
|
{ SIGKILL, SIG_FLAG_NOCATCH, nxsig_abnormal_termination }
|
2018-08-30 18:27:18 +02:00
|
|
|
#endif
|
2018-08-27 23:37:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NACTIONS (sizeof(g_defactions) / sizeof(struct nxsig_defaction_s))
|
2018-08-27 19:40:09 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* TODO: Take into account pthread-specific signal behaviors */
|
|
|
|
|
|
|
|
/* Default Actions:
|
|
|
|
*
|
|
|
|
* - Abnormal termination of the process. The process is terminated with
|
|
|
|
* all the consequences of _exit() except that the status made available
|
|
|
|
* to wait() and waitpid() indicates abnormal termination by the
|
|
|
|
* specified signal.
|
|
|
|
* - Abnormal termination of the process. Additionally with the XSI
|
|
|
|
* extension, implementation-defined abnormal termination actions, such
|
|
|
|
* as creation of a core file, may occur.
|
|
|
|
* - Ignore the signal.
|
|
|
|
* - Stop the process.
|
|
|
|
* - Continue the process, if it is stopped; otherwise, ignore the signal.
|
|
|
|
*/
|
|
|
|
|
2018-08-30 18:27:18 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_null_action
|
|
|
|
*
|
|
|
|
* Description:
|
2018-09-02 21:51:52 +02:00
|
|
|
* The do-nothing default signal action handler.
|
2018-08-30 18:27:18 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* Standard signal handler parameters
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void nxsig_null_action(int signo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_abnormal_termination
|
|
|
|
*
|
|
|
|
* Description:
|
2018-08-28 06:32:57 +02:00
|
|
|
* This is the handler for the abnormal termination default action.
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* Standard signal handler parameters
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
static void nxsig_abnormal_termination(int signo)
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2018-08-29 15:33:28 +02:00
|
|
|
FAR struct tcb_s *rtcb = (FAR struct tcb_s *)this_task();
|
|
|
|
|
|
|
|
/* Careful: In the multi-threaded task, the signal may be handled on a
|
|
|
|
* child pthread.
|
|
|
|
*/
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-29 15:33:28 +02:00
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
2018-08-29 23:50:01 +02:00
|
|
|
/* Kill of of the children of the task. This will not kill the currently
|
|
|
|
* running task/pthread (this_task). It will kill the main thread of the
|
|
|
|
* task group if the this_task is a
|
2018-08-29 15:33:28 +02:00
|
|
|
* pthread.
|
|
|
|
*/
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-29 15:33:28 +02:00
|
|
|
group_killchildren((FAR struct task_tcb_s *)rtcb);
|
2018-08-27 19:40:09 +02:00
|
|
|
#endif
|
|
|
|
|
2018-08-29 15:33:28 +02:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
|
|
|
/* Check if the currently running task is actually a pthread */
|
|
|
|
|
|
|
|
if ((rtcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD)
|
|
|
|
{
|
|
|
|
/* Exit the final thread of the task group.
|
|
|
|
*
|
|
|
|
* REVISIT: This will not work if HAVE_GROUP_MEMBERS is not set.
|
|
|
|
*/
|
|
|
|
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Exit to terminate the task (note that exit() vs. _exit() is used. */
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-29 15:33:28 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|
|
|
|
|
2018-08-30 18:27:18 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_stop_task
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This is the handler for the abnormal termination default action.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* Standard signal handler parameters
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void nxsig_stop_task(int signo)
|
|
|
|
{
|
|
|
|
FAR struct tcb_s *rtcb = (FAR struct tcb_s *)this_task();
|
2018-09-02 23:36:25 +02:00
|
|
|
#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT)
|
|
|
|
FAR struct task_group_s *group;
|
|
|
|
|
|
|
|
DEBUGASSERT(rtcb != NULL && rtcb->group != NULL);
|
|
|
|
group = rtcb->group;
|
|
|
|
#endif
|
2018-08-30 18:27:18 +02:00
|
|
|
|
|
|
|
/* Careful: In the multi-threaded task, the signal may be handled on a
|
|
|
|
* child pthread.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
|
|
|
/* Suspend of of the children of the task. This will not suspend the
|
|
|
|
* currently running task/pthread (this_task). It will suspend the
|
2018-09-02 21:51:52 +02:00
|
|
|
* main thread of the task group if the this_task is a pthread.
|
2018-08-30 18:27:18 +02:00
|
|
|
*/
|
|
|
|
|
2018-09-02 21:51:52 +02:00
|
|
|
group_suspendchildren(rtcb);
|
2018-08-30 18:27:18 +02:00
|
|
|
#endif
|
|
|
|
|
2018-09-02 23:36:25 +02:00
|
|
|
/* Lock the scheduler so this thread is not pre-empted until after we
|
2018-09-02 21:51:52 +02:00
|
|
|
* call sched_suspend().
|
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
|
|
|
|
|
|
|
#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT)
|
|
|
|
/* Notify via waitpid if any parent is waiting for this task to EXIT
|
|
|
|
* or STOP. This action is only performed if WUNTRACED is set in the
|
|
|
|
* waitpid flags.
|
|
|
|
*/
|
|
|
|
|
2018-09-02 23:36:25 +02:00
|
|
|
if ((group->tg_waitflags & WUNTRACED) != 0)
|
2018-09-02 21:51:52 +02:00
|
|
|
{
|
|
|
|
/* Return zero for exit status (we are not exiting, however) */
|
|
|
|
|
|
|
|
if (group->tg_statloc != NULL)
|
|
|
|
{
|
|
|
|
*group->tg_statloc = 0;
|
|
|
|
group->tg_statloc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tg_waitflags == 0 means that the flags are available to another
|
|
|
|
* caller of waitpid().
|
|
|
|
*/
|
|
|
|
|
|
|
|
group->tg_waitflags = 0;
|
|
|
|
|
|
|
|
/* YWakeup any tasks waiting for this task to exit or stop. */
|
|
|
|
|
|
|
|
while (group->tg_exitsem.semcount < 0)
|
|
|
|
{
|
|
|
|
/* Wake up the thread */
|
|
|
|
|
|
|
|
nxsem_post(&group->tg_exitsem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Then, finally, suspend this the final thread of the task group */
|
2018-08-30 18:27:18 +02:00
|
|
|
|
|
|
|
sched_suspend(rtcb);
|
2018-09-02 21:51:52 +02:00
|
|
|
sched_unlock();
|
2018-08-30 18:27:18 +02:00
|
|
|
}
|
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
/****************************************************************************
|
2018-08-27 21:13:23 +02:00
|
|
|
* Name: nxsig_default_action
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-08-27 21:13:23 +02:00
|
|
|
* Look up the default action associated with this signal
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-08-27 21:13:23 +02:00
|
|
|
* signo - The signal number to use in the query
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2018-08-27 21:13:23 +02:00
|
|
|
* The default handler associated with this signal
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
static _sa_handler_t nxsig_default_action(int signo)
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2018-08-27 23:37:43 +02:00
|
|
|
int i;
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
/* Search the default action table for the entry associated with this
|
|
|
|
* signal.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < NACTIONS; i++)
|
|
|
|
{
|
|
|
|
if (g_defactions[i].signo == signo)
|
|
|
|
{
|
|
|
|
return g_defactions[i].action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No default action */
|
|
|
|
|
|
|
|
return SIG_IGN;
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_setup_default_action
|
|
|
|
*
|
|
|
|
* Description:
|
2018-08-28 06:32:57 +02:00
|
|
|
* Setup the default action for a signal.
|
|
|
|
*
|
|
|
|
* This function is called early in task setup, prior to the creation of
|
|
|
|
* any pthreads so we should have exclusive access to the group structure.
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-08-27 21:13:23 +02:00
|
|
|
* group - The group that the task belongs in.
|
|
|
|
* action - The new default signal action
|
|
|
|
* signo - The signal that will produce this default action
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
static void nxsig_setup_default_action(FAR struct task_group_s *group,
|
2018-08-27 23:37:43 +02:00
|
|
|
FAR const struct nxsig_defaction_s *info)
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2018-08-27 21:13:23 +02:00
|
|
|
/* Get the address of the handler for this signals default action. */
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
if (info->action != SIG_IGN)
|
2018-08-27 21:13:23 +02:00
|
|
|
{
|
2018-08-27 23:37:43 +02:00
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
/* Attach the signal handler.
|
|
|
|
*
|
2018-08-30 18:27:18 +02:00
|
|
|
* NOTE: nxsig_action will call nxsig_default(tcb, action, false).
|
|
|
|
* Don't be surprised.
|
2018-08-27 23:37:43 +02:00
|
|
|
*/
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
memset(&sa, 0, sizeof(sa));
|
2018-08-27 23:37:43 +02:00
|
|
|
sa.sa_handler = info->action;
|
|
|
|
sa.sa_flags = SA_SIGINFO;
|
2018-08-30 18:27:18 +02:00
|
|
|
(void)nxsig_action(info->signo, &sa, NULL, true);
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
/* Indicate that the default signal handler has been attached */
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
(void)sigaddset(&group->tg_sigdefault, (int)info->signo);
|
2018-08-27 21:13:23 +02:00
|
|
|
}
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_isdefault
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return true if the specified signal is set to the default action.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* tcb - Identifies the thread associated with the default handler
|
|
|
|
* signo - The signal number to be queried
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; A negated errno value is returned
|
|
|
|
* on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool nxsig_isdefault(FAR struct tcb_s *tcb, int signo)
|
|
|
|
{
|
|
|
|
FAR struct task_group_s *group;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DEBUGASSERT(tcb != NULL && tcb->group != NULL && GOOD_SIGNO(signo));
|
|
|
|
group = tcb->group;
|
|
|
|
|
|
|
|
/* Return true if the signo is marked as using the default action. Return
|
|
|
|
* false in all other cases.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = sigismember(&group->tg_sigdefault, signo);
|
|
|
|
return ret < 0 ? false : (bool)ret;
|
|
|
|
}
|
|
|
|
|
2018-08-28 20:39:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_iscatchable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return true if the specified signal can be caught or ignored.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* signo - The signal number to be queried
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; A negated errno value is returned
|
|
|
|
* on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool nxsig_iscatchable(int signo)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Search the default action table for the entry associated with this
|
|
|
|
* signal.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < NACTIONS; i++)
|
|
|
|
{
|
|
|
|
if (g_defactions[i].signo == signo)
|
|
|
|
{
|
|
|
|
return (g_defactions[i].flags & SIG_FLAG_NOCATCH) == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it is not in the table, then it is catchable */
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
/****************************************************************************
|
2018-08-27 21:13:23 +02:00
|
|
|
* Name: nxsig_default
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-08-27 21:13:23 +02:00
|
|
|
* If 'defaction' is true, then return the default signal handler action
|
|
|
|
* for the specified signal and mark that the default signal hander is
|
|
|
|
* in place (it is not yet).
|
|
|
|
*
|
|
|
|
* If 'defaction' is false, then mark that the default signal handler is
|
|
|
|
* NOT in place and return SIG_IGN.
|
|
|
|
*
|
|
|
|
* This function is called form sigaction() to handle actions = SIG_DFL.
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* tcb - Identifies the thread associated with the default handler
|
|
|
|
* signo - The signal number whose behavior will be modified.
|
|
|
|
* defaction - True: the default action is in place
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2018-08-27 21:13:23 +02:00
|
|
|
* The address of the default signal action handler is returne on success.
|
|
|
|
* SIG_IGN is returned if there is no default action.
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
_sa_handler_t nxsig_default(FAR struct tcb_s *tcb, int signo, bool defaction)
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2018-08-27 21:13:23 +02:00
|
|
|
FAR struct task_group_s *group;
|
2018-08-27 23:37:43 +02:00
|
|
|
_sa_handler_t handler = SIG_IGN;
|
2018-08-28 06:32:57 +02:00
|
|
|
irqstate_t flags;
|
2018-08-27 21:13:23 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(tcb != NULL && tcb->group != NULL);
|
|
|
|
group = tcb->group;
|
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
/* Are we setting or unsetting the default action? */
|
|
|
|
|
|
|
|
if (defaction)
|
|
|
|
{
|
|
|
|
/* We are setting the default action. Look up the default action
|
|
|
|
* associated with signo.
|
|
|
|
*/
|
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
handler = nxsig_default_action(signo);
|
2018-08-27 23:37:43 +02:00
|
|
|
if (handler != SIG_IGN)
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2018-08-28 06:32:57 +02:00
|
|
|
/* sigaddset() is not atomic (but neither is sigaction()) */
|
|
|
|
|
|
|
|
flags = spin_lock_irqsave();
|
2018-08-27 21:13:23 +02:00
|
|
|
(void)sigaddset(&group->tg_sigdefault, signo);
|
2018-08-28 06:32:57 +02:00
|
|
|
spin_unlock_irqrestore(flags);
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-27 21:13:23 +02:00
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
if (handler == SIG_IGN)
|
2018-08-27 19:40:09 +02:00
|
|
|
{
|
2019-03-01 17:50:02 +01:00
|
|
|
/* We are unsetting the default action. NOTE that sigdelset() is not
|
|
|
|
* atomic (but neither is sigaction()).
|
|
|
|
*/
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-28 06:32:57 +02:00
|
|
|
flags = spin_lock_irqsave();
|
2018-08-27 21:13:23 +02:00
|
|
|
(void)sigdelset(&group->tg_sigdefault, signo);
|
2018-08-28 06:32:57 +02:00
|
|
|
spin_unlock_irqrestore(flags);
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
return handler;
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_default_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
* Set all signals to their default action. This is called from nxtask_start
|
2018-08-27 21:13:23 +02:00
|
|
|
* to configure the newly started task.
|
2018-08-27 19:40:09 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* tcb - Identifies the thread associated with the default handlers
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; A negated errno value is returned
|
|
|
|
* on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int nxsig_default_initialize(FAR struct tcb_s *tcb)
|
|
|
|
{
|
2018-08-27 21:13:23 +02:00
|
|
|
FAR struct task_group_s *group;
|
2018-08-27 23:37:43 +02:00
|
|
|
int i;
|
2018-08-27 19:40:09 +02:00
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
DEBUGASSERT(tcb != NULL && tcb->group != NULL);
|
|
|
|
group = tcb->group;
|
|
|
|
|
|
|
|
/* Initialize the set of default signal handlers */
|
|
|
|
|
|
|
|
(void)sigemptyset(&group->tg_sigdefault);
|
|
|
|
|
2018-08-28 06:32:57 +02:00
|
|
|
/* Setup the default action for each signal in g_defactions[] */
|
2018-08-27 21:13:23 +02:00
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
for (i = 0; i < NACTIONS; i++)
|
2018-08-27 21:13:23 +02:00
|
|
|
{
|
2018-08-27 23:37:43 +02:00
|
|
|
nxsig_setup_default_action(group, &g_defactions[i]);
|
2018-08-27 21:13:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
2018-08-27 19:40:09 +02:00
|
|
|
}
|