diff libinterp/corefcn/sighandlers.cc @ 25284:78fb24bdd8bb stable

unblock async signals before executing subprocess (bug #53635) * sighandlers.cc (sigint_handler): Delete. (generic_sig_handler): Handle sigint and sigbreak here. (catch_interrupts): Use generic_sig_handler instead of sigint_handler. (F__show_signal_mask__): New function. * signal-wrappers.h, signal-wrappers.c (octave_alloc_signal_mask, octave_free_signal_mask, octave_get_signal_mask, octave_set_signal_mask): New functions. * toplev.cc (get_signal_mask, restore_signal_mask): New static functions. (Fsystem): Save signal mask. Unblock async signals before executing subprocess. Use unwind_protect frame to restore previous mask.
author John W. Eaton <jwe@octave.org>
date Thu, 19 Apr 2018 01:58:44 -0400
parents 078b795c5219
children 389757b7b6af
line wrap: on
line diff
--- a/libinterp/corefcn/sighandlers.cc	Wed Apr 18 15:18:47 2018 -0400
+++ b/libinterp/corefcn/sighandlers.cc	Thu Apr 19 01:58:44 2018 -0400
@@ -243,7 +243,7 @@
                         << std::endl;
             else if ((have_sigint && sig == sigint)
                      || (have_sigbreak && sig == sigbreak))
-              /* handled separately; do nothing */;
+              ; // Handled separately; do nothing.
             else
               std::cerr << "warning: ignoring unexpected signal: "
                         << octave_strsignal_wrapper (sig)
@@ -287,7 +287,16 @@
 
     if ((have_sigint && sig == sigint)
         || (have_sigbreak && sig == sigbreak))
-      octave_interrupt_state++;
+      {
+        if (! octave_initialized)
+          exit (1);
+
+        if (can_interrupt)
+          {
+            octave_signal_caught = 1;
+            octave_interrupt_state++;
+          }
+      }
   }
 
   static void
@@ -310,32 +319,13 @@
     std::cerr << "warning: floating point exception" << std::endl;
   }
 
-  // Handle SIGINT.
-  //
-  // This also has to work for SIGBREAK (on systems that have it), so we
-  // use the value of sig, instead of just assuming that it is called
-  // for SIGINT only.
-
-  static void
-  sigint_handler (int)
-  {
-    if (! octave_initialized)
-      exit (1);
-
-    if (can_interrupt)
-      {
-        octave_signal_caught = 1;
-        octave_interrupt_state++;
-      }
-  }
-
   interrupt_handler
   catch_interrupts (void)
   {
     interrupt_handler retval;
 
-    retval.int_handler = set_signal_handler ("SIGINT", sigint_handler);
-    retval.brk_handler = set_signal_handler ("SIGBREAK", sigint_handler);
+    retval.int_handler = set_signal_handler ("SIGINT", generic_sig_handler);
+    retval.brk_handler = set_signal_handler ("SIGBREAK", generic_sig_handler);
 
     return retval;
   }