diff --git a/include/signal.h b/include/signal.h index ffb77e079c..8dd86705a2 100644 --- a/include/signal.h +++ b/include/signal.h @@ -1,7 +1,7 @@ /******************************************************************************** * include/signal.h * - * Copyright (C) 2007-2009, 2011, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2013-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -262,8 +262,12 @@ 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); +int sigignore(int signo); int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset); +int sigpause(int signo); +int sigrelse(int signo); int sigpending(FAR sigset_t *set); +int sighold(int signo); int sigsuspend(FAR const sigset_t *sigmask); int sigwaitinfo(FAR const sigset_t *set, FAR struct siginfo *value); int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *value, diff --git a/libc/signal/Make.defs b/libc/signal/Make.defs index fe7eb180e7..b79cca478c 100644 --- a/libc/signal/Make.defs +++ b/libc/signal/Make.defs @@ -37,7 +37,8 @@ ifneq ($(CONFIG_DISABLE_SIGNALS),y) # Add the signal C files to the build -CSRCS += sig_emptyset.c sig_fillset.c sig_addset.c sig_delset.c sig_ismember.c +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 # Add the signal directory to the build diff --git a/libc/signal/sig_emptyset.c b/libc/signal/sig_emptyset.c index c41ae65a4c..1899302bf0 100644 --- a/libc/signal/sig_emptyset.c +++ b/libc/signal/sig_emptyset.c @@ -38,7 +38,6 @@ ****************************************************************************/ #include -#include /**************************************************************************** * Public Functions diff --git a/libc/signal/sig_hold.c b/libc/signal/sig_hold.c new file mode 100644 index 0000000000..2b48075f1f --- /dev/null +++ b/libc/signal/sig_hold.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * libc/signal/sig_hold.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: sighold + * + * Description: + * The sighold() function will add 'signo' to the calling process' signal + * mask. + * + ****************************************************************************/ + +int sighold(int signo) +{ + sigset_t set; + int ret; + + /* Create a set of signals with only the signal to be blocked */ + + (void)sigemptyset(&set); + ret = sigaddset(&set, signo); + if (ret == OK) + { + /* Block the signal */ + + ret = sigprocmask(SIG_BLOCK, &set, NULL); + } + + return ret; +} diff --git a/libc/signal/sig_ignore.c b/libc/signal/sig_ignore.c new file mode 100755 index 0000000000..a7f722fc62 --- /dev/null +++ b/libc/signal/sig_ignore.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * libc/signal/sig_ignore.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: sigignore + * + * Description: + * The sigignore() function will set the disposition of 'signo' to SIG_IGN. + * + ****************************************************************************/ + +int sigignore(int signo) +{ + struct sigaction act; + int ret; + + /* Ignore the signal */ + + act.sa_handler = SIG_IGN; + act.sa_flags = 0; + + ret = sigemptyset(&act.sa_mask); + if (ret == OK) + { + ret = sigaction(signo, &act, NULL); + } + + return ret; +} diff --git a/libc/signal/sig_pause.c b/libc/signal/sig_pause.c new file mode 100755 index 0000000000..71edc5f5bc --- /dev/null +++ b/libc/signal/sig_pause.c @@ -0,0 +1,84 @@ +/**************************************************************************** + * libc/signal/sig_ignore.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 +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sigpause + * + * Description: + * The sigpause() will remove sig 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. + * + ****************************************************************************/ + +int sigpause(int signo) +{ + sigset_t set; + int ret; + + /* Get the current set of blocked signals */ + + sched_lock(); + ret = sigprocmask(SIG_SETMASK, NULL, &set); + if (ret == OK) + { + /* Remove the 'signo' from the set of blocked signals */ + + ret = sigdelset(&set, signo); + } + + /* Let sigsuspend do the rest of the job */ + + if (ret == OK) + { + ret = sigsuspend(&set); + } + + sched_unlock(); + return ret; +} diff --git a/libc/signal/sig_relse.c b/libc/signal/sig_relse.c new file mode 100755 index 0000000000..c17731bfe8 --- /dev/null +++ b/libc/signal/sig_relse.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * libc/signal/sig_relse.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: sigrelse + * + * Description: + * The sigrelse() function will remove 'signo' to the calling process' signal + * mask. + * + ****************************************************************************/ + +int sighold(int signo) +{ + sigset_t set; + int ret; + + /* Create a set of signals with only the signal to be unblocked */ + + (void)sigemptyset(&set); + ret = sigaddset(&set, signo); + if (ret == OK) + { + /* Unblock the signal */ + + ret = sigprocmask(SIG_UNBLOCK, &set, NULL); + } + + return ret; +}