emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r110194: Fix handling of fatal signal


From: Eli Zaretskii
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r110194: Fix handling of fatal signals and exceptions on MS-Windows.
Date: Tue, 25 Sep 2012 13:50:01 +0200
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 110194
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Tue 2012-09-25 13:50:01 +0200
message:
  Fix handling of fatal signals and exceptions on MS-Windows.
  
   src/w32proc.c (sys_signal): Handle all signals defined by the
   MS-Windows runtime, not just SIGCHLD.  Actually install the signal
   handlers for signals supported by Windows.  Don't override
   term_ntproc as the handler for SIGABRT.
   (sigaction): Rewrite to call sys_signal instead of duplicating its
   code.
   (sys_kill): Improve commentary.
   src/w32.c (term_ntproc): Accept (and ignore) one argument, for
   consistency with a signature of a signal handler.  All callers
   changed.
   (init_ntproc): Accept an argument DUMPING.  If dumping, don't
   install term_ntproc as a signal handler for SIGABRT, as that
   should be done by the dumped Emacs.
   src/w32.h (init_ntproc, term_ntproc): Adjust prototypes.
   src/w32select.c (term_w32select): Protect against repeated
   invocation by setting clipboard_owner to NULL after calling
   DestroyWindow.
   src/emacs.c (shut_down_emacs, main): Adapt the calls to init_ntproc
   and term_ntproc to their modified signatures.
modified:
  src/ChangeLog
  src/emacs.c
  src/w32.c
  src/w32.h
  src/w32proc.c
  src/w32select.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-09-25 07:01:52 +0000
+++ b/src/ChangeLog     2012-09-25 11:50:01 +0000
@@ -1,5 +1,29 @@
 2012-09-25  Eli Zaretskii  <address@hidden>
 
+       * w32proc.c (sys_signal): Handle all signals defined by the
+       MS-Windows runtime, not just SIGCHLD.  Actually install the signal
+       handlers for signals supported by Windows.  Don't override
+       term_ntproc as the handler for SIGABRT.
+       (sigaction): Rewrite to call sys_signal instead of duplicating its
+       code.
+       (sys_kill): Improve commentary.
+
+       * w32.c (term_ntproc): Accept (and ignore) one argument, for
+       consistency with a signature of a signal handler.  All callers
+       changed.
+       (init_ntproc): Accept an argument DUMPING.  If dumping, don't
+       install term_ntproc as a signal handler for SIGABRT, as that
+       should be done by the dumped Emacs.
+
+       * w32.h (init_ntproc, term_ntproc): Adjust prototypes.
+
+       * w32select.c (term_w32select): Protect against repeated
+       invocation by setting clipboard_owner to NULL after calling
+       DestroyWindow.
+
+       * emacs.c (shut_down_emacs, main): Adapt the calls to init_ntproc
+       and term_ntproc to their modified signatures.
+
        * character.c (char_string, string_char): Remove calls to
        MAYBE_UNIFY_CHAR.  See the discussion starting at
        http://lists.gnu.org/archive/html/emacs-devel/2012-09/msg00433.html

=== modified file 'src/emacs.c'
--- a/src/emacs.c       2012-09-23 17:05:14 +0000
+++ b/src/emacs.c       2012-09-25 11:50:01 +0000
@@ -1258,7 +1258,7 @@
   globals_of_w32 ();
   /* Initialize environment from registry settings.  */
   init_environment (argv);
-  init_ntproc ();      /* must precede init_editfns.  */
+  init_ntproc (dumping); /* must precede init_editfns.  */
 #endif
 
   /* Initialize and GC-protect Vinitial_environment and
@@ -1906,7 +1906,7 @@
   ignore_sigio ();
 
 #ifdef WINDOWSNT
-  term_ntproc ();
+  term_ntproc (0);
 #endif
 
   /* Do this only if terminating normally, we want glyph matrices

=== modified file 'src/w32.c'
--- a/src/w32.c 2012-09-23 09:16:57 +0000
+++ b/src/w32.c 2012-09-25 11:50:01 +0000
@@ -6624,8 +6624,9 @@
 }
 
 void
-term_ntproc (void)
+term_ntproc (int ignored)
 {
+  (void)ignored;
   /* shutdown the socket interface if necessary */
   term_winsock ();
 
@@ -6633,7 +6634,7 @@
 }
 
 void
-init_ntproc (void)
+init_ntproc (int dumping)
 {
   /* Initialize the socket interface now if available and requested by
      the user by defining PRELOAD_WINSOCK; otherwise loading will be
@@ -6710,7 +6711,8 @@
 
   /* unfortunately, atexit depends on implementation of malloc */
   /* atexit (term_ntproc); */
-  signal (SIGABRT, term_ntproc);
+  if (!dumping)
+    signal (SIGABRT, term_ntproc);
 
   /* determine which drives are fixed, for GetCachedVolumeInformation */
   {

=== modified file 'src/w32.h'
--- a/src/w32.h 2012-09-23 09:16:57 +0000
+++ b/src/w32.h 2012-09-25 11:50:01 +0000
@@ -127,8 +127,8 @@
 /* Return the string resource associated with KEY of type TYPE.  */
 extern LPBYTE w32_get_resource (char * key, LPDWORD type);
 
-extern void init_ntproc (void);
-extern void term_ntproc (void);
+extern void init_ntproc (int);
+extern void term_ntproc (int);
 extern void globals_of_w32 (void);
 extern void syms_of_w32term (void);
 extern void syms_of_w32fns (void);

=== modified file 'src/w32proc.c'
--- a/src/w32proc.c     2012-09-23 17:34:30 +0000
+++ b/src/w32proc.c     2012-09-25 11:50:01 +0000
@@ -86,19 +86,34 @@
 /* Signal handlers...SIG_DFL == 0 so this is initialized correctly.  */
 static signal_handler sig_handlers[NSIG];
 
-/* Fake signal implementation to record the SIGCHLD handler.  */
+/* Improve on the CRT 'signal' implementation so that we could record
+   the SIGCHLD handler.  */
 signal_handler
 sys_signal (int sig, signal_handler handler)
 {
   signal_handler old;
 
-  if (sig != SIGCHLD)
+  /* SIGCHLD is needed for supporting subprocesses, see sys_kill
+     below.  All the others are the only ones supported by the MS
+     runtime.  */
+  if (!(sig == SIGCHLD || sig == SIGSEGV || sig == SIGILL
+       || sig == SIGFPE || sig == SIGABRT || sig == SIGTERM))
     {
       errno = EINVAL;
       return SIG_ERR;
     }
   old = sig_handlers[sig];
-  sig_handlers[sig] = handler;
+  /* SIGABRT is treated specially because w32.c installs term_ntproc
+     as its handler, so we don't want to override that afterwards.
+     Aborting Emacs works specially anyway: either by calling
+     emacs_abort directly or through terminate_due_to_signal, which
+     calls emacs_abort through emacs_raise.  */
+  if (!(sig == SIGABRT && old == term_ntproc))
+    {
+      sig_handlers[sig] = handler;
+      if (sig != SIGCHLD)
+       signal (sig, handler);
+    }
   return old;
 }
 
@@ -106,23 +121,26 @@
 int
 sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
 {
-  signal_handler old;
+  signal_handler old = SIG_DFL;
+  int retval = 0;
 
-  if (sig != SIGCHLD)
-    {
-      errno = EINVAL;
-      return -1;
-    }
-  old = sig_handlers[sig];
   if (act)
-    sig_handlers[sig] = act->sa_handler;
+    old = sys_signal (sig, act->sa_handler);
+  else if (oact)
+    old = sig_handlers[sig];
+
+  if (old == SIG_ERR)
+    {
+      errno = EINVAL;
+      retval = -1;
+    }
   if (oact)
     {
       oact->sa_handler = old;
       oact->sa_flags = 0;
       oact->sa_mask = empty_mask;
     }
-  return 0;
+  return retval;
 }
 
 /* Defined in <process.h> which conflicts with the local copy */
@@ -1420,6 +1438,7 @@
   return TRUE;
 }
 
+/* Emulate 'kill', but only for other processes.  */
 int
 sys_kill (int pid, int sig)
 {
@@ -1438,6 +1457,11 @@
   cp = find_child_pid (pid);
   if (cp == NULL)
     {
+      /* We were passed a PID of something other than our subprocess.
+        If that is our own PID, we will send to ourself a message to
+        close the selected frame, which does not necessarily
+        terminates Emacs.  But then we are not supposed to call
+        sys_kill with our own PID.  */
       proc_hand = OpenProcess (PROCESS_TERMINATE, 0, pid);
       if (proc_hand == NULL)
         {

=== modified file 'src/w32select.c'
--- a/src/w32select.c   2012-09-23 08:44:20 +0000
+++ b/src/w32select.c   2012-09-25 11:50:01 +0000
@@ -474,7 +474,10 @@
 {
   /* This is needed to trigger WM_RENDERALLFORMATS. */
   if (clipboard_owner != NULL)
-    DestroyWindow (clipboard_owner);
+    {
+      DestroyWindow (clipboard_owner);
+      clipboard_owner = NULL;
+    }
 }
 
 static void


reply via email to

[Prev in Thread] Current Thread [Next in Thread]