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:
@ -36,7 +41,7 @@
2004-03-11 André Pönitz <poenitz@gmx.net>
* buffer.[Ch]: use InsetText instead of LyXText as container for
* buffer.[Ch]: use InsetText instead of LyXText as container for
the main lyx text.
* dociterator.[Ch]: drop the BufferView * member which is not needed
@ -102,7 +107,7 @@
* text.C:
* text2.C:
* rowpainter.C:
* BufferView_pimpl.C: rename textwidth -> maxwidth,
* BufferView_pimpl.C: rename textwidth -> maxwidth,
prepareToPrint -> computeRowMetrics and remove textWidth accessor.
2004-03-01 Alfredo Braunstein <abraunst@lyx.org>
@ -119,11 +124,11 @@
2004-03-01 Alfredo Braunstein <abraunst@lyx.org>
* FontIterator.[Ch]: move FontIterator from lyxtext.h/text.C to here
* FontIterator.[Ch]: move FontIterator from lyxtext.h/text.C to here
2004-03-01 Alfredo Braunstein <abraunst@lyx.org>
* lyxtext.h: add FontIterator class
* lyxtext.h: add FontIterator class
* text.C (FontIterator, operator*, operator->, operator++): add
(rowBreakPoint, setRowWidth): adjust (fixing a
@ -274,16 +279,16 @@
2004-02-04 André Pönitz <poenitz@gmx.net>
* BufferView.[Ch] (insertInset):
* BufferView_pimpl.[Ch] (insertInset): remove unneeded return value
* BufferView_pimpl.[Ch] (insertInset): remove unneeded return value
* text2.C:
* text3.C: adjust
2004-02-03 Alfredo Braunstein <abraunst@lyx.org>
* BufferView_pimpl.C (dispatch): remove call to LCursor::dispatch
* BufferView_pimpl.C (dispatch): remove call to LCursor::dispatch
on the default clause of the switch
* lyxfunc.C (dispatch): call BufferView::dispatch if the event
* lyxfunc.C (dispatch): call BufferView::dispatch if the event
wasn't catched by LCursor::dispatch
2004-02-03 André Pönitz <poenitz@gmx.net>
@ -295,7 +300,7 @@
* lyxfunc.C: adjust
* lyxtext.h (firstPar, lastPar): remove dead functions
* lyxtext.h (firstPar, lastPar): remove dead functions
* text.C:
* text2.C:

View File

@ -119,7 +119,7 @@ void LyX::exec(int & argc, char * argv[])
// Start the real execution loop.
singleton_->priv_exec(argc, argv);
}
LyX & LyX::ref()
{
@ -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 <<
"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;
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 !\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();