1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/* -*- c++ -*- */
/*
* Copyright 2004 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* GNU Radio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
/*
* This is actually the same as gr_local_signhandler, but with a different name.
* We don't have a common library to put this in, so...
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <usrp_local_sighandler.h>
#include <stdexcept>
#include <stdio.h>
#include <string.h>
usrp_local_sighandler::usrp_local_sighandler (int signum,
void (*new_handler)(int))
: d_signum (signum)
{
#ifdef HAVE_SIGACTION
struct sigaction new_action;
memset (&new_action, 0, sizeof (new_action));
new_action.sa_handler = new_handler;
sigemptyset (&new_action.sa_mask);
new_action.sa_flags = 0;
if (sigaction (d_signum, &new_action, &d_old_action) < 0){
perror ("sigaction (install new)");
throw std::runtime_error ("sigaction");
}
#endif
}
usrp_local_sighandler::~usrp_local_sighandler ()
{
#ifdef HAVE_SIGACTION
if (sigaction (d_signum, &d_old_action, 0) < 0){
perror ("sigaction (restore old)");
throw std::runtime_error ("sigaction");
}
#endif
}
void
usrp_local_sighandler::throw_signal(int signum) throw(usrp_signal)
{
throw usrp_signal (signum);
}
/*
* Semi-hideous way to may a signal number into a signal name
*/
#define SIGNAME(x) case x: return #x
std::string
usrp_signal::name () const
{
char tmp[128];
switch (signal ()){
#ifdef SIGHUP
SIGNAME (SIGHUP);
#endif
#ifdef SIGINT
SIGNAME (SIGINT);
#endif
#ifdef SIGQUIT
SIGNAME (SIGQUIT);
#endif
#ifdef SIGILL
SIGNAME (SIGILL);
#endif
#ifdef SIGTRAP
SIGNAME (SIGTRAP);
#endif
#ifdef SIGABRT
SIGNAME (SIGABRT);
#endif
#ifdef SIGBUS
SIGNAME (SIGBUS);
#endif
#ifdef SIGFPE
SIGNAME (SIGFPE);
#endif
#ifdef SIGKILL
SIGNAME (SIGKILL);
#endif
#ifdef SIGUSR1
SIGNAME (SIGUSR1);
#endif
#ifdef SIGSEGV
SIGNAME (SIGSEGV);
#endif
#ifdef SIGUSR2
SIGNAME (SIGUSR2);
#endif
#ifdef SIGPIPE
SIGNAME (SIGPIPE);
#endif
#ifdef SIGALRM
SIGNAME (SIGALRM);
#endif
#ifdef SIGTERM
SIGNAME (SIGTERM);
#endif
#ifdef SIGSTKFLT
SIGNAME (SIGSTKFLT);
#endif
#ifdef SIGCHLD
SIGNAME (SIGCHLD);
#endif
#ifdef SIGCONT
SIGNAME (SIGCONT);
#endif
#ifdef SIGSTOP
SIGNAME (SIGSTOP);
#endif
#ifdef SIGTSTP
SIGNAME (SIGTSTP);
#endif
#ifdef SIGTTIN
SIGNAME (SIGTTIN);
#endif
#ifdef SIGTTOU
SIGNAME (SIGTTOU);
#endif
#ifdef SIGURG
SIGNAME (SIGURG);
#endif
#ifdef SIGXCPU
SIGNAME (SIGXCPU);
#endif
#ifdef SIGXFSZ
SIGNAME (SIGXFSZ);
#endif
#ifdef SIGVTALRM
SIGNAME (SIGVTALRM);
#endif
#ifdef SIGPROF
SIGNAME (SIGPROF);
#endif
#ifdef SIGWINCH
SIGNAME (SIGWINCH);
#endif
#ifdef SIGIO
SIGNAME (SIGIO);
#endif
#ifdef SIGPWR
SIGNAME (SIGPWR);
#endif
#ifdef SIGSYS
SIGNAME (SIGSYS);
#endif
default:
#if defined (HAVE_SNPRINTF)
#if defined (SIGRTMIN) && defined (SIGRTMAX)
if (signal () >= SIGRTMIN && signal () <= SIGRTMAX){
snprintf (tmp, sizeof (tmp), "SIGRTMIN + %d", signal ());
return tmp;
}
#endif
snprintf (tmp, sizeof (tmp), "SIGNAL %d", signal ());
return tmp;
#else
return "Unknown signal";
#endif
}
}
|