John Levon wrote:
>> Or should the code in child_handler be truly trivial:
> Yes.

John, I take it that you're (almost) happy with the existing signal 
handling code in error_handler below. To my mind it needs only a 
handling_error flag to ensure that it handles multiple signals 
safely. (The SIGPIPE should be removed if it isn't an error.)

Thoughts?
Angus

 static void error_handler(int err_sig)
 {
+    static sig_atomic_t handling_error = false;
+    if (handling_error)
+        return;
+    handling_error = true;
+
     switch (err_sig) {
     case SIGHUP:
         lyxerr << "\nlyx: SIGHUP signal caught" << endl;
         break;
     case SIGINT:
         // no comments
         break;
     case SIGFPE:
         lyxerr << "\nlyx: SIGFPE signal caught" << 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;
         break;
     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
     signal(SIGHUP, SIG_DFL);
     signal(SIGINT, SIG_DFL);
     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))
         lyx::support::abort();
     exit(0);
 }


Reply via email to