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