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 3, 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., 51 Franklin Street,
20 * Boston, MA 02110-1301, 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>
37 usrp_local_sighandler::usrp_local_sighandler (int signum,
38 void (*new_handler)(int))
42 struct sigaction new_action;
43 memset (&new_action, 0, sizeof (new_action));
45 new_action.sa_handler = new_handler;
46 sigemptyset (&new_action.sa_mask);
47 new_action.sa_flags = 0;
49 if (sigaction (d_signum, &new_action, &d_old_action) < 0){
50 perror ("sigaction (install new)");
51 throw std::runtime_error ("sigaction");
56 usrp_local_sighandler::~usrp_local_sighandler ()
59 if (sigaction (d_signum, &d_old_action, 0) < 0){
60 perror ("sigaction (restore old)");
61 throw std::runtime_error ("sigaction");
67 usrp_local_sighandler::throw_signal(int signum) throw(usrp_signal)
69 throw usrp_signal (signum);
73 * Semi-hideous way to may a signal number into a signal name
76 #define SIGNAME(x) case x: return #x
79 usrp_signal::name () const
178 #if defined (HAVE_SNPRINTF)
179 #if defined (SIGRTMIN) && defined (SIGRTMAX)
180 if (signal () >= SIGRTMIN && signal () <= SIGRTMAX){
181 snprintf (tmp, sizeof (tmp), "SIGRTMIN + %d", signal ());
185 snprintf (tmp, sizeof (tmp), "SIGNAL %d", signal ());
188 return "Unknown signal";