From 0b6cb71e500807ed48bc5317bb7ec03b073fc0a0 Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Wed, 14 Dec 2011 20:53:57 +0000 Subject: * defs.h (wait_to_die_with_timeout): Declare. * utils.c: #include "gdb_wait.h". (sigalrm_handler, wait_to_die_with_timeout): New functions. * ser-pipe.c: Don't #include "gdb_wait.h". (pipe_close): Give child a chance to die on its own after closing its stdin before SIGTERM'ing it. --- gdb/ser-pipe.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'gdb/ser-pipe.c') diff --git a/gdb/ser-pipe.c b/gdb/ser-pipe.c index 9bf0d04..7f71987 100644 --- a/gdb/ser-pipe.c +++ b/gdb/ser-pipe.c @@ -31,7 +31,6 @@ #include #include #include "gdb_string.h" -#include "gdb_wait.h" #include @@ -163,14 +162,30 @@ pipe_close (struct serial *scb) if (state != NULL) { - int status; - kill (state->pid, SIGTERM); -#ifdef HAVE_WAITPID + int wait_result, status; + + /* Don't kill the task right away, give it a chance to shut down cleanly. + But don't wait forever though. */ +#define PIPE_CLOSE_TIMEOUT 5 + /* Assume the program will exit after SIGTERM. Might be useful to print any remaining stderr output from scb->error_fd while waiting. */ - waitpid (state->pid, &status, 0); +#define SIGTERM_TIMEOUT INT_MAX + + wait_result = -1; +#ifdef HAVE_WAITPID + wait_result = wait_to_die_with_timeout (state->pid, &status, + PIPE_CLOSE_TIMEOUT); #endif + if (wait_result == -1) + { + kill (state->pid, SIGTERM); +#ifdef HAVE_WAITPID + wait_to_die_with_timeout (state->pid, &status, SIGTERM_TIMEOUT); +#endif + } + if (scb->error_fd != -1) close (scb->error_fd); scb->error_fd = -1; -- cgit v1.1