diff mbox

Avoid race condition when handling a SIGWINCH signal

Message ID 1431524000-21098-1-git-send-email-patrick@parcs.ath.cx
State New
Headers show

Commit Message

Patrick Palka May 13, 2015, 1:33 p.m. UTC
The control variable win_resized must be cleared before responding to
it.

Otherwise there is a small window where another SIGWINCH might occur in
between the handling of an earlier SIGWINCH and the clearing of
win_resized, at which point win_resized would be set (again) by the
signal handler.  Shortly thereafter we would clear win_resized even
though we only handled the earlier SIGWINCH but not the latest one.
This chain of events is all avoided if we clear win_resized first.

gdb/ChangeLog:

	* tui/tui-win.c (tui_async_resize_screen): Clear win_resized
	first before resizing the window.
	* tui.c (tui_enable): Likewise.
---
 gdb/tui/tui-win.c | 2 +-
 gdb/tui/tui.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Pedro Alves May 13, 2015, 2:17 p.m. UTC | #1
On 05/13/2015 02:33 PM, Patrick Palka wrote:
> The control variable win_resized must be cleared before responding to
> it.
> 
> Otherwise there is a small window where another SIGWINCH might occur in
> between the handling of an earlier SIGWINCH and the clearing of
> win_resized, at which point win_resized would be set (again) by the
> signal handler.  Shortly thereafter we would clear win_resized even
> though we only handled the earlier SIGWINCH but not the latest one.
> This chain of events is all avoided if we clear win_resized first.
> 
> gdb/ChangeLog:
> 
> 	* tui/tui-win.c (tui_async_resize_screen): Clear win_resized
> 	first before resizing the window.
> 	* tui.c (tui_enable): Likewise.

OK.

Thanks,
Pedro Alves
diff mbox

Patch

diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 683c0ed..8c0685b 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -858,10 +858,10 @@  tui_async_resize_screen (gdb_client_data arg)
     }
   else
     {
+      tui_set_win_resized_to (FALSE);
       tui_resize_all ();
       tui_refresh_all_win ();
       tui_update_gdb_sizes ();
-      tui_set_win_resized_to (FALSE);
       tui_redisplay_readline ();
     }
 }
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 9fac06e..b04e106 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -492,8 +492,8 @@  tui_enable (void)
      window.  */
   if (tui_win_resized ())
     {
-      tui_resize_all ();
       tui_set_win_resized_to (FALSE);
+      tui_resize_all ();
     }
 
   if (deprecated_safe_get_selected_frame ())