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
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
* This file is part of the KDE Libraries
* Copyright (C) 2000 Timo Hummel <[email protected]>
* Tom Braun <[email protected]>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef __KCRASH_H
#define __KCRASH_H
#include <tqstring.h>
#include "tdelibs_export.h"
/**
* This class handles segmentation-faults.
* By default it displays a message-box saying the application crashed.
* This default can be overridden by setting a custom crash handler with
* setCrashHandler().
* If a function is specified with setEmergencySaveFunction() it will
* be called by the default crash handler, giving the application a chance
* to save its data.
*/
class TDECORE_EXPORT KCrash
{
private: // ;o)
static const char *appName;
static const char *appPath;
static bool safer;
public:
/**
* The default crash handler.
* @param signal the signal number
*/
static void defaultCrashHandler (int signal);
/**
* This function type is a pointer to a crash handler function.
* The function's argument is the number of the signal.
*/
typedef void (*HandlerType)(int);
/**
* Install a function to be called in case a SIGSEGV is caught.
* @param handler HandlerType handler can be one of
* @li null in which case signal-catching is disabled
* (by calling signal(SIGSEGV, SIG_DFL))
* @li if handler is omitted the default crash handler is installed.
* @li an user defined function in the form:
* static (if in a class) void myCrashHandler(int);
* @param handler the crash handler
*/
static void setCrashHandler (HandlerType handler = defaultCrashHandler);
/**
* Returns the installed crash handler.
* @return the crash handler
*/
static HandlerType crashHandler() { return _crashHandler; }
/**
* Installs a function which should try to save the applications data.
* It is the crash handler�s responsibility to call this function.
* Therefore, if no crash handler is set, the default crash handler
* is installed to ensure the save function is called.
* @param saveFunction the handler to install
*/
static void setEmergencySaveFunction (HandlerType saveFunction = (HandlerType)0);
/**
* Return the currently set emergency save function.
* @return the emergency save function
*/
static HandlerType emergencySaveFunction() { return _emergencySaveFunction; }
/**
* Set whether to start drkonqi without arbitrary disk access
*/
static void setSafer( bool on ) { safer = on; }
/**
* Sets the application @p path which should be passed to
* Dr. Konqi, our nice crash display application.
* @param path the application path.
*/
static void setApplicationPath (TQString path) { appPath = tqstrdup(path.local8Bit().data()); }
/* KDE 4: Make it const TQString & */
/**
* Sets the application name @p name which should be passed to
* Dr. Konqi, our nice crash display application.
* @param name the name of the application, as shown in Dr. Konqi
*/
static void setApplicationName (TQString name) { appName = tqstrdup(name.local8Bit().data()); }
/* KDE 4: Make it const TQString & */
protected:
/**
* Pointer to the crash handler.
*/
static HandlerType _crashHandler;
/**
* Pointer to the emergency save function.
*/
static HandlerType _emergencySaveFunction;
private:
static void startDrKonqi( const char* argv[], int argc );
static void startDirectly( const char* argv[], int argc );
};
#endif
|