Commit c7041908 authored by Paul Eggert's avatar Paul Eggert
Browse files

Try to avoid malloc SEGVs on Cygwin.

* callproc.c, process.h (block_child_signal, unblock_child_signal):
Now extern.
* emacs.c (main): Catch SIGCHLD just before initializing gfilenotify.
* process.c (catch_child_signal): Block SIGCHLD while futzing with
the SIGCHLD handler, since the code is not atomic and (due to glib)
signals may be arriving now.
* sysdep.c (init_signals): Do not catch child signals here;
'main' now does that later, at a safer time.

Fixes: debbugs:14569
parent 18bb9e21
2013-06-23 Paul Eggert <eggert@cs.ucla.edu>
Try to avoid malloc SEGVs on Cygwin (Bug#14569).
* callproc.c, process.h (block_child_signal, unblock_child_signal):
Now extern.
* emacs.c (main): Catch SIGCHLD just before initializing gfilenotify.
* process.c (catch_child_signal): Block SIGCHLD while futzing with
the SIGCHLD handler, since the code is not atomic and (due to glib)
signals may be arriving now.
* sysdep.c (init_signals): Do not catch child signals here;
'main' now does that later, at a safer time.
2013-06-22 Paul Eggert <eggert@cs.ucla.edu> 2013-06-22 Paul Eggert <eggert@cs.ucla.edu>
Clean up SIGCHLD handling a bit (Bug#14569). Clean up SIGCHLD handling a bit (Bug#14569).
......
...@@ -84,7 +84,7 @@ static int synch_process_fd; ...@@ -84,7 +84,7 @@ static int synch_process_fd;
/* Block SIGCHLD. */ /* Block SIGCHLD. */
static void void
block_child_signal (void) block_child_signal (void)
{ {
sigset_t blocked; sigset_t blocked;
...@@ -95,7 +95,7 @@ block_child_signal (void) ...@@ -95,7 +95,7 @@ block_child_signal (void)
/* Unblock SIGCHLD. */ /* Unblock SIGCHLD. */
static void void
unblock_child_signal (void) unblock_child_signal (void)
{ {
pthread_sigmask (SIG_SETMASK, &empty_mask, 0); pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
......
...@@ -1257,6 +1257,13 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem ...@@ -1257,6 +1257,13 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
tzset (); tzset ();
#endif /* MSDOS */ #endif /* MSDOS */
/* Do this after initializing the memory allocator, since it uses
glib and glib uses malloc. And do it before anything else that
invokes glib, to avoid potential races among glib subthreads in
Cygwin glib. gfilenotify invokes glib, so this can't be delayed
further. */
catch_child_signal ();
#ifdef HAVE_GFILENOTIFY #ifdef HAVE_GFILENOTIFY
globals_of_gfilenotify (); globals_of_gfilenotify ();
#endif #endif
......
...@@ -7084,11 +7084,13 @@ catch_child_signal (void) ...@@ -7084,11 +7084,13 @@ catch_child_signal (void)
#endif #endif
emacs_sigaction_init (&action, deliver_child_signal); emacs_sigaction_init (&action, deliver_child_signal);
block_child_signal ();
sigaction (SIGCHLD, &action, &old_action); sigaction (SIGCHLD, &action, &old_action);
eassert (! (old_action.sa_flags & SA_SIGINFO)); eassert (! (old_action.sa_flags & SA_SIGINFO));
if (old_action.sa_handler != SIG_DFL && old_action.sa_handler != SIG_IGN if (old_action.sa_handler != SIG_DFL && old_action.sa_handler != SIG_IGN
&& old_action.sa_handler != deliver_child_signal) && old_action.sa_handler != deliver_child_signal)
lib_child_handler = old_action.sa_handler; lib_child_handler = old_action.sa_handler;
unblock_child_signal ();
} }
......
...@@ -200,6 +200,8 @@ extern Lisp_Object QCflowcontrol, Qhw, Qsw, QCsummary; ...@@ -200,6 +200,8 @@ extern Lisp_Object QCflowcontrol, Qhw, Qsw, QCsummary;
/* Defined in callproc.c. */ /* Defined in callproc.c. */
extern void block_child_signal (void);
extern void unblock_child_signal (void);
extern void record_kill_process (struct Lisp_Process *); extern void record_kill_process (struct Lisp_Process *);
/* Defined in process.c. */ /* Defined in process.c. */
......
...@@ -1901,8 +1901,6 @@ init_signals (bool dumping) ...@@ -1901,8 +1901,6 @@ init_signals (bool dumping)
sigaction (SIGFPE, &action, 0); sigaction (SIGFPE, &action, 0);
} }
catch_child_signal ();
#ifdef SIGUSR1 #ifdef SIGUSR1
add_user_signal (SIGUSR1, "sigusr1"); add_user_signal (SIGUSR1, "sigusr1");
#endif #endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment