public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <dan@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: RFC: Wait for exit after "target remote |"
Date: Mon, 30 Aug 2010 19:12:00 -0000	[thread overview]
Message-ID: <20100830191215.GH28036@caradoc.them.org> (raw)

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;

             reply	other threads:[~2010-08-30 19:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-30 19:12 Daniel Jacobowitz [this message]
2010-09-01  2:07 ` Joel Brobecker
2010-09-02 18:41   ` Daniel Jacobowitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100830191215.GH28036@caradoc.them.org \
    --to=dan@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).