1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief POSIX Signals Check Signal |
---|
5 | * @ingroup POSIX_SIGNALS |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2007. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #if defined(RTEMS_DEBUG) |
---|
22 | #include <assert.h> |
---|
23 | #endif |
---|
24 | #include <errno.h> |
---|
25 | #include <pthread.h> |
---|
26 | #include <signal.h> |
---|
27 | #include <string.h> |
---|
28 | |
---|
29 | #include <rtems/system.h> |
---|
30 | #include <rtems/score/isr.h> |
---|
31 | #include <rtems/score/thread.h> |
---|
32 | #include <rtems/score/wkspace.h> |
---|
33 | #include <rtems/seterr.h> |
---|
34 | #include <rtems/posix/threadsup.h> |
---|
35 | #include <rtems/posix/psignalimpl.h> |
---|
36 | #include <rtems/posix/pthreadimpl.h> |
---|
37 | #include <rtems/posix/time.h> |
---|
38 | #include <stdio.h> |
---|
39 | |
---|
40 | bool _POSIX_signals_Check_signal( |
---|
41 | POSIX_API_Control *api, |
---|
42 | int signo, |
---|
43 | bool is_global |
---|
44 | ) |
---|
45 | { |
---|
46 | siginfo_t siginfo_struct; |
---|
47 | sigset_t saved_signals_blocked; |
---|
48 | Thread_Wait_information stored_thread_wait_information; |
---|
49 | Thread_Control *executing; |
---|
50 | |
---|
51 | if ( ! _POSIX_signals_Clear_signals( api, signo, &siginfo_struct, |
---|
52 | is_global, true, true ) ) |
---|
53 | return false; |
---|
54 | |
---|
55 | /* |
---|
56 | * Since we made a union of these, only one test is necessary but this is |
---|
57 | * safer. |
---|
58 | */ |
---|
59 | #if defined(RTEMS_DEBUG) |
---|
60 | assert( _POSIX_signals_Vectors[ signo ].sa_handler || |
---|
61 | _POSIX_signals_Vectors[ signo ].sa_sigaction ); |
---|
62 | #endif |
---|
63 | |
---|
64 | /* |
---|
65 | * Just to prevent sending a signal which is currently being ignored. |
---|
66 | */ |
---|
67 | if ( _POSIX_signals_Vectors[ signo ].sa_handler == SIG_IGN ) |
---|
68 | return false; |
---|
69 | |
---|
70 | /* |
---|
71 | * Block the signals requested in sa_mask |
---|
72 | */ |
---|
73 | saved_signals_blocked = api->signals_blocked; |
---|
74 | api->signals_blocked |= _POSIX_signals_Vectors[ signo ].sa_mask; |
---|
75 | |
---|
76 | executing = _Thread_Get_executing(); |
---|
77 | |
---|
78 | /* |
---|
79 | * We have to save the blocking information of the current wait queue |
---|
80 | * because the signal handler may subsequently go on and put the thread |
---|
81 | * on a wait queue, for its own purposes. |
---|
82 | */ |
---|
83 | memcpy( &stored_thread_wait_information, &executing->Wait, |
---|
84 | sizeof( stored_thread_wait_information )); |
---|
85 | |
---|
86 | /* |
---|
87 | * Here, the signal handler function executes |
---|
88 | */ |
---|
89 | switch ( _POSIX_signals_Vectors[ signo ].sa_flags ) { |
---|
90 | case SA_SIGINFO: |
---|
91 | (*_POSIX_signals_Vectors[ signo ].sa_sigaction)( |
---|
92 | signo, |
---|
93 | &siginfo_struct, |
---|
94 | NULL /* context is undefined per 1003.1b-1993, p. 66 */ |
---|
95 | ); |
---|
96 | break; |
---|
97 | default: |
---|
98 | (*_POSIX_signals_Vectors[ signo ].sa_handler)( signo ); |
---|
99 | break; |
---|
100 | } |
---|
101 | |
---|
102 | /* |
---|
103 | * Restore the blocking information |
---|
104 | */ |
---|
105 | memcpy( &executing->Wait, &stored_thread_wait_information, |
---|
106 | sizeof( executing->Wait )); |
---|
107 | |
---|
108 | /* |
---|
109 | * Restore the previous set of blocked signals |
---|
110 | */ |
---|
111 | api->signals_blocked = saved_signals_blocked; |
---|
112 | |
---|
113 | return true; |
---|
114 | } |
---|