1 /***************************************************************************
2 * Copyright (C) 2012 by CADS/UV Software Team, *
3 * Indian Institute of Astrophysics *
4 * Bangalore 560034 *
5 * cads_AT_iiap.res.in *
6 * *
7 * This program 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 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program 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. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/
22 /*--------------------------------------------------------------------------
23 File : signal_handler.c
24 Author : Reks
25 Date : 09/07/2005
26 Version: 1.11
27 File Description: This file contains a function to identify a crash
28 signal, trap it and exit with status 1.
29 the distribution. The Following functions are defined
30 in this file:
31 1. set_signal ()
32 2. signal_handler ()
34 URL: More information on Cads software is available at
35 http://cads.iiap.res.in/software
36 *-------------------------------------------------------------------------*/
38 /*-------------------------------------------------------------------------
39 Revision : Author, dd/mm/yyyy
40 Revision history :----
42 Reks, 09th Jul 2005: Created this file
43 Reks, 08th Dec 2005: Re-ordered functions to stop complaints from ANSI
44 *-------------------------------------------------------------------------*/
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <signal.h>
49 void signals_handler(int signal)
50 {
52 /* Try to figure out what that signal means... */
53 switch (signal)
54 {
55 case SIGSEGV:
56 fprintf(stderr, "\nFATAL : Segmentation Fault\n");
57 break;
58 case SIGFPE:
59 fprintf(stderr, "\nFATAL : Integer or Floating Point Exception\n");
60 break;
61 case SIGILL:
62 fprintf(stderr, "\nFATAL : Illegal Operation Exception\n");
63 break;
64 default:
65 fprintf(stderr, "\nFATAL : Unknown signal trapped. Argument = %d\n",
66 signal);
67 break;
68 }
70 /* No point continuing... print out a suggestion and packup.. */
71 printf("\n-----------------------------------------------------------\n");
72 printf("You seem to have come across a bug in the software. Please \n");
73 printf("report this incident to http://cads.iiap.res.in/bugzilla/\n");
74 printf("-----------------------------------------------------------\n\n");
76 exit(EXIT_FAILURE);
77 }
79 void set_signals(void)
80 {
82 /* Any of these signals and send them to signal_handler */
83 signal(SIGSEGV, signals_handler);
84 signal(SIGFPE, signals_handler);
85 signal(SIGILL, signals_handler);
86 }