aboutsummaryrefslogtreecommitdiff
path: root/gdb/event-top.c
diff options
context:
space:
mode:
authorJan Kratochvil <jan.kratochvil@redhat.com>2014-03-18 22:48:06 +0100
committerJan Kratochvil <jan.kratochvil@redhat.com>2014-03-18 22:48:06 +0100
commit06c868a8dc5ef46ab7dd6601c8bc2f417e415af9 (patch)
tree7f84cc92cda1b30d22b7356698bae1bf89a2d076 /gdb/event-top.c
parentdea80df0999ae0bad56e79af2a88a30be38bb8e4 (diff)
downloadgdb-06c868a8dc5ef46ab7dd6601c8bc2f417e415af9.zip
gdb-06c868a8dc5ef46ab7dd6601c8bc2f417e415af9.tar.gz
gdb-06c868a8dc5ef46ab7dd6601c8bc2f417e415af9.tar.bz2
Fix SIGTERM signal safety (PR gdb/15358).
gdb/ 2014-03-18 Jan Kratochvil <jan.kratochvil@redhat.com> PR gdb/15358 * defs.h (sync_quit_force_run): New declaration. (QUIT): Check also SYNC_QUIT_FORCE_RUN. * event-top.c (async_sigterm_handler): New declaration. (async_sigterm_token): New variable. (async_init_signals): Create also async_sigterm_token. (async_sigterm_handler): New function. (sync_quit_force_run): New variable. (handle_sigterm): Replace quit_force call by other calls. * utils.c (quit): Call quit_force if SYNC_QUIT_FORCE_RUN. gdb/testsuite/ 2014-03-18 Jan Kratochvil <jan.kratochvil@redhat.com> PR gdb/15358 * gdb.base/gdb-sigterm.c: New file. * gdb.base/gdb-sigterm.exp: New file. Message-ID: <20140316135334.GA30698@host2.jankratochvil.net>
Diffstat (limited to 'gdb/event-top.c')
-rw-r--r--gdb/event-top.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/gdb/event-top.c b/gdb/event-top.c
index fbe89bd..c353f48 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -72,6 +72,7 @@ static void async_float_handler (gdb_client_data);
#ifdef STOP_SIGNAL
static void async_stop_sig (gdb_client_data);
#endif
+static void async_sigterm_handler (gdb_client_data arg);
/* Readline offers an alternate interface, via callback
functions. These are all included in the file callback.c in the
@@ -135,6 +136,7 @@ static struct async_signal_handler *sigfpe_token;
#ifdef STOP_SIGNAL
static struct async_signal_handler *sigtstp_token;
#endif
+static struct async_signal_handler *async_sigterm_token;
/* Structure to save a partially entered command. This is used when
the user types '\' at the end of a command line. This is necessary
@@ -733,6 +735,8 @@ async_init_signals (void)
sigint_token =
create_async_signal_handler (async_request_quit, NULL);
signal (SIGTERM, handle_sigterm);
+ async_sigterm_token
+ = create_async_signal_handler (async_sigterm_handler, NULL);
/* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
to the inferior and breakpoints will be ignored. */
@@ -769,7 +773,6 @@ async_init_signals (void)
sigtstp_token =
create_async_signal_handler (async_stop_sig, NULL);
#endif
-
}
/* Tell the event loop what to do if SIGINT is received.
@@ -797,13 +800,33 @@ handle_sigint (int sig)
gdb_call_async_signal_handler (sigint_token, immediate_quit);
}
+/* Handle GDB exit upon receiving SIGTERM if target_can_async_p (). */
+
+static void
+async_sigterm_handler (gdb_client_data arg)
+{
+ quit_force (NULL, stdin == instream);
+}
+
+/* See defs.h. */
+volatile int sync_quit_force_run;
+
/* Quit GDB if SIGTERM is received.
GDB would quit anyway, but this way it will clean up properly. */
void
handle_sigterm (int sig)
{
signal (sig, handle_sigterm);
- quit_force ((char *) 0, stdin == instream);
+
+ /* Call quit_force in a signal safe way.
+ quit_force itself is not signal safe. */
+ if (target_can_async_p ())
+ mark_async_signal_handler (async_sigterm_token);
+ else
+ {
+ sync_quit_force_run = 1;
+ set_quit_flag ();
+ }
}
/* Do the quit. All the checks have been done by the caller. */