Make error handling a little more robust.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8508 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-03-22 13:09:59 +00:00
parent f16a17fa42
commit eed73def23
2 changed files with 47 additions and 35 deletions

View File

@ -1,3 +1,8 @@
2004-03-22 Angus Leeming <leeming@lyx.org>
* lyx_main.C (error_handler, init): remove handler for SIGPIPE.
Ensure that error_handler is processed once only and that all data
is saved before attempting to output any warning messages.
2004-03-21 Alfredo Braunstein <abraunst@lyx.org>
@ -12,11 +17,11 @@
        * paragraph.[Ch]: fix completely broken operator=()
2004-03-16 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* LColor.C (getFromLyXName): make sure that the color name is used
as lowercase.
2004-03-17 Angus Leeming <leeming@lyx.org>
* lfuns.h:

View File

@ -258,34 +258,45 @@ extern "C" {
static void error_handler(int err_sig)
{
// Throw away any signals other than the first one received.
static sig_atomic_t handling_error = false;
if (handling_error)
return;
handling_error = true;
// We have received a signal indicating a fatal error, so
// try and save the data ASAP.
LyX::cref().emergencyCleanup();
// These lyxerr calls may or may not work:
// Signals are asynchronous, so the main program may be in a very
// fragile state when a signal is processed and thus while a signal
// handler function executes.
// In general, therefore, we should avoid performing any
// I/O operations or calling most library and system functions from
// signal handlers.
// This shouldn't matter here, however, as we've already invoked
// emergencyCleanup.
switch (err_sig) {
case SIGHUP:
lyxerr << "\nlyx: SIGHUP signal caught" << endl;
break;
case SIGINT:
// no comments
lyxerr << "\nlyx: SIGHUP signal caught\nBye." << endl;
break;
case SIGFPE:
lyxerr << "\nlyx: SIGFPE signal caught" << endl;
lyxerr << "\nlyx: SIGFPE signal caught\nBye." << endl;
break;
case SIGSEGV:
lyxerr << "\nlyx: SIGSEGV signal caught" << endl;
lyxerr <<
lyxerr << "\nlyx: SIGSEGV signal caught\n"
"Sorry, you have found a bug in LyX. "
"Please read the bug-reporting instructions "
"in Help->Introduction and send us a bug report, "
"if necessary. Thanks !" << endl;
"if necessary. Thanks !\nBye." << endl;
break;
case SIGINT:
case SIGTERM:
// no comments
break;
case SIGPIPE:
// This will be received if lyx tries to write to a socket
// whose reading end was closed. It can safely be ignored,
// as in this case the ::write() system call will return -1
// and errno will be set to EPIPE
return;
//break;
}
// Deinstall the signal handlers
@ -294,13 +305,9 @@ static void error_handler(int err_sig)
signal(SIGFPE, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGPIPE, SIG_DFL);
LyX::cref().emergencyCleanup();
lyxerr << "Bye." << endl;
if (err_sig!= SIGHUP &&
(!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV))
if (err_sig == SIGSEGV ||
(err_sig != SIGHUP && !GetEnv("LYXDEBUG").empty()))
lyx::support::abort();
exit(0);
}
@ -323,7 +330,7 @@ void LyX::init(bool gui)
signal(SIGSEGV, error_handler);
signal(SIGINT, error_handler);
signal(SIGTERM, error_handler);
signal(SIGPIPE, error_handler);
// SIGPIPE can be safely ignored.
bool const explicit_userdir = setLyxPaths();