From 27a18d9044ced6a33ab178848e6d37c95e86bcc4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 9 Apr 2015 10:16:35 -0600 Subject: Add sigset() --- nuttx/Documentation/NuttxUserGuide.html | 171 ++++++++++++++++++++++++++++---- nuttx/include/signal.h | 9 +- nuttx/libc/signal/Make.defs | 1 + nuttx/libc/signal/sig_set.c | 127 ++++++++++++++++++++++++ 4 files changed, 288 insertions(+), 20 deletions(-) create mode 100644 nuttx/libc/signal/sig_set.c (limited to 'nuttx') diff --git a/nuttx/Documentation/NuttxUserGuide.html b/nuttx/Documentation/NuttxUserGuide.html index 917b52559..c2d65d00d 100644 --- a/nuttx/Documentation/NuttxUserGuide.html +++ b/nuttx/Documentation/NuttxUserGuide.html @@ -13,7 +13,7 @@

NuttX Operating System

User's Manual

by

Gregory Nutt

-

Last Updated: November 29, 2014

+

Last Updated: April 9, 2015

@@ -4487,14 +4487,19 @@ interface of the same name.
  • 2.7.4 sigdelset
  • 2.7.5 sigismember
  • 2.7.6 sigaction
  • -
  • 2.7.7 sigprocmask
  • -
  • 2.7.8 sigpending
  • -
  • 2.7.9 sigsuspend
  • -
  • 2.7.10 sigwaitinfo
  • -
  • 2.7.11 sigtimedwait
  • -
  • 2.7.12 sigqueue
  • -
  • 2.7.13 kill
  • -
  • 2.7.14 pause
  • +
  • 2.7.7 sigignore
  • +
  • 2.7.8 sigset
  • +
  • 2.7.9 sigprocmask
  • +
  • 2.7.10 sighold
  • +
  • 2.7.11 sigrelse
  • +
  • 2.7.12 sigpending
  • +
  • 2.7.13 sigsuspend
  • +
  • 2.7.14 sigpause
  • +
  • 2.7.15 sigwaitinfo
  • +
  • 2.7.16 sigtimedwait
  • +
  • 2.7.17 sigqueue
  • +
  • 2.7.18 kill
  • +
  • 2.7.19 pause
  • 2.7.1 sigemptyset

    @@ -4729,7 +4734,65 @@ Differences from the POSIX implementation include: -

    2.7.7 sigprocmask

    +

    2.7.7 sigignore

    + +

    +Function Prototype: +

    +    #include <signal.h>
    +    int sigignore(int signo);
    +
    + +

    +Description: The sigignore() function will set the disposition of signo to SIG_IGN. +

    +Input Parameters: +

    + +

    +Returned Value: +

    + +

    2.7.8 sigset

    + +

    +Function Prototype: +

    +    #include <signal.h>
    +    void (*sigset(int signo, void (*disp)(int)))(int);
    +
    + +

    +Description: + The sigset() function will modify signal dispositions. + The signo argument specifies the signal. + The disp argument specifies the signal's disposition, which may be SIG_DFL, SIG_IGN, or the address of a signal handler. + If disp is the address of a signal handler, the system will add signo to the calling process' signal mask before executing the signal handler; when the signal handler returns, the system will restore the calling process' signal mask to its state prior to the delivery of the signal. + signo will be removed from the calling process' signal mask. +

    +

    + NOTE: The value SIG_HOLD for disp is not currently supported. +

    +

    +Input Parameters: +

    + +

    +Returned Value: +

    + +

    2.7.9 sigprocmask

    Function Prototype: @@ -4779,7 +4842,55 @@ pointed to by the set input parameter. POSIX Compatibility: Comparable to the POSIX interface of the same name. -

    2.7.8 sigpending

    +

    2.7.10 sighold

    + +

    +Function Prototype: +

    +    #include <signal.h>
    +    int sighold(int signo);
    +
    + +

    +Description: The sighold() function will add signo to the calling process' signal mask +

    +

    +Input Parameters: +

    + +

    +Returned Value: +

    + +

    2.7.11 sigrelse

    + +

    +Function Prototype: +

    +    #include <signal.h>
    +    int sigrelse(int signo);
    +
    + +

    +Description: The sighold() function will remove signo from the calling process' signal mask +

    +

    +Input Parameters: +

    + +

    +Returned Value: +

    + +

    2.7.12 sigpending

    Function Prototype: @@ -4817,7 +4928,7 @@ is delivered more than once." POSIX Compatibility: Comparable to the POSIX interface of the same name. -

    2.7.9 sigsuspend

    +

    2.7.13 sigsuspend

    Function Prototype: @@ -4865,7 +4976,30 @@ function or to terminate the task." Only delivery of the signal is required in the present implementation (even if the signal is ignored). -

    2.7.10 sigwaitinfo

    +

    2.7.14 sigpause

    +

    +Function Prototype: +

    +    #include <signal.h>
    +    int sigpause(int signo);
    +
    + +

    +Description: The sigpause()) function will remove signo) from the calling process' signal mask and suspend the calling process until a signal is received. +The sigpause()) function will restore the process' signal mask to its original state before returning. +

    +Input Parameters: +

    + +

    +Returned Value: +

    + +

    2.7.15 sigwaitinfo

    Function Prototype: @@ -4894,10 +5028,9 @@ with a NULL timeout parameter. (see below).

    Assumptions/Limitations:

    - POSIX Compatibility: Comparable to the POSIX -interface of the same name. + POSIX Compatibility: Comparable to the POSIX interface of the same name. -

    2.7.11 sigtimedwait

    +

    2.7.16 sigtimedwait

    Function Prototype: @@ -4963,7 +5096,7 @@ that the unblocked signal be caught; the task will be resumed even if the unblocked signal is ignored. -

    2.7.12 sigqueue

    +

    2.7.17 sigqueue

    Function Prototype: @@ -5020,7 +5153,7 @@ There is no null signal in the present implementation; a zero signal will be sent. -

    2.7.13 kill

    +

    2.7.18 kill

    Function Prototype: @@ -5076,7 +5209,7 @@ be sent.

  • Sending of signals to 'process groups' is not supported in NuttX.
  • -

    2.7.14 pause

    +

    2.7.19 pause

    Function Prototype: diff --git a/nuttx/include/signal.h b/nuttx/include/signal.h index 8dd86705a..59baf16a5 100644 --- a/nuttx/include/signal.h +++ b/nuttx/include/signal.h @@ -165,11 +165,17 @@ #define SIGEV_NONE 0 /* No notification desired */ #define SIGEV_SIGNAL 1 /* Notify via signal */ -/* Special values of sigaction (all treated like NULL) */ +/* Special values of of sa_handler used by sigaction and sigset. There are all + * treated like NULL for now. + * + * REVISIT: Need to distinguish the value of SIG_HOLD. It is need in the + * implementation of sigset(). + */ #define SIG_ERR ((CODE void*)-1) #define SIG_DFL ((CODE void*)0) #define SIG_IGN ((CODE void*)0) +#define SIG_HOLD ((CODE void*)0) /******************************************************************************** * Global Type Declarations @@ -262,6 +268,7 @@ int sigdelset(FAR sigset_t *set, int signo); int sigismember(FAR const sigset_t *set, int signo); int sigaction(int sig, FAR const struct sigaction *act, FAR struct sigaction *oact); +void (*sigset(int signo, void (*disp)(int)))(int); int sigignore(int signo); int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset); int sigpause(int signo); diff --git a/nuttx/libc/signal/Make.defs b/nuttx/libc/signal/Make.defs index b79cca478..7be0ba02e 100644 --- a/nuttx/libc/signal/Make.defs +++ b/nuttx/libc/signal/Make.defs @@ -39,6 +39,7 @@ ifneq ($(CONFIG_DISABLE_SIGNALS),y) CSRCS += sig_emptyset.c sig_fillset.c sig_addset.c sig_delset.c CSRCS += sig_ismember.c sig_hold.c sig_relse.c sig_ignore.c sig_pause.c +CSRCS += sig_set.c # Add the signal directory to the build diff --git a/nuttx/libc/signal/sig_set.c b/nuttx/libc/signal/sig_set.c new file mode 100644 index 000000000..c5f01f582 --- /dev/null +++ b/nuttx/libc/signal/sig_set.c @@ -0,0 +1,127 @@ +/**************************************************************************** + * libc/signal/sig_set.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sigset + * + * Description: + * The sigset() function will modify signal dispositions. The 'signo' + * argument specifies the signal. The 'disp' argument specifies the + * signal's disposition, which may be SIG_DFL, SIG_IGN, or the address + * of a signal handler. If 'disp' is the address of a signal handler, the + * system will add 'signo' to the calling process' signal mask before + * executing the signal handler; when the signal handler returns, the + * system will restore the calling process' signal mask to its state prior + * to the delivery of the signal. 'signo' will be removed from the calling + * process' signal mask. + * + * NOTE: The value SIG_HOLD for 'disp' is not supported. It should work + * like this: If 'disp' is equal to SIG_HOLD, 'signo' will be added to, + * not removed from, the calling process' signal mask and 'signo''s + * disposition will remain unchanged. + * + * Input Parameters: + * signo - Identifies the signal to operate on + * disp - The new disposition of the signal + * + * Returned Value: + * Upon successful completion, sigset() will the previous disposition of + * the signal. Otherwise, SIG_ERR will be returned and errno set to + * indicate the error. + * + * NOTE: sigset() would return SIG_HOLD if the signal had been blocked and + * the signal's previous disposition if it had not been blocked. + * + ****************************************************************************/ + +void (*sigset(int signo, void (*disp)(int)))(int) +{ + struct sigaction act; + struct sigaction oact; + int ret; + + /* Initialize the sigaction structure */ + + act.sa_handler = disp; + act.sa_flags = 0; + (void)sigemptyset(&act.sa_mask); + + /* Check for SIG_IGN and SIG_DFL (and someday SIG_HOLD) + * + * REVISIT: Currently SIG_IGN, SIG_DFL, and SIG_HOLD have the same value + * and cannot be distinguished. + */ + + if (disp != SIG_DFL /* && disp != SIG_IGN */) + { + /* Add the signal to the set of signals to be ignored with the signal + * handler executes. + */ + + ret = sigaddset(&act.sa_mask, signo); + if (ret < 0) + { + /* Would happen if signo were invalid */ + + return SIG_ERR; + } + } + + /* Set the signal disposition */ + + ret = sigaction(signo, &act, &oact); + + /* Upon successful completion, sigset() will the signal's previous + * disposition. Otherwise, SIG_ERR will be returned and errno set to + * indicate the error. + */ + + if (ret == OK) + { + return oact.sa_handler; + } + + return SIG_ERR; +} -- cgit v1.2.3