Subversion Repositories shark

Rev

Rev 1119 | Go to most recent revision | 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
 ------------
1123 pj 21
 CVS :        $Id: sig.c,v 1.3 2003-01-07 17:10:15 pj Exp $
1099 pj 22
 
23
 File:        $File$
1123 pj 24
 Revision:    $Revision: 1.3 $
25
 Last update: $Date: 2003-01-07 17:10:15 $
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
 sys_end
60
 task_sigmask
61
 sigaction
62
 sigqueue
63
 task_signal
64
*/
65
 
66
#include "kernel/kern.h"
67
 
68
 
69
TASK goofy(void *arg)
70
{
71
  struct timespec t;
72
 
73
  cprintf("Goofy: waiting 2 secs...\n");
74
 
75
  do {
76
    sys_gettime(&t);
77
  } while (t.tv_sec < 2); // wait until 2 sec
78
 
79
  cprintf("Goofy: ok, I'm ready :-)\n");
80
 
81
  return 0;
82
}
83
 
1123 pj 84
void catchit_RT(int signo, siginfo_t *info, void *extra)
1099 pj 85
{
1123 pj 86
  cprintf("RT signal: Current Running Task = %d signo=%d code=%d value=%d from pid=%d\n",
1099 pj 87
            exec_shadow,
88
            info->si_signo, info->si_code,
89
            info->si_value.sival_int, info->si_task);
90
}
91
 
1123 pj 92
void catchit(int signo)
93
{
94
  cprintf("RT signal: Current Running Task = %d signo=%d\n",
95
          exec_shadow, signo);
96
}
1099 pj 97
 
98
int main(int argc, char **argv)
99
{
100
  struct timespec t;
101
  NRT_TASK_MODEL m;
102
  PID p2;
103
 
104
  sigset_t newmask;
105
  sigset_t oldmask;
106
  struct sigaction action;
107
  union sigval sval;
108
 
109
  clear();
110
 
111
  /* Set the signal action */
112
  action.sa_flags = SA_SIGINFO;
1123 pj 113
  action.sa_sigaction = catchit_RT;
1099 pj 114
  action.sa_handler = 0;
115
  action.sa_mask = 0;
116
 
117
  if (sigaction(SIGUSR1, &action, NULL) == -1) {
118
    perror("Error using sigaction.");
119
    return -1;
120
  }
121
 
122
  action.sa_flags = 0;
1119 pj 123
  action.sa_handler = (void (*)(int))catchit;
1099 pj 124
 
125
  if (sigaction(SIGILL, &action, NULL) == -1) {
126
    perror("Error using sigaction.");
127
    return -1;
128
  }
129
 
130
  /* create another task */
131
  nrt_task_default_model(m);
132
  nrt_task_def_group(m,1);
133
 
134
  p2 = task_create("goofy", goofy, &m, NULL);
135
  if (p2 == NIL)
136
  {
137
    cprintf("Can't create goofy task...\n");
138
    return 1;
139
  }
140
 
141
  group_activate(1);
142
 
143
  /* block the signal for the main task */
144
  sigemptyset(&newmask);
145
  sigaddset(&newmask,SIGUSR1);
146
  task_sigmask(SIG_BLOCK, &newmask, &oldmask); // pthread_sigmask
147
 
148
  cprintf("main: Sending 2 signals ...\n");
149
 
150
  sval.sival_int = 123;
151
  sigqueue(0,SIGUSR1,sval);
152
  sval.sival_int = 999;
153
  sigqueue(0,SIGUSR1,sval);
154
 
155
  cprintf("main: Now sending a signal to myself,"
156
          " then wait until 4 secs...\n");
157
 
158
  task_signal(0 /* main */, SIGILL); // pthread_kill
159
 
160
  NULL_TIMESPEC(&t);
161
  do {
162
    sys_gettime(&t);
163
  } while (t.tv_sec < 4); // wait until 4 s
164
 
165
  cprintf("main: ending...\n");
166
 
167
  return 0;
168
}