summaryrefslogtreecommitdiff
path: root/gdb/ser-pipe.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2011-12-14 20:53:56 +0000
committerDoug Evans <dje@google.com>2011-12-14 20:53:56 +0000
commit9dcf5fa00224eba53fbd2f993fc8cc63aa276ebb (patch)
tree187232ec527722d275718be454a247e776e29e55 /gdb/ser-pipe.c
parentfbe5b50a657ba2ff014801fe82a4526ae03fa8c3 (diff)
downloadgdb-9dcf5fa00224eba53fbd2f993fc8cc63aa276ebb.tar.gz
* 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 9bf0d04f306..7f719873db4 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;