mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 07:12:54 +08:00
This commit moves all of the libraries under a common directory called libs/. This most certainly break libcxx and uClibc++ for now.
Squashed commit of the following:
libs/libxx: Fix some confusing in naming. If the directory is called libxx, then the library must be libxx.a (unless perhaps LIBCXX is selected).
libs/: Fix paths in moved library directories.
libs: Brute force move of libc, libnx, and libxx to libs. Cannot yet build it in that configuration.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
############################################################################
|
||||
# libs/libc/signal/Make.defs
|
||||
#
|
||||
# Copyright (C) 2011-2012, 2016-2017 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_DISABLE_SIGNALS),y)
|
||||
|
||||
# Add the signal C files to the build
|
||||
|
||||
CSRCS += sig_addset.c sig_delset.c sig_emptyset.c sig_fillset.c
|
||||
CSRCS += sig_hold.c sig_ignore.c sig_ismember.c sig_pause.c sig_raise.c
|
||||
CSRCS += sig_relse.c sig_set.c signal.c sigwait.c
|
||||
|
||||
# Add the signal directory to the build
|
||||
|
||||
DEPPATH += --dep-path signal
|
||||
VPATH += :signal
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/signal/sig_addset.c
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2011 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>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sigaddset
|
||||
*
|
||||
* Description:
|
||||
* This function adds the signal specified by signo to the signal set
|
||||
* specified by set.
|
||||
*
|
||||
* Input Parameters:
|
||||
* set - Signal set to add signal to
|
||||
* signo - Signal to add
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK), or -1 (ERROR) if the signal number is invalid.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sigaddset(FAR sigset_t *set, int signo)
|
||||
{
|
||||
/* Verify the signal */
|
||||
|
||||
if (!GOOD_SIGNO(signo))
|
||||
{
|
||||
set_errno(EINVAL);
|
||||
return ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add the signal to the set */
|
||||
|
||||
*set |= SIGNO2SET(signo);
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/signal/sig_delset.c
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2011 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>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sigdelset
|
||||
*
|
||||
* Description:
|
||||
* This function deletes the signal specified by signo from the signal
|
||||
* set specified by the 'set' argument.
|
||||
*
|
||||
* Input Parameters:
|
||||
* set - Signal set to delete the signal from
|
||||
* signo - Signal to delete
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK), or -1 (ERROR) if the signal number is invalid.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sigdelset(FAR sigset_t *set, int signo)
|
||||
{
|
||||
/* Verify the signal */
|
||||
|
||||
if (!GOOD_SIGNO(signo))
|
||||
{
|
||||
set_errno(EINVAL);
|
||||
return ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Remove the signal from the set */
|
||||
|
||||
*set &= ~SIGNO2SET(signo);
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/signal/sig_emptyset.c
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2011 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: sigemptyset
|
||||
*
|
||||
* Description:
|
||||
* This function initializes the signal set specified by set such that all
|
||||
* signals are excluded.
|
||||
*
|
||||
* Input Parameters:
|
||||
* set - Signal set to initialize
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK), or -1 (ERROR) if the signal set cannot be initialized.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sigemptyset(FAR sigset_t *set)
|
||||
{
|
||||
*set = NULL_SIGNAL_SET;
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/signal/sig_fillset.c
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2011 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>
|
||||
|
||||
/****************************************************************************
|
||||
* Publics Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sigfillset
|
||||
*
|
||||
* Description:
|
||||
* This function initializes the signal set specified by set such that all
|
||||
* signals are included.
|
||||
*
|
||||
* Input Parameters:
|
||||
* set - Signal set to initalize
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK), or -1 (ERROR) if the signal set cannot be initialized.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sigfillset(FAR sigset_t *set)
|
||||
{
|
||||
*set = ALL_SIGNAL_SET;
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
* libs/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;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/****************************************************************************
|
||||
* libs/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;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/signal/sig_ismember.c
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2011 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: sigismember
|
||||
*
|
||||
* Description:
|
||||
* This function tests whether the signal specified by signo is a member
|
||||
* of the set specified by set.
|
||||
*
|
||||
* Input Parameters:
|
||||
* set - Signal set to test
|
||||
* signo - Signal to test for
|
||||
*
|
||||
* Returned Value:
|
||||
* 1 (true), if the specified signal is a member of the set,
|
||||
* 0 (OK or FALSE), if it is not, or
|
||||
* -1 (ERROR) if the signal number is invalid.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sigismember(FAR const sigset_t *set, int signo)
|
||||
{
|
||||
int ret = ERROR;
|
||||
|
||||
/* Verify the signal */
|
||||
|
||||
if (GOOD_SIGNO(signo))
|
||||
{
|
||||
/* Check if the signal is in the set */
|
||||
|
||||
ret = ((*set & SIGNO2SET(signo)) != 0);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
* libs/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;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/signal/sig_raise.c
|
||||
*
|
||||
* Copyright (C) 2016 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>
|
||||
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sig_raise
|
||||
*
|
||||
* Description:
|
||||
* The raise() function sends the signal signo to the executing thread or
|
||||
* process. If a signal handler is called, the raise() function does not
|
||||
* return until after the signal handler does.
|
||||
*
|
||||
* If the implementation supports the Threads option, the effect of the
|
||||
* raise() function is equivalent to calling:
|
||||
*
|
||||
* pthread_kill(pthread_self(), signo);
|
||||
*
|
||||
* except that on failures, -1 (ERROR) is returned and the errno() variable
|
||||
* is set accordingly. Otherwise, the effect of the raise() function is
|
||||
* equivalent to calling:
|
||||
*
|
||||
* kill(getpid(), signo)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int raise(int signo)
|
||||
{
|
||||
#ifndef CONFIG_DISABLE_PTHREAD
|
||||
int errcode = pthread_kill(pthread_self(), signo);
|
||||
if (errcode != OK)
|
||||
{
|
||||
DEBUGASSERT(errcode > 0);
|
||||
set_errno(errcode);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
#else
|
||||
return kill(getpid(), signo);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
* libs/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' from the calling process'
|
||||
* signal mask.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sigrelse(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;
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/signal/sig_set.c
|
||||
*
|
||||
* Copyright (C) 2015-2017 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>
|
||||
|
||||
#include <signal.h>
|
||||
#include <assert.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sigset
|
||||
*
|
||||
* Description:
|
||||
* The signal() function will modify signal dispositions. The 'signo'
|
||||
* argument specifies the signal. The 'func' argument specifies the
|
||||
* signal's disposition, which may be SIG_DFL, SIG_IGN, or the address
|
||||
* of a signal handler.
|
||||
*
|
||||
* The System V sigset function is very similar to the (obsolete) POSIX
|
||||
* signal() function except that it includes additional managment of the
|
||||
* tasks' signal mask. This function is then simply a wrapper around
|
||||
* signal() with this additional signal mask logic added.
|
||||
*
|
||||
* - The sigset set function also accepts the SIG_HOLD value for 'func':
|
||||
* If 'func' is equal to SIG_HOLD, 'signo' will be added to the signal
|
||||
* mask of the calling process and 'signo's disposition will remain
|
||||
* unchanged.
|
||||
* - If 'func' is not equal to SIG_HOLD, 'signo' will be removed from the
|
||||
* signal mask of the calling process.
|
||||
*
|
||||
* Input Parameters:
|
||||
* signo - Identifies the signal to operate on
|
||||
* func - The new disposition of the signal
|
||||
*
|
||||
* Returned Value:
|
||||
* Upon successful completion, sigset() shall return SIG_HOLD if the
|
||||
* signal had been blocked and the signal's previous disposition if it had
|
||||
* not been blocked. Otherwise, SIG_ERR shall be returned and errno set to
|
||||
* indicate the error.
|
||||
*
|
||||
* Hmm.. this wording is not clear to me. I assume this to mean:
|
||||
*
|
||||
* if (func == SIG_HOLD)
|
||||
* {
|
||||
* Set mask
|
||||
* if (mask successfuly set)
|
||||
* {
|
||||
* return SIG_HOLD
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* return SIG_ERR
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* Set disposition
|
||||
* if (disposition successfuly set)
|
||||
* {
|
||||
* return old disposition
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* return SIG_ERR
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* But you could also argue that the English means to return SIG_HOLD in
|
||||
* any case is the signal is blocked. And, in that case would you set the
|
||||
* disposition or not? Unclear.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
_sa_handler_t sigset(int signo, _sa_handler_t func)
|
||||
{
|
||||
_sa_handler_t disposition;
|
||||
sigset_t set;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(GOOD_SIGNO(signo) && func != SIG_ERR);
|
||||
|
||||
(void)sigemptyset(&set);
|
||||
(void)sigaddset(&set, signo);
|
||||
|
||||
/* Check if we are being asked to block the signal */
|
||||
|
||||
if (func == SIG_HOLD)
|
||||
{
|
||||
ret = sigprocmask(SIG_BLOCK, &set, NULL);
|
||||
disposition = ret < 0 ? SIG_ERR : SIG_HOLD;
|
||||
}
|
||||
|
||||
/* No.. then signal can handle the other cases */
|
||||
|
||||
else
|
||||
{
|
||||
/* Set the signal handler disposition */
|
||||
|
||||
disposition = signal(signo, func);
|
||||
if (disposition != SIG_ERR)
|
||||
{
|
||||
/* And unblock the signal */
|
||||
|
||||
ret = sigprocmask(SIG_UNBLOCK, &set, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Restore the original signal disposition and return and
|
||||
* error.
|
||||
*/
|
||||
|
||||
(void)signal(signo, disposition);
|
||||
disposition = SIG_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return disposition;
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/signal/signal.c
|
||||
*
|
||||
* Copyright (C) 2015-2017 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>
|
||||
|
||||
#include <signal.h>
|
||||
#include <assert.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: signal
|
||||
*
|
||||
* Description:
|
||||
* The signal() function will modify signal dispositions. The 'signo'
|
||||
* argument specifies the signal. The 'func' argument specifies the
|
||||
* signal's disposition, which may be SIG_DFL, SIG_IGN, or the address
|
||||
* of a signal handler. If 'func' 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.
|
||||
*
|
||||
* Input Parameters:
|
||||
* signo - Identifies the signal to operate on
|
||||
* func - The new disposition of the signal
|
||||
*
|
||||
* Returned Value:
|
||||
* Upon successful completion, signal() will return the previous
|
||||
* disposition of the signal handling. Otherwise, SIG_ERR will be returned
|
||||
* and errno set to indicate the nature of the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
_sa_handler_t signal(int signo, _sa_handler_t func)
|
||||
{
|
||||
struct sigaction act;
|
||||
struct sigaction oact;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(GOOD_SIGNO(signo) && func != SIG_ERR && func != SIG_HOLD);
|
||||
|
||||
/* Initialize the sigaction structure */
|
||||
|
||||
act.sa_handler = func;
|
||||
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 (func != SIG_DFL /* && func != SIG_IGN */)
|
||||
{
|
||||
/* Add the signal to the set of signals to be ignored when the signal
|
||||
* handler executes.
|
||||
*/
|
||||
|
||||
ret = sigaddset(&act.sa_mask, signo);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Would happen if signo were invalid */
|
||||
|
||||
return (_sa_handler_t)SIG_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the signal disposition */
|
||||
|
||||
ret = sigaction(signo, &act, &oact);
|
||||
|
||||
/* Upon successful completion, signal() 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 (_sa_handler_t)SIG_ERR;
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/signal/sigwait.c
|
||||
*
|
||||
* Copyright (C) 2017 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>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sigwait
|
||||
*
|
||||
* Description:
|
||||
* The sigwait() function selects a pending signal from set, atomically
|
||||
* clears it from the system's set of pending signals, and returns that
|
||||
* signal number in the location referenced by sig. If prior to the call
|
||||
* to sigwait() there are multiple pending instances of a single signal
|
||||
* number, it is implementation-dependent whether upon successful return
|
||||
* there are any remaining pending signals for that signal number. If the
|
||||
* implementation supports queued signals and there are multiple signals
|
||||
* queued for the signal number selected, the first such queued signal
|
||||
* causes a return from sigwait() and the remainder remain queued. If no
|
||||
* signal in set is pending at the time of the call, the thread is
|
||||
* suspended until one or more becomes pending. The signals defined by set
|
||||
* will been blocked at the time of the call to sigwait(); otherwise the
|
||||
* behavior is undefined. The effect of sigwait() on the signal actions
|
||||
* for the signals in set is unspecified.
|
||||
*
|
||||
* If more than one thread is using sigwait() to wait for the same
|
||||
* signal, no more than one of these threads will return from sigwait()
|
||||
* with the signal number. Which thread returns from sigwait() if more
|
||||
* than a single thread is waiting is unspecified.
|
||||
*
|
||||
* Should any of the multiple pending signals in the range SIGRTMIN to
|
||||
* SIGRTMAX be selected, it shall be the lowest numbered one. The selection
|
||||
* order between realtime and non-realtime signals, or between multiple
|
||||
* pending non-realtime signals, is unspecified.
|
||||
*
|
||||
* Input Parameters:
|
||||
* set - The set of pending signals to wait for
|
||||
* sig - The location in which to return the pending signal number.
|
||||
*
|
||||
* Returned Value:
|
||||
* Upon successful completion, sigwait() stores the signal number of the
|
||||
* received signal at the location referenced by sig and returns zero.
|
||||
* Otherwise, an error number is returned to indicate the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int sigwait(FAR const sigset_t *set, FAR int *sig)
|
||||
{
|
||||
int signo;
|
||||
|
||||
DEBUGASSERT(set != NULL && sig != NULL);
|
||||
|
||||
/* The standard sigwait() function behaves that same as sigwainfo() with
|
||||
* the info argument set to NULL.
|
||||
*/
|
||||
|
||||
signo = sigwaitinfo(set, NULL);
|
||||
if (signo < 0)
|
||||
{
|
||||
/* If sigwaitinfo() fails, return the error number */
|
||||
|
||||
return get_errno();
|
||||
}
|
||||
|
||||
/* Return the signal number in the user provided location */
|
||||
|
||||
*sig = signo;
|
||||
return OK;
|
||||
}
|
||||
Reference in New Issue
Block a user