aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
authorPaul Eggert2012-09-05 14:33:53 -0700
committerPaul Eggert2012-09-05 14:33:53 -0700
commit20ef56dbc88f517ebf60d89577fc89870d9fe888 (patch)
treee93c0bc49e89e86836575b2b4443c699a237621d /src/data.c
parenta4e6c042f8f66c47209d76d863adbf5ea3f84a96 (diff)
downloademacs-20ef56dbc88f517ebf60d89577fc89870d9fe888.tar.gz
emacs-20ef56dbc88f517ebf60d89577fc89870d9fe888.zip
Fix race conditions with signal handlers and errno.
Be more systematic about preserving errno whenever a signal handler returns, even if it's not in the main thread. Do this by renaming signal handlers to distinguish between signal delivery and signal handling. All uses changed. * atimer.c (deliver_alarm_signal): Rename from alarm_signal_handler. * data.c (deliver_arith_signal): Rename from arith_error. * dispnew.c (deliver_window_change_signal): Rename from window_change_signal. * emacs.c (deliver_error_signal): Rename from fatal_error_signal. (deliver_danger_signal) [SIGDANGER]: Rename from memory_warning_signal. * keyboard.c (deliver_input_available_signal): Rename from input_available_signal. (deliver_user_signal): Rename from handle_user_signal. (deliver_interrupt_signal): Rename from interrupt_signal. * process.c (deliver_pipe_signal): Rename from send_process_trap. (deliver_child_signal): Rename from sigchld_handler. * atimer.c (handle_alarm_signal): * data.c (handle_arith_signal): * dispnew.c (handle_window_change_signal): * emacs.c (handle_fatal_signal, handle_danger_signal): * keyboard.c (handle_input_available_signal): * keyboard.c (handle_user_signal, handle_interrupt_signal): * process.c (handle_pipe_signal, handle_child_signal): New functions, with the actual signal-handling code taken from the original respective signal handlers, sans the sporadic attempts to preserve errno, since that's now done by handle_on_main_thread. * atimer.c (alarm_signal_handler): Remove unnecessary decl. * emacs.c, floatfns.c, lisp.h: Remove unused FLOAT_CATCH_SIGKILL cruft. * emacs.c (main_thread) [FORWARD_SIGNAL_TO_MAIN_THREAD]: Move to sysdep.c. (main) [FORWARD_SIGNAL_TO_MAIN_THREAD]: Move initialization of main_thread to sysdep.c's init_signals. * process.c (waitpid) [!WNOHANG]: #define to wait; that's good enough for our usage, and simplifies the mainline code. (record_child_status_change): New static function, as a helper for handle_child_signal, and with most of the old child handler's contents. (CAN_HANDLE_MULTIPLE_CHILDREN): New constant. (handle_child_signal): Use the above. * sysdep.c (main_thread) [FORWARD_SIGNAL_TO_MAIN_THREAD]: Moved here from emacs.c. (init_signals) [FORWARD_SIGNAL_TO_MAIN_THREAD]: Initialize it; code moved here from emacs.c's main function. * sysdep.c, syssignal.h (handle_on_main_thread): New function, replacing the old SIGNAL_THREAD_CHECK. All uses changed. This lets callers save and restore errno properly.
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/data.c b/src/data.c
index 415a8962350..6151d815b29 100644
--- a/src/data.c
+++ b/src/data.c
@@ -3207,18 +3207,19 @@ syms_of_data (void)
3207 XSYMBOL (intern_c_string ("most-negative-fixnum"))->constant = 1; 3207 XSYMBOL (intern_c_string ("most-negative-fixnum"))->constant = 1;
3208} 3208}
3209 3209
3210#ifndef FORWARD_SIGNAL_TO_MAIN_THREAD 3210static _Noreturn void
3211_Noreturn 3211handle_arith_signal (int sig)
3212#endif
3213static void
3214arith_error (int signo)
3215{ 3212{
3216 sigsetmask (SIGEMPTYMASK); 3213 sigsetmask (SIGEMPTYMASK);
3217
3218 SIGNAL_THREAD_CHECK (signo);
3219 xsignal0 (Qarith_error); 3214 xsignal0 (Qarith_error);
3220} 3215}
3221 3216
3217static void
3218deliver_arith_signal (int sig)
3219{
3220 handle_on_main_thread (sig, handle_arith_signal);
3221}
3222
3222void 3223void
3223init_data (void) 3224init_data (void)
3224{ 3225{
@@ -3230,5 +3231,5 @@ init_data (void)
3230 if (!initialized) 3231 if (!initialized)
3231 return; 3232 return;
3232#endif /* CANNOT_DUMP */ 3233#endif /* CANNOT_DUMP */
3233 signal (SIGFPE, arith_error); 3234 signal (SIGFPE, deliver_arith_signal);
3234} 3235}