2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2014-08-08 20:55:02 +02:00
|
|
|
* sched/signal/sig_action.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2024-09-11 13:45:11 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2020-05-16 17:06:29 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-05-16 17:06:29 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-05-16 17:06:29 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-12-14 19:39:29 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2009-12-14 20:30:18 +01:00
|
|
|
#include <stdint.h>
|
2018-08-30 18:27:18 +02:00
|
|
|
#include <stdbool.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <signal.h>
|
|
|
|
#include <sched.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2013-01-23 23:23:46 +01:00
|
|
|
#include <errno.h>
|
2009-12-14 19:39:29 +01:00
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
#include <nuttx/irq.h>
|
2022-09-25 17:08:38 +02:00
|
|
|
#include <nuttx/queue.h>
|
2023-05-30 06:51:09 +02:00
|
|
|
#include <nuttx/signal.h>
|
2021-12-09 06:09:34 +01:00
|
|
|
#include <nuttx/spinlock.h>
|
2016-02-14 15:17:46 +01:00
|
|
|
|
2014-08-09 01:53:55 +02:00
|
|
|
#include "sched/sched.h"
|
2014-08-08 22:06:42 +02:00
|
|
|
#include "group/group.h"
|
2014-08-08 20:44:44 +02:00
|
|
|
#include "signal/signal.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-05-29 08:55:19 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Preprocessor definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* judges if a sigaction instance is a preallocated one */
|
|
|
|
|
|
|
|
#if CONFIG_SIG_PREALLOC_ACTIONS > 0
|
|
|
|
# define IS_PREALLOC_ACTION(x) ( \
|
|
|
|
(uintptr_t)(x) >= (uintptr_t)g_sigactions && \
|
|
|
|
(uintptr_t)(x) < ((uintptr_t)g_sigactions) + sizeof(g_sigactions))
|
|
|
|
#else
|
|
|
|
# define IS_PREALLOC_ACTION(x) false
|
|
|
|
#endif
|
|
|
|
|
2021-12-09 06:09:34 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static spinlock_t g_sigaction_spin;
|
|
|
|
|
2024-05-29 08:55:19 +02:00
|
|
|
#if CONFIG_SIG_PREALLOC_ACTIONS > 0
|
|
|
|
static sigactq_t g_sigactions[CONFIG_SIG_PREALLOC_ACTIONS];
|
|
|
|
static bool g_sigactions_used = false;
|
|
|
|
#endif
|
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Private Functions
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2021-07-13 15:56:29 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_alloc_actionblock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Allocate a block of signal actions and place them
|
|
|
|
* on the free list.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void nxsig_alloc_actionblock(void)
|
|
|
|
{
|
|
|
|
FAR sigactq_t *sigact;
|
|
|
|
irqstate_t flags;
|
|
|
|
int i;
|
|
|
|
|
2024-05-29 08:55:19 +02:00
|
|
|
/* Use pre-allocated instances only once */
|
|
|
|
|
|
|
|
#if CONFIG_SIG_PREALLOC_ACTIONS > 0
|
|
|
|
flags = spin_lock_irqsave(&g_sigaction_spin);
|
|
|
|
if (!g_sigactions_used)
|
|
|
|
{
|
|
|
|
for (i = 0; i < CONFIG_SIG_PREALLOC_ACTIONS; i++)
|
|
|
|
{
|
|
|
|
sq_addlast((FAR sq_entry_t *)(g_sigactions + i), &g_sigfreeaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_sigactions_used = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&g_sigaction_spin, flags);
|
|
|
|
#endif
|
|
|
|
|
2021-07-13 15:56:29 +02:00
|
|
|
/* Allocate a block of signal actions */
|
|
|
|
|
2024-05-29 08:55:19 +02:00
|
|
|
sigact = kmm_malloc((sizeof(sigactq_t)) * CONFIG_SIG_ALLOC_ACTIONS);
|
2021-07-13 15:56:29 +02:00
|
|
|
if (sigact != NULL)
|
|
|
|
{
|
2021-12-09 06:09:34 +01:00
|
|
|
flags = spin_lock_irqsave(&g_sigaction_spin);
|
2021-07-13 15:56:29 +02:00
|
|
|
|
2024-05-29 08:55:19 +02:00
|
|
|
for (i = 0; i < CONFIG_SIG_ALLOC_ACTIONS; i++)
|
2021-07-13 15:56:29 +02:00
|
|
|
{
|
|
|
|
sq_addlast((FAR sq_entry_t *)sigact++, &g_sigfreeaction);
|
|
|
|
}
|
|
|
|
|
2021-12-09 06:09:34 +01:00
|
|
|
spin_unlock_irqrestore(&g_sigaction_spin, flags);
|
2021-07-13 15:56:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_
This is analogous to similar renaming that was done previously for semaphores.
Squashed commit of the following:
sched/signal: Fix a few compile warnings introduced by naming changes.
sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix.
sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
|
|
|
* Name: nxsig_alloc_action
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Allocate a new element for a sigaction queue
|
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_
This is analogous to similar renaming that was done previously for semaphores.
Squashed commit of the following:
sched/signal: Fix a few compile warnings introduced by naming changes.
sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix.
sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
|
|
|
static FAR sigactq_t *nxsig_alloc_action(void)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR sigactq_t *sigact;
|
2021-07-13 15:56:29 +02:00
|
|
|
irqstate_t flags;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Try to get the signal action structure from the free list */
|
|
|
|
|
2021-12-09 06:09:34 +01:00
|
|
|
flags = spin_lock_irqsave(&g_sigaction_spin);
|
2015-10-08 03:59:14 +02:00
|
|
|
sigact = (FAR sigactq_t *)sq_remfirst(&g_sigfreeaction);
|
2021-12-09 06:09:34 +01:00
|
|
|
spin_unlock_irqrestore(&g_sigaction_spin, flags);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-05-29 08:55:19 +02:00
|
|
|
/* Check if we got one via loop as not in critical section now */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2021-12-23 03:31:30 +01:00
|
|
|
while (!sigact)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
/* Add another block of signal actions to the list */
|
|
|
|
|
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_
This is analogous to similar renaming that was done previously for semaphores.
Squashed commit of the following:
sched/signal: Fix a few compile warnings introduced by naming changes.
sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix.
sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
|
|
|
nxsig_alloc_actionblock();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* And try again */
|
|
|
|
|
2021-12-09 06:09:34 +01:00
|
|
|
flags = spin_lock_irqsave(&g_sigaction_spin);
|
2015-10-08 03:59:14 +02:00
|
|
|
sigact = (FAR sigactq_t *)sq_remfirst(&g_sigfreeaction);
|
2021-12-09 06:09:34 +01:00
|
|
|
spin_unlock_irqrestore(&g_sigaction_spin, flags);
|
2012-07-14 21:30:31 +02:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
return sigact;
|
|
|
|
}
|
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2018-08-30 18:27:18 +02:00
|
|
|
* Name: nxsig_action and sigaction
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2008-01-31 18:59:22 +01:00
|
|
|
* This function allows the calling process to examine and/or specify the
|
|
|
|
* action to be associated with a specific signal.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
* The structure sigaction, used to describe an action to be taken, is
|
|
|
|
* defined to include the following members:
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
* - sa_u.sa_handler: Pointer to a signal-catching function
|
|
|
|
* - sa_u.sa_sigaction: Alternative form of the signal-catching function
|
|
|
|
* - sa_mask: An additional set of signals to be blocked during execution
|
|
|
|
* of a signal catching function
|
|
|
|
* - sa_flags. Special flags to affect the behavior of a signal.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
* If the argument 'act' is not NULL, it points to a structure specifying
|
|
|
|
* the action to be associated with the specified signal. If the argument
|
|
|
|
* 'oact' is not NULL, the action previously associated with the signal
|
|
|
|
* is stored in the location pointed to by the argument 'oact.'
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
* When a signal is caught by a signal-catching function installed by
|
|
|
|
* sigaction() function, a new signal mask is calculated and installed for
|
|
|
|
* the duration of the signal-catching function. This mask is formed by
|
|
|
|
* taking the union of the current signal mask and the value of the
|
|
|
|
* sa_mask for the signal being delivered and then including the signal
|
|
|
|
* being delivered. If and when the user's signal handler returns, the
|
|
|
|
* original signal mask is restored.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
* Once an action is installed for a specific signal, it remains installed
|
2018-08-30 18:27:18 +02:00
|
|
|
* until another action is explicitly requested by another call to
|
|
|
|
* sigaction().
|
|
|
|
*
|
|
|
|
* nxsig_action() is an internal version of sigaction that adds an
|
|
|
|
* additional parameter, force, that is used to set default signal actions
|
|
|
|
* (which may not normally be settable). nxsig_action() does not alter the
|
|
|
|
* errno variable.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2018-08-30 18:27:18 +02:00
|
|
|
* sig - Signal of interest
|
|
|
|
* act - Location of new handler
|
|
|
|
* oact - Location to store only handler
|
|
|
|
* force - Force setup of the signal handler, even if it cannot normally
|
|
|
|
* be caught or ignored (nxsig_action only)
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2018-08-30 18:27:18 +02:00
|
|
|
* nxsig_action:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned
|
|
|
|
* on failure
|
|
|
|
* sigaction:
|
|
|
|
* Zero (OK) is returned on success; -1 (ERROR) is returned on any
|
2020-03-10 05:50:49 +01:00
|
|
|
* failure if the signal number is invalid with the errno set
|
|
|
|
* appropriately
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
* POSIX Compatibility:
|
2018-08-28 20:39:03 +02:00
|
|
|
* - If CONFIG_SIG_DEFAULT is not defined, then there are no default actions
|
|
|
|
* so the special value SIG_DFL is treated like SIG_IGN.
|
2013-01-23 23:23:46 +01:00
|
|
|
* - All sa_flags in struct sigaction of act input are ignored (all
|
2020-03-10 05:50:49 +01:00
|
|
|
* treated like SA_SIGINFO). The one exception is if
|
|
|
|
* CONFIG_SCHED_CHILD_STATUS is defined; then SA_NOCLDWAIT is supported but
|
|
|
|
* only for SIGCHLD
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-08-30 18:27:18 +02:00
|
|
|
int nxsig_action(int signo, FAR const struct sigaction *act,
|
|
|
|
FAR struct sigaction *oact, bool force)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2016-02-07 00:44:41 +01:00
|
|
|
FAR struct tcb_s *rtcb = this_task();
|
2016-02-18 15:34:11 +01:00
|
|
|
FAR struct task_group_s *group;
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR sigactq_t *sigact;
|
2018-08-27 23:37:43 +02:00
|
|
|
_sa_handler_t handler;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/* Since sigactions can only be installed from the running thread of
|
|
|
|
* execution, no special precautions should be necessary.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-18 15:34:11 +01:00
|
|
|
DEBUGASSERT(rtcb != NULL && rtcb->group != NULL);
|
|
|
|
group = rtcb->group;
|
|
|
|
|
2013-01-23 23:23:46 +01:00
|
|
|
/* Verify the signal number */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-01-23 23:23:46 +01:00
|
|
|
if (!GOOD_SIGNO(signo))
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2018-08-30 18:27:18 +02:00
|
|
|
return -EINVAL;
|
2013-01-23 23:23:46 +01:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-08-28 20:39:03 +02:00
|
|
|
#ifdef CONFIG_SIG_DEFAULT
|
|
|
|
/* Check if the user is trying to catch or ignore a signal that cannot be
|
|
|
|
* caught or ignored.
|
|
|
|
*/
|
|
|
|
|
2018-08-30 18:27:18 +02:00
|
|
|
if (act != NULL && !force && act->sa_handler != SIG_DFL &&
|
|
|
|
!nxsig_iscatchable(signo))
|
2018-08-28 20:39:03 +02:00
|
|
|
{
|
2018-08-30 18:27:18 +02:00
|
|
|
return -EINVAL;
|
2018-08-28 20:39:03 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-18 15:34:11 +01:00
|
|
|
/* Find the signal in the signal action queue */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_
This is analogous to similar renaming that was done previously for semaphores.
Squashed commit of the following:
sched/signal: Fix a few compile warnings introduced by naming changes.
sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix.
sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
|
|
|
sigact = nxsig_find_action(group, signo);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-01-23 23:23:46 +01:00
|
|
|
/* Return the old sigaction value if so requested */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
if (oact != NULL)
|
2013-01-23 23:23:46 +01:00
|
|
|
{
|
2018-08-27 21:13:23 +02:00
|
|
|
#ifdef CONFIG_SIG_DEFAULT
|
|
|
|
if (nxsig_isdefault(rtcb, signo))
|
|
|
|
{
|
|
|
|
/* Return SIG_DFL if the default signal is attached */
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
oact->sa_handler = SIG_DFL;
|
|
|
|
oact->sa_flags = SA_SIGINFO;
|
2023-03-23 21:36:14 +01:00
|
|
|
sigemptyset(&oact->sa_mask);
|
2018-08-27 21:13:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2013-01-23 23:23:46 +01:00
|
|
|
if (sigact)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2018-08-27 21:13:23 +02:00
|
|
|
/* Return the old signal action */
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
oact->sa_handler = sigact->act.sa_handler;
|
|
|
|
oact->sa_mask = sigact->act.sa_mask;
|
|
|
|
oact->sa_flags = sigact->act.sa_flags;
|
2013-01-23 23:23:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* There isn't an old value */
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
oact->sa_handler = NULL;
|
|
|
|
oact->sa_flags = 0;
|
2023-03-23 21:36:14 +01:00
|
|
|
sigemptyset(&oact->sa_mask);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2013-01-23 23:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If the argument act is a null pointer, signal handling is unchanged;
|
2018-08-27 21:13:23 +02:00
|
|
|
* thus, the call can be used to inquire about the current handling of
|
2014-04-13 22:32:20 +02:00
|
|
|
* a given signal.
|
2013-01-23 23:23:46 +01:00
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
if (act == NULL)
|
2013-01-23 23:23:46 +01:00
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
|
|
|
|
/* Handle a special case. Retention of child status can be suppressed
|
|
|
|
* if signo == SIGCHLD and sa_flags == SA_NOCLDWAIT.
|
|
|
|
*
|
|
|
|
* POSIX.1 leaves it unspecified whether a SIGCHLD signal is generated
|
|
|
|
* when a child process terminates. In NuttX, a SIGCHLD signal is
|
|
|
|
* generated in this case; but in some other implementations, it may not
|
|
|
|
* be.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (signo == SIGCHLD && (act->sa_flags & SA_NOCLDWAIT) != 0)
|
|
|
|
{
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* We do require a critical section to muck with the TCB values that
|
|
|
|
* can be modified by the child thread.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-01-23 23:23:46 +01:00
|
|
|
/* Mark that status should be not be retained */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-01-25 18:23:38 +01:00
|
|
|
rtcb->group->tg_flags |= GROUP_FLAG_NOCLDWAIT;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-01-23 23:23:46 +01:00
|
|
|
/* Free all pending exit status */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-05-16 17:06:29 +02:00
|
|
|
group_remove_children(rtcb->group);
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2013-01-23 23:23:46 +01:00
|
|
|
}
|
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
handler = act->sa_handler;
|
2018-08-27 21:13:23 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_SIG_DEFAULT
|
|
|
|
/* If the caller is setting the handler to SIG_DFL, then we need to
|
|
|
|
* replace this with the correct, internal default signal action handler.
|
|
|
|
*/
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
if (handler == SIG_DFL)
|
2018-08-27 21:13:23 +02:00
|
|
|
{
|
|
|
|
/* nxsig_default() may returned SIG_IGN */
|
|
|
|
|
|
|
|
handler = nxsig_default(rtcb, signo, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We will be replacing the default action (or ignoring it) */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
nxsig_default(rtcb, signo, false);
|
2018-08-27 21:13:23 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-23 23:23:46 +01:00
|
|
|
/* Handle the case where no sigaction is supplied (SIG_IGN) */
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
if (handler == SIG_IGN)
|
2013-01-23 23:23:46 +01:00
|
|
|
{
|
2013-01-25 00:18:32 +01:00
|
|
|
/* Do we still have a sigaction container from the previous setting? */
|
2013-01-23 23:23:46 +01:00
|
|
|
|
2013-01-25 00:18:32 +01:00
|
|
|
if (sigact)
|
|
|
|
{
|
2016-02-18 15:34:11 +01:00
|
|
|
/* Yes.. Remove it from signal action queue */
|
2013-01-25 00:18:32 +01:00
|
|
|
|
2016-02-18 15:34:11 +01:00
|
|
|
sq_rem((FAR sq_entry_t *)sigact, &group->tg_sigactionq);
|
2013-01-23 23:23:46 +01:00
|
|
|
|
2013-01-25 00:18:32 +01:00
|
|
|
/* And deallocate it */
|
2013-01-23 23:23:46 +01:00
|
|
|
|
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_
This is analogous to similar renaming that was done previously for semaphores.
Squashed commit of the following:
sched/signal: Fix a few compile warnings introduced by naming changes.
sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix.
sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
|
|
|
nxsig_release_action(sigact);
|
2013-01-25 00:18:32 +01:00
|
|
|
}
|
2013-01-23 23:23:46 +01:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-01-23 23:23:46 +01:00
|
|
|
/* A sigaction has been supplied */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-01-23 23:23:46 +01:00
|
|
|
else
|
|
|
|
{
|
2013-01-25 00:18:32 +01:00
|
|
|
/* Do we still have a sigaction container from the previous setting?
|
|
|
|
* If so, then re-use for the new signal action.
|
|
|
|
*/
|
2013-01-23 23:23:46 +01:00
|
|
|
|
2018-08-27 21:13:23 +02:00
|
|
|
if (sigact == NULL)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2013-01-25 00:18:32 +01:00
|
|
|
/* No.. Then we need to allocate one for the new action. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_
This is analogous to similar renaming that was done previously for semaphores.
Squashed commit of the following:
sched/signal: Fix a few compile warnings introduced by naming changes.
sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix.
sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
|
|
|
sigact = nxsig_alloc_action();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-01-23 23:23:46 +01:00
|
|
|
/* An error has occurred if we could not allocate the sigaction */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-01-23 23:23:46 +01:00
|
|
|
if (!sigact)
|
2015-10-08 03:59:14 +02:00
|
|
|
{
|
2018-08-30 18:27:18 +02:00
|
|
|
return -ENOMEM;
|
2015-10-08 03:59:14 +02:00
|
|
|
}
|
2013-01-23 23:23:46 +01:00
|
|
|
|
|
|
|
/* Put the signal number in the queue entry */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-01-23 23:23:46 +01:00
|
|
|
sigact->signo = (uint8_t)signo;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-18 15:34:11 +01:00
|
|
|
/* Add the new sigaction to signal action queue */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-18 15:34:11 +01:00
|
|
|
sq_addlast((FAR sq_entry_t *)sigact, &group->tg_sigactionq);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2013-01-23 23:23:46 +01:00
|
|
|
|
|
|
|
/* Set the new sigaction */
|
|
|
|
|
2018-08-27 23:37:43 +02:00
|
|
|
sigact->act.sa_handler = handler;
|
|
|
|
sigact->act.sa_mask = act->sa_mask;
|
|
|
|
sigact->act.sa_flags = act->sa_flags;
|
2022-12-22 13:46:12 +01:00
|
|
|
sigact->act.sa_user = act->sa_user;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2013-01-25 00:18:32 +01:00
|
|
|
return OK;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2018-08-30 18:27:18 +02:00
|
|
|
int sigaction(int signo, FAR const struct sigaction *act,
|
|
|
|
FAR struct sigaction *oact)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* nxsig_action() does all of the work */
|
|
|
|
|
|
|
|
ret = nxsig_action(signo, act, oact, false);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
set_errno(-ret);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_
This is analogous to similar renaming that was done previously for semaphores.
Squashed commit of the following:
sched/signal: Fix a few compile warnings introduced by naming changes.
sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix.
sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
|
|
|
* Name: nxsig_release_action
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Deallocate a sigaction Q entry
|
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_
This is analogous to similar renaming that was done previously for semaphores.
Squashed commit of the following:
sched/signal: Fix a few compile warnings introduced by naming changes.
sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix.
sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
|
|
|
void nxsig_release_action(FAR sigactq_t *sigact)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2021-07-13 15:56:29 +02:00
|
|
|
irqstate_t flags;
|
|
|
|
|
2024-05-29 08:55:19 +02:00
|
|
|
if (CONFIG_SIG_ALLOC_ACTIONS > 1 || IS_PREALLOC_ACTION(sigact))
|
|
|
|
{
|
|
|
|
/* Non-preallocated instances will never return to heap! */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2024-05-29 08:55:19 +02:00
|
|
|
flags = spin_lock_irqsave(&g_sigaction_spin);
|
|
|
|
sq_addlast((FAR sq_entry_t *)sigact, &g_sigfreeaction);
|
|
|
|
spin_unlock_irqrestore(&g_sigaction_spin, flags);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kmm_free(sigact);
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|