1 // KDat - a tar-based DAT archiver
2 // Copyright (C) 2001-2002 Lawrence Widman, kdat@cardiothink.com
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <qmessagebox.h>
24 //#include <kstandarddirs.h>
26 void error_handler(int err_sig
);
28 /* include the following in main():
29 signal(SIGHUP, error_handler);
30 signal(SIGINT, error_handler);
31 signal(SIGFPE, error_handler);
32 signal(SIGSEGV, error_handler);
33 signal(SIGTERM, error_handler);
35 printf("Error_handler installed\n");
38 // from /usr/include/bits/signum.h:
39 // #define SIGHUP 1 /* Hangup (POSIX). */
40 // #define SIGINT 2 /* Interrupt (ANSI). */
41 // #define SIGFPE 8 /* Floating-point exception (ANSI). */
42 // #define SIGSEGV 11 /* Segmentation violation (ANSI). */
43 // #define SIGTERM 15 /* Termination (ANSI). */
45 void error_handler(int err_sig
)
47 QString base1a
, base1b
, base2a
, base2b
, msg1
, msg2
, msg3
;
50 base1a
= i18n( " caught.\nExit the program from File->Quit or do "
51 "\"kill -9 <pid>\" if you like.\n" );
52 base1b
= base1a
; // deep copy
54 base2a
= i18n( "You can dump core by selecting the \"Abort\" button.\n"
55 "Please notify the maintainer (see Help->About KDat)." );
56 base2b
= base2a
; // deep copy
58 msg1
= base1a
.append(base2a
);
59 msg2
= base1b
.append("It is strongly recommended to do this!\n");
60 msg2
= msg2
.append(base2b
);
61 msg3
= i18n( "An Error Signal was Received" );
65 fprintf(stderr
, "kdat: SIGHUP signal (\"Hangup (POSIX)\") caught\n");
66 i
= QMessageBox::critical( (QWidget
*)NULL
,
68 i18n( "SIGHUP signal (\"Hangup (POSIX)\")" ).append( msg1
),
69 QMessageBox::Ignore
, QMessageBox::Abort
, QMessageBox::NoButton
);
70 if( i
== QMessageBox::Abort
){ abort(); }
73 fprintf(stderr
, "kdat: SIGINT signal (\"Interrupt (ANSI)\") caught\n");
74 i
= QMessageBox::critical( (QWidget
*)NULL
,
76 i18n( "SIGINT signal (\"Interrupt (ANSI)\")" ).append( msg1
),
77 QMessageBox::Ignore
, QMessageBox::Abort
, QMessageBox::NoButton
);
78 if( i
== QMessageBox::Abort
){ abort(); }
81 fprintf(stderr
, "kdat: SIGFPE signal (\"Floating-point exception (ANSI)\") caught\n");
82 i
= QMessageBox::critical( (QWidget
*)NULL
,
84 i18n("SIGFPE signal (\"Floating-point exception (ANSI)\")").append (msg2
),
85 QMessageBox::Ignore
, QMessageBox::Abort
, QMessageBox::NoButton
);
86 if( i
== QMessageBox::Abort
){ abort(); }
89 fprintf(stderr
, "kdat: SIGSEGV signal (\"Segmentation violation (ANSI)\") caught\n");
90 i
= QMessageBox::critical( (QWidget
*)NULL
,
92 i18n( "SIGSEGV signal (\"Segmentation violation (ANSI)\")").append(msg2
),
93 /* button1, button2 */
94 QMessageBox::Ignore
, QMessageBox::Abort
, QMessageBox::NoButton
);
95 if( i
== QMessageBox::Abort
){ abort(); }
98 fprintf(stderr
, "kdat: SIGTERM signal (\"Termination (ANSI)\") caught\n");
99 i
= QMessageBox::critical( (QWidget
*)NULL
,
101 i18n( "SIGTERM signal (\"Termination (ANSI)\")").append(msg1
),
102 QMessageBox::Ignore
, QMessageBox::Abort
, QMessageBox::NoButton
);
103 if( i
== QMessageBox::Abort
){ abort(); }
107 // Deinstall the signal handlers
108 // signal(SIGHUP, SIG_DFL);
109 // signal(SIGINT, SIG_DFL);
110 // signal(SIGFPE, SIG_DFL);
111 // signal(SIGSEGV, SIG_DFL);
112 // signal(SIGTERM, SIG_DFL);