This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RFC: Wait for exit after "target remote |"
- From: Daniel Jacobowitz <dan at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 30 Aug 2010 15:12:16 -0400
- Subject: RFC: Wait for exit after "target remote |"
While looking at cpexprs.exp I found that halfway through the test my
system had hundreds of zombie simulator processes. Turns out,
ser-pipe forks and execs but never ever waits! This bug has been
lurking for years.
Does anyone think this patch is a bad idea? It's straightforward
enough; we've already sent SIGTERM, so then call waitpid. If the
child is wedged and does not respond to SIGTERM, then GDB may hang;
it's not trivial to retry and send SIGKILL. But, IMO, that's not a
likely scenario.
Comments welcome!
--
Daniel Jacobowitz
CodeSourcery
2010-08-30 Daniel Jacobowitz <dan@codesourcery.com>
* config.in, configure: Regenerated.
* configure.ac: Check for waitpid.
* ser-pipe.c (pipe_close): Wait for the program to exit.
Index: config.in
===================================================================
RCS file: /cvs/src/src/gdb/config.in,v
retrieving revision 1.122
diff -u -p -r1.122 config.in
--- config.in 28 Jul 2010 23:24:57 -0000 1.122
+++ config.in 30 Aug 2010 19:08:28 -0000
@@ -676,6 +676,9 @@
/* Define to 1 if you have the <vfork.h> header file. */
#undef HAVE_VFORK_H
+/* Define to 1 if you have the `waitpid' function. */
+#undef HAVE_WAITPID
+
/* Define to 1 if you have the <wait.h> header file. */
#undef HAVE_WAIT_H
Index: configure
===================================================================
RCS file: /cvs/src/src/gdb/configure,v
retrieving revision 1.315
diff -u -p -r1.315 configure
--- configure 18 Aug 2010 22:57:46 -0000 1.315
+++ configure 30 Aug 2010 19:08:29 -0000
@@ -12550,7 +12550,7 @@ for ac_func in canonicalize_file_name re
getgid pipe poll pread64 resize_term sbrk setpgid setpgrp setsid \
sigaction sigprocmask sigsetmask socketpair syscall \
ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
- setrlimit getrlimit posix_madvise
+ setrlimit getrlimit posix_madvise waitpid
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
Index: configure.ac
===================================================================
RCS file: /cvs/src/src/gdb/configure.ac,v
retrieving revision 1.129
diff -u -p -r1.129 configure.ac
--- configure.ac 18 Aug 2010 22:57:46 -0000 1.129
+++ configure.ac 30 Aug 2010 19:08:29 -0000
@@ -962,7 +962,7 @@ AC_CHECK_FUNCS([canonicalize_file_name r
getgid pipe poll pread64 resize_term sbrk setpgid setpgrp setsid \
sigaction sigprocmask sigsetmask socketpair syscall \
ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
- setrlimit getrlimit posix_madvise])
+ setrlimit getrlimit posix_madvise waitpid])
AM_LANGINFO_CODESET
# Check the return and argument types of ptrace. No canned test for
Index: ser-pipe.c
===================================================================
RCS file: /cvs/src/src/gdb/ser-pipe.c,v
retrieving revision 1.28
diff -u -p -r1.28 ser-pipe.c
--- ser-pipe.c 20 Aug 2010 18:49:20 -0000 1.28
+++ ser-pipe.c 30 Aug 2010 19:08:29 -0000
@@ -31,6 +31,7 @@
#include <sys/time.h>
#include <fcntl.h>
#include "gdb_string.h"
+#include "gdb_wait.h"
#include <signal.h>
@@ -162,11 +163,14 @@ pipe_close (struct serial *scb)
if (state != NULL)
{
+ int status;
kill (state->pid, SIGTERM);
- /* Might be useful to check that the child does die,
- and while we're waiting for it to die print any remaining
- stderr output. */
-
+#ifdef HAVE_WAITPID
+ /* 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);
+#endif
if (scb->error_fd != -1)
close (scb->error_fd);
scb->error_fd = -1;