[v5,7/8] Introduce set_force_quit_flag and change type of sync_quit_force_run

Message ID 20230222234613.29662-8-kevinb@redhat.com
State Committed
Commit 80d03917838c16ee0da53a4a8642d5df3bee724e
Headers
Series Fix gdb.base/gdb-sigterm.exp failure/error |

Commit Message

Kevin Buettner Feb. 22, 2023, 11:46 p.m. UTC
  At the moment, handle_sigterm() in event-top.c does the following:

  sync_quit_force_run = 1;
  set_quit_flag ();

This was used several more times in a later patch in this series, so
I'm introducing (at Pedro's suggestion) a new function named
'set_force_quit_flag'.  It simply sets sync_quit_force_run and also
calls set_quit_flag().  I've revised the later patch to call
set_force_quit_flag instead.

I noticed that sync_quit_force_run is declared as an int but is being
used as a bool, so I also changed its type to bool in this commit.
---
 gdb/defs.h      |  5 ++++-
 gdb/event-top.c | 13 ++++++++++---
 gdb/utils.c     |  2 +-
 3 files changed, 15 insertions(+), 5 deletions(-)
  

Patch

diff --git a/gdb/defs.h b/gdb/defs.h
index f4fba9acf30..e7c9a39dd89 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -173,7 +173,10 @@  extern quit_handler_ftype *quit_handler;
 extern void default_quit_handler (void);
 
 /* Flag that function quit should call quit_force.  */
-extern volatile int sync_quit_force_run;
+extern volatile bool sync_quit_force_run;
+
+/* Set sync_quit_force_run and also call set_quit_flag().  */
+extern void set_force_quit_flag ();
 
 extern void quit (void);
 
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 563050a4081..eed0ec0eb44 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -1217,7 +1217,15 @@  async_sigterm_handler (gdb_client_data arg)
 }
 
 /* See defs.h.  */
-volatile int sync_quit_force_run;
+volatile bool sync_quit_force_run;
+
+/* See defs.h.  */
+void
+set_force_quit_flag ()
+{
+  sync_quit_force_run = true;
+  set_quit_flag ();
+}
 
 /* Quit GDB if SIGTERM is received.
    GDB would quit anyway, but this way it will clean up properly.  */
@@ -1226,8 +1234,7 @@  handle_sigterm (int sig)
 {
   signal (sig, handle_sigterm);
 
-  sync_quit_force_run = 1;
-  set_quit_flag ();
+  set_force_quit_flag ();
 
   mark_async_signal_handler (async_sigterm_token);
 }
diff --git a/gdb/utils.c b/gdb/utils.c
index 08cc41b4ef8..0138c8e9fb6 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -641,7 +641,7 @@  quit (void)
 {
   if (sync_quit_force_run)
     {
-      sync_quit_force_run = 0;
+      sync_quit_force_run = false;
       throw_forced_quit ("SIGTERM");
     }