SVN_SILENT made messages (.desktop file)
[kdeadmin.git] / kdat / ErrorHandler.cpp
blob420cd71d5568742f25e591f21cfa70a4ec9aa4bb
1 // KDat - a tar-based DAT archiver
2 // Copyright (C) 2001-2002 Lawrence Widman, kdat@cardiothink.com
3 //
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.
8 //
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
18 #include <stdio.h>
19 #include <signal.h>
20 #include <stdlib.h>
21 #include <kglobal.h>
22 #include <qmessagebox.h>
23 #include <klocale.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;
48 int i;
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" );
63 switch (err_sig) {
64 case SIGHUP:
65 fprintf(stderr, "kdat: SIGHUP signal (\"Hangup (POSIX)\") caught\n");
66 i = QMessageBox::critical( (QWidget *)NULL,
67 msg3,
68 i18n( "SIGHUP signal (\"Hangup (POSIX)\")" ).append( msg1 ),
69 QMessageBox::Ignore, QMessageBox::Abort, QMessageBox::NoButton);
70 if( i == QMessageBox::Abort ){ abort(); }
71 break;
72 case SIGINT:
73 fprintf(stderr, "kdat: SIGINT signal (\"Interrupt (ANSI)\") caught\n");
74 i = QMessageBox::critical( (QWidget *)NULL,
75 msg3,
76 i18n( "SIGINT signal (\"Interrupt (ANSI)\")" ).append( msg1 ),
77 QMessageBox::Ignore, QMessageBox::Abort, QMessageBox::NoButton);
78 if( i == QMessageBox::Abort ){ abort(); }
79 break;
80 case SIGFPE:
81 fprintf(stderr, "kdat: SIGFPE signal (\"Floating-point exception (ANSI)\") caught\n");
82 i = QMessageBox::critical( (QWidget *)NULL,
83 msg3,
84 i18n("SIGFPE signal (\"Floating-point exception (ANSI)\")").append (msg2),
85 QMessageBox::Ignore, QMessageBox::Abort, QMessageBox::NoButton);
86 if( i == QMessageBox::Abort ){ abort(); }
87 break;
88 case SIGSEGV:
89 fprintf(stderr, "kdat: SIGSEGV signal (\"Segmentation violation (ANSI)\") caught\n");
90 i = QMessageBox::critical( (QWidget *)NULL,
91 msg3,
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(); }
96 break;
97 case SIGTERM:
98 fprintf(stderr, "kdat: SIGTERM signal (\"Termination (ANSI)\") caught\n");
99 i = QMessageBox::critical( (QWidget *)NULL,
100 msg3,
101 i18n( "SIGTERM signal (\"Termination (ANSI)\")").append(msg1),
102 QMessageBox::Ignore, QMessageBox::Abort, QMessageBox::NoButton);
103 if( i == QMessageBox::Abort ){ abort(); }
104 break;
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);