1 | /* |
---|
2 | * COPYRIGHT (c) 1989-1999. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.OARcorp.com/rtems/license.html. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #define CONFIGURE_INIT |
---|
13 | #include "system.h" |
---|
14 | #include <signal.h> |
---|
15 | |
---|
16 | volatile int Signal_occurred; |
---|
17 | volatile int Signal_count; |
---|
18 | |
---|
19 | void Signal_handler( |
---|
20 | int signo |
---|
21 | ) |
---|
22 | { |
---|
23 | Signal_count++; |
---|
24 | printf( |
---|
25 | "Signal: %d caught by 0x%x (%d)\n", |
---|
26 | signo, |
---|
27 | pthread_self(), |
---|
28 | Signal_count |
---|
29 | ); |
---|
30 | Signal_occurred = 1; |
---|
31 | } |
---|
32 | |
---|
33 | void *POSIX_Init( |
---|
34 | void *argument |
---|
35 | ) |
---|
36 | { |
---|
37 | int status; |
---|
38 | struct timespec tv; |
---|
39 | struct timespec tr; |
---|
40 | struct sigaction act; |
---|
41 | sigset_t mask; |
---|
42 | sigset_t pending_set; |
---|
43 | |
---|
44 | puts( "\n\n*** POSIX TEST 2 ***" ); |
---|
45 | |
---|
46 | /* set the time of day, and print our buffer in multiple ways */ |
---|
47 | |
---|
48 | set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 ); |
---|
49 | |
---|
50 | /* get id of this thread */ |
---|
51 | |
---|
52 | Init_id = pthread_self(); |
---|
53 | printf( "Init's ID is 0x%08x\n", Init_id ); |
---|
54 | |
---|
55 | /* install a signal handler */ |
---|
56 | |
---|
57 | status = sigemptyset( &act.sa_mask ); |
---|
58 | assert( !status ); |
---|
59 | |
---|
60 | act.sa_handler = Signal_handler; |
---|
61 | act.sa_flags = 0; |
---|
62 | |
---|
63 | sigaction( SIGUSR1, &act, NULL ); |
---|
64 | |
---|
65 | /* simple signal to self */ |
---|
66 | |
---|
67 | Signal_count = 0; |
---|
68 | Signal_occurred = 0; |
---|
69 | |
---|
70 | status = pthread_kill( Init_id, SIGUSR1 ); |
---|
71 | assert( !status ); |
---|
72 | |
---|
73 | Signal_occurred = 0; |
---|
74 | |
---|
75 | /* now block the signal, send it, see if it is pending, and unblock it */ |
---|
76 | |
---|
77 | status = sigemptyset( &mask ); |
---|
78 | assert( !status ); |
---|
79 | |
---|
80 | status = sigaddset( &mask, SIGUSR1 ); |
---|
81 | assert( !status ); |
---|
82 | |
---|
83 | printf( "Init: Block SIGUSR1\n" ); |
---|
84 | status = sigprocmask( SIG_BLOCK, &mask, NULL ); |
---|
85 | assert( !status ); |
---|
86 | |
---|
87 | status = sigpending( &pending_set ); |
---|
88 | assert( !status ); |
---|
89 | printf( "Init: Signals pending 0x%08x\n", pending_set ); |
---|
90 | |
---|
91 | |
---|
92 | printf( "Init: send SIGUSR1 to self\n" ); |
---|
93 | status = pthread_kill( Init_id, SIGUSR1 ); |
---|
94 | assert( !status ); |
---|
95 | |
---|
96 | status = sigpending( &pending_set ); |
---|
97 | assert( !status ); |
---|
98 | printf( "Init: Signals pending 0x%08x\n", pending_set ); |
---|
99 | |
---|
100 | printf( "Init: Unblock SIGUSR1\n" ); |
---|
101 | status = sigprocmask( SIG_UNBLOCK, &mask, NULL ); |
---|
102 | assert( !status ); |
---|
103 | |
---|
104 | /* create a thread */ |
---|
105 | |
---|
106 | status = pthread_create( &Task_id, NULL, Task_1_through_3, NULL ); |
---|
107 | assert( !status ); |
---|
108 | |
---|
109 | /* |
---|
110 | * Loop for 5 seconds seeing how many signals we catch |
---|
111 | */ |
---|
112 | |
---|
113 | tr.tv_sec = 5; |
---|
114 | tr.tv_nsec = 0; |
---|
115 | |
---|
116 | do { |
---|
117 | tv = tr; |
---|
118 | |
---|
119 | Signal_occurred = 0; |
---|
120 | |
---|
121 | status = nanosleep ( &tv, &tr ); |
---|
122 | |
---|
123 | if ( status == -1 ) { |
---|
124 | assert( errno == EINTR ); |
---|
125 | assert( tr.tv_nsec || tr.tv_sec ); |
---|
126 | } else if ( !status ) { |
---|
127 | assert( !tr.tv_nsec && !tr.tv_sec ); |
---|
128 | } |
---|
129 | |
---|
130 | printf( |
---|
131 | "Init: signal was %sprocessed with %d:%d time remaining\n", |
---|
132 | (Signal_occurred) ? "" : "not ", |
---|
133 | (int) tr.tv_sec, |
---|
134 | (int) tr.tv_nsec |
---|
135 | ); |
---|
136 | |
---|
137 | } while ( tr.tv_sec || tr.tv_nsec ); |
---|
138 | |
---|
139 | /* exit this thread */ |
---|
140 | |
---|
141 | puts( "*** END OF POSIX TEST 2 ***" ); |
---|
142 | rtems_test_exit( 0 ); |
---|
143 | |
---|
144 | return NULL; /* just so the compiler thinks we returned something */ |
---|
145 | } |
---|