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>
This commit is contained in:
Jan Kratochvil
2014-03-18 22:48:06 +01:00
parent dea80df099
commit 06c868a8dc
7 changed files with 176 additions and 3 deletions

View File

@@ -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. */