]> git.lyx.org Git - features.git/commitdiff
Make error handling a little more robust.
authorAngus Leeming <leeming@lyx.org>
Mon, 22 Mar 2004 13:09:59 +0000 (13:09 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 22 Mar 2004 13:09:59 +0000 (13:09 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8508 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/lyx_main.C

index 70a09dc14a9a8e6ab98c561a1286bccb424fb7c7..6f103e98a4245b6a060f9381c979212fe01d2d4e 100644 (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>
 
 
         * 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
        * 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>
 
 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
 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>
 
        * lyxfunc.C: adjust
 
-       * lyxtext.h (firstPar, lastPar): remove dead functions 
+       * lyxtext.h (firstPar, lastPar): remove dead functions
 
        * text.C:
        * text2.C:
index 7608131af2d8c26baa10bd86dd9faba35edf7ba6..c3c1edf9338a5c6343908c42a70ff400ea7dc2ea 100644 (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();