1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup POSIXAPI |
---|
7 | * |
---|
8 | * @brief Allows calling process to examine action of a Specific Signal |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * 3.3.4 Examine and Change Signal Action, P1003.1b-1993, p. 70 |
---|
13 | * |
---|
14 | * COPYRIGHT (c) 1989-1999. |
---|
15 | * On-Line Applications Research Corporation (OAR). |
---|
16 | * |
---|
17 | * Redistribution and use in source and binary forms, with or without |
---|
18 | * modification, are permitted provided that the following conditions |
---|
19 | * are met: |
---|
20 | * 1. Redistributions of source code must retain the above copyright |
---|
21 | * notice, this list of conditions and the following disclaimer. |
---|
22 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
23 | * notice, this list of conditions and the following disclaimer in the |
---|
24 | * documentation and/or other materials provided with the distribution. |
---|
25 | * |
---|
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
36 | * POSSIBILITY OF SUCH DAMAGE. |
---|
37 | */ |
---|
38 | |
---|
39 | #ifdef HAVE_CONFIG_H |
---|
40 | #include "config.h" |
---|
41 | #endif |
---|
42 | |
---|
43 | #include <pthread.h> |
---|
44 | #include <signal.h> |
---|
45 | #include <errno.h> |
---|
46 | |
---|
47 | #include <rtems/posix/psignalimpl.h> |
---|
48 | #include <rtems/seterr.h> |
---|
49 | |
---|
50 | int sigaction( |
---|
51 | int sig, |
---|
52 | const struct sigaction *__restrict act, |
---|
53 | struct sigaction *__restrict oact |
---|
54 | ) |
---|
55 | { |
---|
56 | Thread_queue_Context queue_context; |
---|
57 | |
---|
58 | if ( !sig ) |
---|
59 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
60 | |
---|
61 | if ( !is_valid_signo(sig) ) |
---|
62 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
63 | |
---|
64 | /* |
---|
65 | * Some signals cannot be ignored (P1003.1b-1993, pp. 70-72 and references. |
---|
66 | * |
---|
67 | * NOTE: Solaris documentation claims to "silently enforce" this which |
---|
68 | * contradicts the POSIX specification. |
---|
69 | */ |
---|
70 | |
---|
71 | if ( sig == SIGKILL ) |
---|
72 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
73 | |
---|
74 | _Thread_queue_Context_initialize( &queue_context ); |
---|
75 | _POSIX_signals_Acquire( &queue_context ); |
---|
76 | |
---|
77 | if ( oact ) |
---|
78 | *oact = _POSIX_signals_Vectors[ sig ]; |
---|
79 | |
---|
80 | /* |
---|
81 | * Evaluate the new action structure and set the global signal vector |
---|
82 | * appropriately. |
---|
83 | */ |
---|
84 | |
---|
85 | if ( act ) { |
---|
86 | |
---|
87 | /* |
---|
88 | * Unless the user is installing the default signal actions, then |
---|
89 | * we can just copy the provided sigaction structure into the vectors. |
---|
90 | */ |
---|
91 | |
---|
92 | if ( act->sa_handler == SIG_DFL ) { |
---|
93 | _POSIX_signals_Vectors[ sig ] = _POSIX_signals_Default_vectors[ sig ]; |
---|
94 | } else { |
---|
95 | _POSIX_signals_Clear_process_signals( sig ); |
---|
96 | _POSIX_signals_Vectors[ sig ] = *act; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | _POSIX_signals_Release( &queue_context ); |
---|
101 | |
---|
102 | return 0; |
---|
103 | } |
---|