Hi, I had a look at the signal handling stuff in src/lyx_main.C and I think that part is not fancy enough when compared to the overall fancy performance of LyX :).
I've been writing a general signal handler for my own project and was
wondering whether that (in a modified form) could be used for LyX.
I've come to the conclusion to divide all signals into three categories:
1) Don't catch: let the default handler do whatever the OS wants it to do.
F.ex. SIGALRM as a timer signal. The signal then either does "SIG_DFL"
(default OS action) or "SIG_IGN" (ignore, do nothing when signal's raised).
2) Bailout for non-fatal signals (e.g. memory, internals, variables etc.
are NOT corrupted). F. ex. the SIGINT from ctrl-C.
A bailout signal not necessarily has to terminate LyX. A question dialog
should pop up whether the user really wants to quit (and possibly loose
unsaved data). If the user wants to continue, then there is no risk
to do so.
3) Rescue for fatal interrupts (memory, storage etc. might be corrupted).
F. ex. SIGSEGV memory signal.
There's no other alternative then to terminate LyX. A rescue should
try to emergency-save any unsaved data and quit the application.
Care is needed, since memory might be (partially) corrupted.
To this end, I have written a SignalHandler class as signalhandler.[Ch], which
takes care of all this. When included, all lyx_main.C has to do is, call once:
setSignalHandlers(bailout_func, rescue_func);
where bailout_func and rescue_func are pointers to functions that do the bailout
and rescue. These function can either have the "handler signature":
void (*handler)(int)
or the "sigaction signature"
void (*sigaction)(int, siginfo_t *, void *)
(see "man sigaction" for info on this).
The details of how to connect the signals to these functions, is dealt with
by the SignalHandler class.
signalhandler.C has a list of all signals and what they are supposed to do
(bailout, rescue, the default OS handler etc.). That may need to be modified
to LyX's needs.
The attached files and the patch below would be a starting point. In the patch,
bailout and rescue now are both the old error_handler() function. That should
spit up next, and real bailout and rescue handlers must be written instead.
Just wondering if this is going to be a welcome improvement.
Let me know, and I'll tweek it a bit more to LyX needs.
Regards,
Rob.
Index: src/Makefile.am
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/Makefile.am,v
retrieving revision 1.148
diff -u -r1.148 Makefile.am
--- src/Makefile.am 2002/08/29 13:05:55 1.148
+++ src/Makefile.am 2002/11/20 03:09:44
@@ -187,6 +187,8 @@
pspell.h \
sgml.C \
sgml.h \
+ signalhandler.C \
+ signalhandler.h \
tabular.C \
tabular.h \
tabular-old.C \
Index: src/lyx_main.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyx_main.C,v
retrieving revision 1.126
diff -u -r1.126 lyx_main.C
--- src/lyx_main.C 2002/11/04 02:12:29 1.126
+++ src/lyx_main.C 2002/11/20 03:09:45
@@ -38,6 +38,7 @@
#include "encoding.h"
#include "converter.h"
#include "lyxtextclasslist.h"
+#include "signalhandler.h"
#include "frontends/Alert.h"
#include "frontends/lyx_gui.h"
@@ -197,22 +198,19 @@
LyX::emergencyCleanup();
lyxerr << "Bye." << endl;
- if (err_sig!= SIGHUP &&
+ if (err_sig != SIGHUP &&
(!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV))
lyx::abort();
exit(0);
}
-}
+} // extern "C"
void LyX::init(bool gui)
{
- signal(SIGHUP, error_handler);
- signal(SIGFPE, error_handler);
- signal(SIGSEGV, error_handler);
- signal(SIGINT, error_handler);
- signal(SIGTERM, error_handler);
+ setSignalHandlers(error_handler, error_handler);
+ lyxerr[Debug::INIT] << showSignalActions() << endl;
//
// Determine path of binary
signalhandler.C.gz
Description: application/gzip
signalhandler.h.gz
Description: application/gzip
