Rev 1123 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1099 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /** |
||
20 | ------------ |
||
1547 | pj | 21 | CVS : $Id: sig.c,v 1.4 2005-01-08 14:31:38 pj Exp $ |
1099 | pj | 22 | |
23 | File: $File$ |
||
1547 | pj | 24 | Revision: $Revision: 1.4 $ |
25 | Last update: $Date: 2005-01-08 14:31:38 $ |
||
1099 | pj | 26 | ------------ |
27 | **/ |
||
28 | |||
29 | /* |
||
30 | * Copyright (C) 2000 Paolo Gai and Giorgio Buttazzo |
||
31 | * |
||
32 | * This program is free software; you can redistribute it and/or modify |
||
33 | * it under the terms of the GNU General Public License as published by |
||
34 | * the Free Software Foundation; either version 2 of the License, or |
||
35 | * (at your option) any later version. |
||
36 | * |
||
37 | * This program is distributed in the hope that it will be useful, |
||
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
40 | * GNU General Public License for more details. |
||
41 | * |
||
42 | * You should have received a copy of the GNU General Public License |
||
43 | * along with this program; if not, write to the Free Software |
||
44 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
45 | * |
||
46 | */ |
||
47 | |||
48 | /* |
||
49 | Test Number 5: |
||
50 | |||
51 | this test is a simple main() function with one other task |
||
52 | |||
53 | This test can be useful to test functions like: |
||
54 | |||
55 | sys_gettime |
||
56 | sigemptyset |
||
57 | sigaddset |
||
58 | hartik_deliver_pending_signals |
||
59 | task_sigmask |
||
60 | sigaction |
||
61 | sigqueue |
||
62 | task_signal |
||
63 | */ |
||
64 | |||
65 | #include "kernel/kern.h" |
||
66 | |||
67 | |||
68 | TASK goofy(void *arg) |
||
69 | { |
||
70 | struct timespec t; |
||
71 | |||
72 | cprintf("Goofy: waiting 2 secs...\n"); |
||
73 | |||
74 | do { |
||
75 | sys_gettime(&t); |
||
76 | } while (t.tv_sec < 2); // wait until 2 sec |
||
77 | |||
78 | cprintf("Goofy: ok, I'm ready :-)\n"); |
||
79 | |||
80 | return 0; |
||
81 | } |
||
82 | |||
1123 | pj | 83 | void catchit_RT(int signo, siginfo_t *info, void *extra) |
1099 | pj | 84 | { |
1123 | pj | 85 | cprintf("RT signal: Current Running Task = %d signo=%d code=%d value=%d from pid=%d\n", |
1099 | pj | 86 | exec_shadow, |
87 | info->si_signo, info->si_code, |
||
88 | info->si_value.sival_int, info->si_task); |
||
89 | } |
||
90 | |||
1123 | pj | 91 | void catchit(int signo) |
92 | { |
||
93 | cprintf("RT signal: Current Running Task = %d signo=%d\n", |
||
94 | exec_shadow, signo); |
||
95 | } |
||
1099 | pj | 96 | |
97 | int main(int argc, char **argv) |
||
98 | { |
||
99 | struct timespec t; |
||
100 | NRT_TASK_MODEL m; |
||
101 | PID p2; |
||
102 | |||
103 | sigset_t newmask; |
||
104 | sigset_t oldmask; |
||
105 | struct sigaction action; |
||
106 | union sigval sval; |
||
107 | |||
108 | clear(); |
||
109 | |||
110 | /* Set the signal action */ |
||
111 | action.sa_flags = SA_SIGINFO; |
||
1123 | pj | 112 | action.sa_sigaction = catchit_RT; |
1099 | pj | 113 | action.sa_handler = 0; |
114 | action.sa_mask = 0; |
||
115 | |||
116 | if (sigaction(SIGUSR1, &action, NULL) == -1) { |
||
117 | perror("Error using sigaction."); |
||
118 | return -1; |
||
119 | } |
||
120 | |||
121 | action.sa_flags = 0; |
||
1119 | pj | 122 | action.sa_handler = (void (*)(int))catchit; |
1099 | pj | 123 | |
124 | if (sigaction(SIGILL, &action, NULL) == -1) { |
||
125 | perror("Error using sigaction."); |
||
126 | return -1; |
||
127 | } |
||
128 | |||
129 | /* create another task */ |
||
130 | nrt_task_default_model(m); |
||
131 | nrt_task_def_group(m,1); |
||
132 | |||
133 | p2 = task_create("goofy", goofy, &m, NULL); |
||
134 | if (p2 == NIL) |
||
135 | { |
||
136 | cprintf("Can't create goofy task...\n"); |
||
137 | return 1; |
||
138 | } |
||
139 | |||
140 | group_activate(1); |
||
141 | |||
142 | /* block the signal for the main task */ |
||
143 | sigemptyset(&newmask); |
||
144 | sigaddset(&newmask,SIGUSR1); |
||
145 | task_sigmask(SIG_BLOCK, &newmask, &oldmask); // pthread_sigmask |
||
146 | |||
147 | cprintf("main: Sending 2 signals ...\n"); |
||
148 | |||
149 | sval.sival_int = 123; |
||
150 | sigqueue(0,SIGUSR1,sval); |
||
151 | sval.sival_int = 999; |
||
152 | sigqueue(0,SIGUSR1,sval); |
||
153 | |||
154 | cprintf("main: Now sending a signal to myself," |
||
155 | " then wait until 4 secs...\n"); |
||
156 | |||
157 | task_signal(0 /* main */, SIGILL); // pthread_kill |
||
158 | |||
159 | NULL_TIMESPEC(&t); |
||
160 | do { |
||
161 | sys_gettime(&t); |
||
162 | } while (t.tv_sec < 4); // wait until 4 s |
||
163 | |||
164 | cprintf("main: ending...\n"); |
||
165 | |||
166 | return 0; |
||
167 | } |