diff options
| author | Paul Eggert <eggert@cs.ucla.edu> | 2012-09-23 01:44:20 -0700 |
|---|---|---|
| committer | Paul Eggert <eggert@cs.ucla.edu> | 2012-09-23 01:44:20 -0700 |
| commit | 4d7e6e51dd4acecff466a28d958c50f34fc130b8 (patch) | |
| tree | 5e340d48fb69f9a40a4304cc94db2006caefe51f /src/gtkutil.c | |
| parent | 8f4635e97e1587c4026ec83fc1bd9f8954775915 (diff) | |
| download | emacs-4d7e6e51dd4acecff466a28d958c50f34fc130b8.tar.gz | |
Simplify and avoid signal-handling races.
* nt/inc/ms-w32.h (emacs_raise): New macro.
* src/alloc.c (die):
* src/sysdep.c (emacs_abort) [HAVE_NTGUI]:
Avoid recursive loop if there's a fatal error in the function itself.
* src/atimer.c (pending_atimers):
* src/blockinput.h: Don't include "atimer.h"; no longer needed.
(interrupt_input_pending): Remove. All uses removed.
pending_signals now counts both atimers and ordinary interrupts.
This is less racy than having three separate pending-signal flags.
(block_input, unblock_input, totally_unblock_input, unblock_input_to)
(input_blocked_p):
Rename from their upper-case counterparts BLOCK_INPUT,
UNBLOCK_INPUT, TOTALLY_UNBLOCK_INPUT, UNBLOCK_INPUT_TO,
INPUT_BLOCKED_P, and turn into functions. All uses changed.
This makes it easier to access volatile variables more accurately.
(BLOCK_INPUT_RESIGNAL): Remove. All uses replaced by unblock_input ().
(input_blocked_p): Prefer this to 'interrupt_input_blocked', as
that's more reliable if the code is buggy and sets
interrupt_input_blocked to a negative value. All uses changed.
* src/atimer.c (deliver_alarm_signal):
Remove. No need to deliver this to the parent; any thread can
handle this signal now. All uses replaced by underlying handler.
* src/atimer.c (turn_on_atimers):
* src/dispnew.c (handle_window_change_signal):
* src/emacs.c (handle_danger_signal):
* src/keyboard.c (kbd_buffer_get_event):
Don't reestablish signal handler; not needed with sigaction.
* src/blockinput.h (UNBLOCK_INPUT_TO, TOTALLY_UNBLOCK_INPUT)
(UNBLOCK_INPUT_TO):
Rework to avoid unnecessary accesses to volatile variables.
(UNBLOCK_INPUT_TO): Now a function.
(totally_unblock_input, unblock_input): New decls.
* src/data.c (handle_arith_signal, deliver_arith_signal): Move to sysdep.c
(init_data): Remove. Necessary stuff now done in init_signal.
* src/emacs.c, src/xdisp.c: Include "atimer.h", since we invoke atimer functions.
* src/emacs.c (handle_fatal_signal, deliver_fatal_signal): Move to sysdep.c.
(fatal_error_code): Remove; no longer needed.
(terminate_due_to_signal): Rename from fatal_error_backtrace, since
it doesn't always backtrace. All uses changed. No need to reset
signal to default, since sigaction and/or die does that for us now.
Use emacs_raise (FOO), not kill (getpid (), FOO).
(main): Check more-accurately whether we're dumping.
Move fatal-error setup to sysdep.c
* src/floatfns.c: Do not include "syssignal.h"; no longer needed.
* src/gtkutil.c (xg_get_file_name, xg_get_font):
Remove no-longer-needed signal-mask manipulation.
* src/keyboard.c, src/process.c (POLL_FOR_INPUT):
Don't depend on USE_ASYNC_EVENTS, a symbol that is never defined.
* src/keyboard.c (read_avail_input): Remove.
All uses replaced by gobble_input.
(Ftop_level): Use TOTALLY_UNBLOCK_INPUT rather than open code.
(kbd_buffer_store_event_hold, gobble_input):
(record_asynch_buffer_change) [USABLE_SIGIO]:
(store_user_signal_events):
No need to mess with signal mask.
(gobble_input): If blocking input and there are terminals, simply
set pending_signals to 1 and return. All hooks changed to not
worry about whether input is blocked.
(process_pending_signals): Clear pending_signals before processing
them, in case a signal comes in while we're processing.
By convention callers now test pending_signals before calling us.
(UNBLOCK_INPUT_TO, unblock_input, totally_unblock_input):
New functions, to support changes to blockinput.h.
(handle_input_available_signal): Now extern.
(reinvoke_input_signal): Remove. All uses replaced by
handle_async_input.
(quit_count): Now volatile, since a signal handler uses it.
(handle_interrupt): Now takes bool IN_SIGNAL_HANDLER as arg. All
callers changed. Block SIGINT only if not already blocked.
Clear sigmask reliably, even if Fsignal returns, which it can.
Omit unnecessary accesses to volatile var.
(quit_throw_to_read_char): No need to restore sigmask.
* src/keyboard.c (gobble_input, handle_user_signal):
* src/process.c (wait_reading_process_output):
Call signal-handling code rather than killing ourselves.
* src/lisp.h: Include <float.h>, for...
(IEEE_FLOATING_POINT): New macro, moved here to avoid duplication.
(pending_signals): Now volatile.
(syms_of_data): Now const if IEEE floating point.
(handle_input_available_signal) [USABLE_SIGIO]:
(terminate_due_to_signal, record_child_status_change): New decls.
* src/process.c (create_process): Avoid disaster if memory is exhausted
while we're processing a vfork, by tightening the critical section
around the vfork.
(send_process_frame, process_sent_to, handle_pipe_signal)
(deliver_pipe_signal): Remove. No longer needed, as Emacs now
ignores SIGPIPE.
(send_process): No need for setjmp/longjmp any more, since the
SIGPIPE stuff is now gone. Instead, report an error if errno
is EPIPE.
(record_child_status_change): Now extern. PID and W are now args.
Return void, not bool. All callers changed.
* src/sysdep.c (wait_debugging) [(BSD_SYSTEM || HPUX) && !defined (__GNU__)]:
Remove. All uses removed. This bug should be fixed now in a
different way.
(wait_for_termination_1): Use waitpid rather than sigsuspend,
and record the child status change directly. This avoids the
need to futz with the signal mask.
(process_fatal_action): Move here from emacs.c.
(emacs_sigaction_flags): New function, containing
much of what used to be in emacs_sigaction_init.
(emacs_sigaction_init): Use it. Block nonfatal system signals that are
caught by emacs, to make races less likely.
(deliver_process_signal): Rename from handle_on_main_thread.
All uses changed.
(BACKTRACE_LIMIT_MAX): Now at top level.
(thread_backtrace_buffer, threadback_backtrace_pointers):
New static vars.
(deliver_thread_signal, deliver_fatal_thread_signal):
New functions, for more-accurate delivery of thread-specific signals.
(handle_fatal_signal, deliver_fatal_signal): Move here from emacs.c.
(deliver_arith_signal): Handle in this thread, not
in the main thread, since it's triggered by this thread.
(maybe_fatal_sig): New function.
(init_signals): New arg DUMPING so that we can be more accurate
about whether we're dumping. Caller changed.
Treat thread-specific signals differently from process-general signals.
Block all signals while handling fatal error; that's safer.
xsignal from SIGFPE only on non-IEEE hosts, treating it as fatal
on IEEE hosts.
When batch, ignore SIGHUP, SIGINT, SIGTERM if they were already ignored.
Ignore SIGPIPE unless batch.
(emacs_backtrace): Output backtrace for the appropriate thread,
which is not necessarily the main thread.
* src/syssignal.h: Include <stdbool.h>.
(emacs_raise): New macro.
* src/xterm.c (x_connection_signal): Remove; no longer needed
now that we use sigaction.
(x_connection_closed): No need to mess with sigmask now.
(x_initialize): No need to reset SIGPIPE handler here, since
init_signals does this for us now.
Fixes: debbugs:12471
Diffstat (limited to 'src/gtkutil.c')
| -rw-r--r-- | src/gtkutil.c | 91 |
1 files changed, 32 insertions, 59 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c index 1eb4b2cabdf..bf635250380 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -590,7 +590,7 @@ xg_check_special_colors (struct frame *f, if (! FRAME_GTK_WIDGET (f) || ! (get_bg || get_fg)) return success_p; - BLOCK_INPUT; + block_input (); { #ifdef HAVE_GTK3 GtkStyleContext *gsty @@ -620,7 +620,7 @@ xg_check_special_colors (struct frame *f, #endif } - UNBLOCK_INPUT; + unblock_input (); return success_p; } @@ -725,7 +725,7 @@ xg_prepare_tooltip (FRAME_PTR f, if (!x->ttip_lbl) return 0; - BLOCK_INPUT; + block_input (); encoded_string = ENCODE_UTF_8 (string); widget = GTK_WIDGET (x->ttip_lbl); gwin = gtk_widget_get_window (GTK_WIDGET (x->ttip_window)); @@ -753,7 +753,7 @@ xg_prepare_tooltip (FRAME_PTR f, if (width) *width = req.width; if (height) *height = req.height; - UNBLOCK_INPUT; + unblock_input (); return 1; #endif /* USE_GTK_TOOLTIP */ @@ -769,10 +769,10 @@ xg_show_tooltip (FRAME_PTR f, int root_x, int root_y) struct x_output *x = f->output_data.x; if (x->ttip_window) { - BLOCK_INPUT; + block_input (); gtk_window_move (x->ttip_window, root_x, root_y); gtk_widget_show_all (GTK_WIDGET (x->ttip_window)); - UNBLOCK_INPUT; + unblock_input (); } #endif } @@ -789,7 +789,7 @@ xg_hide_tooltip (FRAME_PTR f) if (f->output_data.x->ttip_window) { GtkWindow *win = f->output_data.x->ttip_window; - BLOCK_INPUT; + block_input (); gtk_widget_hide (GTK_WIDGET (win)); if (g_object_get_data (G_OBJECT (win), "restore-tt")) @@ -799,7 +799,7 @@ xg_hide_tooltip (FRAME_PTR f) GtkSettings *settings = gtk_settings_get_for_screen (screen); g_object_set (settings, "gtk-enable-tooltips", TRUE, NULL); } - UNBLOCK_INPUT; + unblock_input (); ret = 1; } @@ -1007,7 +1007,7 @@ xg_win_to_widget (Display *dpy, Window wdesc) gpointer gdkwin; GtkWidget *gwdesc = 0; - BLOCK_INPUT; + block_input (); gdkwin = gdk_x11_window_lookup_for_display (gdk_x11_lookup_xdisplay (dpy), wdesc); @@ -1019,7 +1019,7 @@ xg_win_to_widget (Display *dpy, Window wdesc) gwdesc = gtk_get_event_widget (&event); } - UNBLOCK_INPUT; + unblock_input (); return gwdesc; } @@ -1123,7 +1123,7 @@ xg_create_frame_widgets (FRAME_PTR f) #endif char *title = 0; - BLOCK_INPUT; + block_input (); if (FRAME_X_EMBEDDED_P (f)) { @@ -1161,7 +1161,7 @@ xg_create_frame_widgets (FRAME_PTR f) if (whbox) gtk_widget_destroy (whbox); if (wfixed) gtk_widget_destroy (wfixed); - UNBLOCK_INPUT; + unblock_input (); return 0; } @@ -1275,7 +1275,7 @@ xg_create_frame_widgets (FRAME_PTR f) } } - UNBLOCK_INPUT; + unblock_input (); return 1; } @@ -1397,12 +1397,12 @@ x_wm_set_size_hint (FRAME_PTR f, long int flags, int user_position) &f->output_data.x->size_hints, sizeof (size_hints)) != 0) { - BLOCK_INPUT; + block_input (); gtk_window_set_geometry_hints (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), NULL, &size_hints, hint_flags); f->output_data.x->size_hints = size_hints; f->output_data.x->hint_flags = hint_flags; - UNBLOCK_INPUT; + unblock_input (); } } @@ -1417,9 +1417,9 @@ xg_set_background_color (FRAME_PTR f, long unsigned int bg) { if (FRAME_GTK_WIDGET (f)) { - BLOCK_INPUT; + block_input (); xg_set_widget_bg (f, FRAME_GTK_WIDGET (f), FRAME_BACKGROUND_PIXEL (f)); - UNBLOCK_INPUT; + unblock_input (); } } @@ -1637,14 +1637,14 @@ pop_down_dialog (Lisp_Object arg) struct Lisp_Save_Value *p = XSAVE_VALUE (arg); struct xg_dialog_data *dd = (struct xg_dialog_data *) p->pointer; - BLOCK_INPUT; + block_input (); if (dd->w) gtk_widget_destroy (dd->w); if (dd->timerid != 0) g_source_remove (dd->timerid); g_main_loop_quit (dd->loop); g_main_loop_unref (dd->loop); - UNBLOCK_INPUT; + unblock_input (); return Qnil; } @@ -1973,16 +1973,6 @@ xg_get_file_name (FRAME_PTR f, int filesel_done = 0; xg_get_file_func func; -#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN) - /* I really don't know why this is needed, but without this the GLIBC add on - library linuxthreads hangs when the Gnome file chooser backend creates - threads. */ - sigset_t blocked; - sigemptyset (&blocked); - sigaddset (&blocked, __SIGRTMIN); - pthread_sigmask (SIG_BLOCK, &blocked, 0); -#endif /* HAVE_PTHREAD */ - #ifdef HAVE_GTK_FILE_SELECTION_NEW if (xg_uses_old_file_dialog ()) @@ -2000,11 +1990,6 @@ xg_get_file_name (FRAME_PTR f, gtk_widget_set_name (w, "emacs-filedialog"); filesel_done = xg_dialog_run (f, w); - -#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN) - pthread_sigmask (SIG_UNBLOCK, &blocked, 0); -#endif - if (filesel_done == GTK_RESPONSE_OK) fn = (*func) (w); @@ -2057,13 +2042,6 @@ xg_get_font (FRAME_PTR f, const char *default_name) int done = 0; Lisp_Object font = Qnil; -#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN) - sigset_t blocked; - sigemptyset (&blocked); - sigaddset (&blocked, __SIGRTMIN); - pthread_sigmask (SIG_BLOCK, &blocked, 0); -#endif /* HAVE_PTHREAD */ - w = gtk_font_chooser_dialog_new ("Pick a font", GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); @@ -2088,11 +2066,6 @@ xg_get_font (FRAME_PTR f, const char *default_name) gtk_widget_set_name (w, "emacs-fontdialog"); done = xg_dialog_run (f, w); - -#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN) - pthread_sigmask (SIG_UNBLOCK, &blocked, 0); -#endif - if (done == GTK_RESPONSE_OK) { #if USE_NEW_GTK_FONT_CHOOSER @@ -3358,7 +3331,7 @@ xg_update_frame_menubar (FRAME_PTR f) if (x->menubar_widget && gtk_widget_get_parent (x->menubar_widget)) return 0; /* Already done this, happens for frames created invisible. */ - BLOCK_INPUT; + block_input (); gtk_box_pack_start (GTK_BOX (x->vbox_widget), x->menubar_widget, FALSE, FALSE, 0); @@ -3378,7 +3351,7 @@ xg_update_frame_menubar (FRAME_PTR f) FRAME_MENUBAR_HEIGHT (f) = req.height; xg_height_or_width_changed (f); } - UNBLOCK_INPUT; + unblock_input (); return 1; } @@ -3393,7 +3366,7 @@ free_frame_menubar (FRAME_PTR f) if (x->menubar_widget) { - BLOCK_INPUT; + block_input (); gtk_container_remove (GTK_CONTAINER (x->vbox_widget), x->menubar_widget); /* The menubar and its children shall be deleted when removed from @@ -3401,7 +3374,7 @@ free_frame_menubar (FRAME_PTR f) x->menubar_widget = 0; FRAME_MENUBAR_HEIGHT (f) = 0; xg_height_or_width_changed (f); - UNBLOCK_INPUT; + unblock_input (); } } @@ -3838,7 +3811,7 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar, if (changed || int_gtk_range_get_value (GTK_RANGE (wscroll)) != value) { - BLOCK_INPUT; + block_input (); /* gtk_range_set_value invokes the callback. Set ignore_gtk_scrollbar to make the callback do nothing */ @@ -3851,7 +3824,7 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar, xg_ignore_gtk_scrollbar = 0; - UNBLOCK_INPUT; + unblock_input (); } } } @@ -4642,7 +4615,7 @@ update_frame_tool_bar (FRAME_PTR f) if (! FRAME_GTK_WIDGET (f)) return; - BLOCK_INPUT; + block_input (); if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX)) { @@ -4684,7 +4657,7 @@ update_frame_tool_bar (FRAME_PTR f) && ! NILP (Fequal (tbinfo->style, style)) && ! NILP (Fequal (tbinfo->last_tool_bar, f->tool_bar_items))) { - UNBLOCK_INPUT; + unblock_input (); return; } @@ -4895,7 +4868,7 @@ update_frame_tool_bar (FRAME_PTR f) xg_height_or_width_changed (f); } - UNBLOCK_INPUT; + unblock_input (); } /* Deallocate all resources for the tool bar on frame F. @@ -4910,7 +4883,7 @@ free_frame_tool_bar (FRAME_PTR f) { struct xg_frame_tb_info *tbinfo; int is_packed = x->handlebox_widget != 0; - BLOCK_INPUT; + block_input (); /* We may have created the toolbar_widget in xg_create_tool_bar, but not the x->handlebox_widget which is created in xg_pack_tool_bar. */ if (is_packed) @@ -4942,7 +4915,7 @@ free_frame_tool_bar (FRAME_PTR f) xg_height_or_width_changed (f); - UNBLOCK_INPUT; + unblock_input (); } } @@ -4954,7 +4927,7 @@ xg_change_toolbar_position (FRAME_PTR f, Lisp_Object pos) if (! x->toolbar_widget || ! x->handlebox_widget) return 1; - BLOCK_INPUT; + block_input (); g_object_ref (x->handlebox_widget); if (x->toolbar_in_hbox) gtk_container_remove (GTK_CONTAINER (x->hbox_widget), @@ -4967,7 +4940,7 @@ xg_change_toolbar_position (FRAME_PTR f, Lisp_Object pos) if (xg_update_tool_bar_sizes (f)) xg_height_or_width_changed (f); - UNBLOCK_INPUT; + unblock_input (); return 1; } |
