Add sighold(), sigrelse(), sigignore(), and sigpause().
This commit is contained in:
parent
f6b05529da
commit
4c60fe666c
@ -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 <gnutt@nuttx.org>
|
||||
*
|
||||
* 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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -38,7 +38,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
72
libc/signal/sig_hold.c
Normal file
72
libc/signal/sig_hold.c
Normal file
@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
* libc/signal/sig_hold.c
|
||||
*
|
||||
* Copyright (C) 2015 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 <signal.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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;
|
||||
}
|
71
libc/signal/sig_ignore.c
Executable file
71
libc/signal/sig_ignore.c
Executable file
@ -0,0 +1,71 @@
|
||||
/****************************************************************************
|
||||
* libc/signal/sig_ignore.c
|
||||
*
|
||||
* Copyright (C) 2015 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 <signal.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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;
|
||||
}
|
84
libc/signal/sig_pause.c
Executable file
84
libc/signal/sig_pause.c
Executable file
@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
* libc/signal/sig_ignore.c
|
||||
*
|
||||
* Copyright (C) 2015 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 <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sched.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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;
|
||||
}
|
72
libc/signal/sig_relse.c
Executable file
72
libc/signal/sig_relse.c
Executable file
@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
* libc/signal/sig_relse.c
|
||||
*
|
||||
* Copyright (C) 2015 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 <signal.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user