3 * Copyright 2004 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * This is actually the same as gr_local_signhandler, but with a different name.
25 * We don't have a common library to put this in, so...
32 #include <usrp_local_sighandler.h>
36 usrp_local_sighandler::usrp_local_sighandler (int signum,
37 void (*new_handler)(int))
41 struct sigaction new_action;
42 memset (&new_action, 0, sizeof (new_action));
44 new_action.sa_handler = new_handler;
45 sigemptyset (&new_action.sa_mask);
46 new_action.sa_flags = 0;
48 if (sigaction (d_signum, &new_action, &d_old_action) < 0){
49 perror ("sigaction (install new)");
50 throw std::runtime_error ("sigaction");
55 usrp_local_sighandler::~usrp_local_sighandler ()
58 if (sigaction (d_signum, &d_old_action, 0) < 0){
59 perror ("sigaction (restore old)");
60 throw std::runtime_error ("sigaction");
66 usrp_local_sighandler::throw_signal(int signum) throw(usrp_signal)
68 throw usrp_signal (signum);
72 * Semi-hideous way to may a signal number into a signal name
75 #define SIGNAME(x) case x: return #x
78 usrp_signal::name () const
177 #if defined (HAVE_SNPRINTF)
178 #if defined (SIGRTMIN) && defined (SIGRTMAX)
179 if (signal () >= SIGRTMIN && signal () <= SIGRTMAX){
180 snprintf (tmp, sizeof (tmp), "SIGRTMIN + %d", signal ());
184 snprintf (tmp, sizeof (tmp), "SIGNAL %d", signal ());
187 return "Unknown signal";