Subversion Repositories shark

Rev

Rev 1119 | Go to most recent revision | Details | 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
 ------------
21
 CVS :        $Id: sig.c,v 1.1 2002-10-28 08:13:37 pj Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1 $
25
 Last update: $Date: 2002-10-28 08:13:37 $
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
 
84
void catchit(int signo, siginfo_t *info, void *extra)
85
{
86
  cprintf("Current Running Task = %d signo=%d code=%d value=%d from pid=%d\n",
87
            exec_shadow,
88
            info->si_signo, info->si_code,
89
            info->si_value.sival_int, info->si_task);
90
}
91
 
92
 
93
int main(int argc, char **argv)
94
{
95
  struct timespec t;
96
  NRT_TASK_MODEL m;
97
  PID p2;
98
 
99
  sigset_t newmask;
100
  sigset_t oldmask;
101
  struct sigaction action;
102
  union sigval sval;
103
 
104
  clear();
105
 
106
  /* Set the signal action */
107
  action.sa_flags = SA_SIGINFO;
108
  action.sa_sigaction = catchit;
109
  action.sa_handler = 0;
110
  action.sa_mask = 0;
111
 
112
  if (sigaction(SIGUSR1, &action, NULL) == -1) {
113
    perror("Error using sigaction.");
114
    return -1;
115
  }
116
 
117
  action.sa_flags = 0;
118
  action.sa_handler = catchit;
119
 
120
  if (sigaction(SIGILL, &action, NULL) == -1) {
121
    perror("Error using sigaction.");
122
    return -1;
123
  }
124
 
125
  /* create another task */
126
  nrt_task_default_model(m);
127
  nrt_task_def_group(m,1);
128
 
129
  p2 = task_create("goofy", goofy, &m, NULL);
130
  if (p2 == NIL)
131
  {
132
    cprintf("Can't create goofy task...\n");
133
    return 1;
134
  }
135
 
136
  group_activate(1);
137
 
138
  /* block the signal for the main task */
139
  sigemptyset(&newmask);
140
  sigaddset(&newmask,SIGUSR1);
141
  task_sigmask(SIG_BLOCK, &newmask, &oldmask); // pthread_sigmask
142
 
143
  cprintf("main: Sending 2 signals ...\n");
144
 
145
  sval.sival_int = 123;
146
  sigqueue(0,SIGUSR1,sval);
147
  sval.sival_int = 999;
148
  sigqueue(0,SIGUSR1,sval);
149
 
150
  cprintf("main: Now sending a signal to myself,"
151
          " then wait until 4 secs...\n");
152
 
153
  task_signal(0 /* main */, SIGILL); // pthread_kill
154
 
155
  NULL_TIMESPEC(&t);
156
  do {
157
    sys_gettime(&t);
158
  } while (t.tv_sec < 4); // wait until 4 s
159
 
160
  cprintf("main: ending...\n");
161
 
162
  return 0;
163
}