From 0dfeed58d3244487a545bb4d4e19658eb299937b Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 22 Jun 2013 12:01:47 -0700 Subject: [PATCH] Clean up SIGCHLD handling a bit. * process.c, process.h (catch_child_signal): Now always extern, even if !NS_IMPL_GNUSTEP. * process.c (catch_child_signal): Move glib tickler here from init_process_emacs, so that it's done earlier in Emacs initialization. Also move the noninteractive && !initialized check here from init_process_emacs. This is all a bit cleaner for GNUish platforms, and I hope it works around the Cygwin bug. * sysdep.c (init_signals): Invoke catch_child_signal here, so that glib signal handling is tickled before glib creates threads. Fixes: debbugs:14569 --- src/ChangeLog | 11 +++++++++++ src/process.c | 35 +++++++++++++++++++---------------- src/process.h | 2 -- src/sysdep.c | 2 ++ 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 36709eb5107..202331dac53 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,16 @@ 2013-06-22 Paul Eggert + Clean up SIGCHLD handling a bit (Bug#14569). + * process.c, process.h (catch_child_signal): + Now always extern, even if !NS_IMPL_GNUSTEP. + * process.c (catch_child_signal): Move glib tickler here from + init_process_emacs, so that it's done earlier in Emacs + initialization. Also move the noninteractive && !initialized + check here from init_process_emacs. This is all a bit cleaner for + GNUish platforms, and I hope it works around the Cygwin bug. + * sysdep.c (init_signals): Invoke catch_child_signal here, so + that glib signal handling is tickled before glib creates threads. + * process.c (wait_reading_process_output): Avoid int overflow when reading more than 2 GiB total from a process. diff --git a/src/process.c b/src/process.c index 0631cb732bf..3e31dede4c2 100644 --- a/src/process.c +++ b/src/process.c @@ -7060,13 +7060,29 @@ integer or floating point values. return system_process_attributes (pid); } -#ifndef NS_IMPL_GNUSTEP -static -#endif +/* Arrange to catch SIGCHLD if needed. */ + void catch_child_signal (void) { struct sigaction action, old_action; + +#if !defined CANNOT_DUMP + if (noninteractive && !initialized) + return; +#endif + +#if defined HAVE_GLIB && !defined WINDOWSNT + /* Tickle glib's child-handling code. Ask glib to wait for Emacs itself; + this should always fail, but is enough to initialize glib's + private SIGCHLD handler, allowing the code below to copy it into + LIB_CHILD_HANDLER. + + Do this early in Emacs initialization, before glib creates + threads, to avoid race condition bugs in Cygwin glib. */ + g_source_unref (g_child_watch_source_new (getpid ())); +#endif + emacs_sigaction_init (&action, deliver_child_signal); sigaction (SIGCHLD, &action, &old_action); eassert (! (old_action.sa_flags & SA_SIGINFO)); @@ -7086,19 +7102,6 @@ init_process_emacs (void) inhibit_sentinels = 0; -#ifndef CANNOT_DUMP - if (! noninteractive || initialized) -#endif - { -#if defined HAVE_GLIB && !defined WINDOWSNT - /* Tickle glib's child-handling code. Ask glib to wait for Emacs itself; - this should always fail, but is enough to initialize glib's - private SIGCHLD handler. */ - g_source_unref (g_child_watch_source_new (getpid ())); -#endif - catch_child_signal (); - } - FD_ZERO (&input_wait_mask); FD_ZERO (&non_keyboard_wait_mask); FD_ZERO (&non_process_wait_mask); diff --git a/src/process.h b/src/process.h index 0c4e17e68cf..9455df18beb 100644 --- a/src/process.h +++ b/src/process.h @@ -217,8 +217,6 @@ extern void add_read_fd (int fd, fd_callback func, void *data); extern void delete_read_fd (int fd); extern void add_write_fd (int fd, fd_callback func, void *data); extern void delete_write_fd (int fd); -#ifdef NS_IMPL_GNUSTEP extern void catch_child_signal (void); -#endif INLINE_HEADER_END diff --git a/src/sysdep.c b/src/sysdep.c index 1d3e646d359..c2769865b5d 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1901,6 +1901,8 @@ init_signals (bool dumping) sigaction (SIGFPE, &action, 0); } + catch_child_signal (); + #ifdef SIGUSR1 add_user_signal (SIGUSR1, "sigusr1"); #endif -- 2.39.2