From owner-svn-src-head@FreeBSD.ORG Fri Feb 5 18:28:44 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 383C7106566C; Fri, 5 Feb 2010 18:28:44 +0000 (UTC) (envelope-from mjacob@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0E7328FC08; Fri, 5 Feb 2010 18:28:44 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o15IShoU018874; Fri, 5 Feb 2010 18:28:43 GMT (envelope-from mjacob@svn.freebsd.org) Received: (from mjacob@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o15IShnR018871; Fri, 5 Feb 2010 18:28:43 GMT (envelope-from mjacob@svn.freebsd.org) Message-Id: <201002051828.o15IShnR018871@svn.freebsd.org> From: Matt Jacob Date: Fri, 5 Feb 2010 18:28:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r203532 - head/usr.bin/gcore X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Feb 2010 18:28:44 -0000 Author: mjacob Date: Fri Feb 5 18:28:43 2010 New Revision: 203532 URL: http://svn.freebsd.org/changeset/base/203532 Log: Fix gcore so that it can have the '-s' flag without hanging. Modified: head/usr.bin/gcore/extern.h head/usr.bin/gcore/gcore.c Modified: head/usr.bin/gcore/extern.h ============================================================================== --- head/usr.bin/gcore/extern.h Fri Feb 5 18:17:17 2010 (r203531) +++ head/usr.bin/gcore/extern.h Fri Feb 5 18:28:43 2010 (r203532) @@ -38,3 +38,4 @@ struct dumpers { int (*ident)(int efd, pid_t pid, char *binfile); void (*dump)(int efd, int fd, pid_t pid); }; +extern int sflag; Modified: head/usr.bin/gcore/gcore.c ============================================================================== --- head/usr.bin/gcore/gcore.c Fri Feb 5 18:17:17 2010 (r203531) +++ head/usr.bin/gcore/gcore.c Fri Feb 5 18:28:43 2010 (r203532) @@ -65,16 +65,15 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include #include #include #include "extern.h" +int sflag; static void killed(int); -static void restart_target(void); static void usage(void) __dead2; static pid_t pid; @@ -84,7 +83,7 @@ SET_DECLARE(dumpset, struct dumpers); int main(int argc, char *argv[]) { - int ch, efd, fd, name[4], sflag; + int ch, efd, fd, name[4]; char *binfile, *corefile; char passpath[MAXPATHLEN], fname[MAXPATHLEN]; struct dumpers **d, *dumper; @@ -148,36 +147,28 @@ main(int argc, char *argv[]) fd = open(corefile, O_RDWR|O_CREAT|O_TRUNC, DEFFILEMODE); if (fd < 0) err(1, "%s", corefile); - if (sflag) { - signal(SIGHUP, killed); - signal(SIGINT, killed); - signal(SIGTERM, killed); - if (kill(pid, SIGSTOP) == -1) - err(1, "%d: stop signal", pid); - atexit(restart_target); - } + /* + * The semantics of the 's' flag is to stop the target process. + * Previous versions of gcore would manage this by trapping SIGHUP, + * SIGINT and SIGTERM (to be passed to the target pid), and then + * signal the child to stop. + * + * However, this messes up if the selected dumper uses ptrace calls + * that leave the child already stopped. The waitpid call in elfcore + * never returns. + * + * The best thing to do here is to externalize the 's' flag and let + * each dumper dispose of what that means, if anything. For the elfcore + * dumper, the 's' flag is a no-op since the ptrace attach stops the + * process in question already. + */ + dumper->dump(efd, fd, pid); (void)close(fd); (void)close(efd); exit(0); } -static void -killed(int sig) -{ - - restart_target(); - signal(sig, SIG_DFL); - kill(getpid(), sig); -} - -static void -restart_target(void) -{ - - kill(pid, SIGCONT); -} - void usage(void) {