From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7866 invoked by alias); 30 Aug 2010 19:12:27 -0000 Received: (qmail 7856 invoked by uid 22791); 30 Aug 2010 19:12:26 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 30 Aug 2010 19:12:20 +0000 Received: (qmail 15507 invoked from network); 30 Aug 2010 19:12:18 -0000 Received: from unknown (HELO caradoc.them.org) (dan@127.0.0.2) by mail.codesourcery.com with ESMTPA; 30 Aug 2010 19:12:18 -0000 Date: Mon, 30 Aug 2010 19:12:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org Subject: RFC: Wait for exit after "target remote |" Message-ID: <20100830191215.GH28036@caradoc.them.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-08/txt/msg00531.txt.bz2 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 * 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 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 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 #include #include "gdb_string.h" +#include "gdb_wait.h" #include @@ -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;