aboutsummaryrefslogtreecommitdiff
path: root/gdb/ser-pipe.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2011-12-14 20:53:57 +0000
committerDoug Evans <dje@google.com>2011-12-14 20:53:57 +0000
commit0b6cb71e500807ed48bc5317bb7ec03b073fc0a0 (patch)
tree876bb7834ffd9b4d1c81f8b97feb39731a6a6664 /gdb/ser-pipe.c
parentafaabefa90aba4f0e37e7ed865ccd64b66dfa354 (diff)
downloadgdb-0b6cb71e500807ed48bc5317bb7ec03b073fc0a0.zip
gdb-0b6cb71e500807ed48bc5317bb7ec03b073fc0a0.tar.gz
gdb-0b6cb71e500807ed48bc5317bb7ec03b073fc0a0.tar.bz2
* 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.
Diffstat (limited to 'gdb/ser-pipe.c')
-rw-r--r--gdb/ser-pipe.c25
1 files changed, 20 insertions, 5 deletions
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 <sys/time.h>
#include <fcntl.h>
#include "gdb_string.h"
-#include "gdb_wait.h"
#include <signal.h>
@@ -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;