svn commit: r216768 - stable/8/usr.bin/gcore

John Baldwin jhb at FreeBSD.org
Tue Dec 28 18:56:56 UTC 2010


Author: jhb
Date: Tue Dec 28 18:56:55 2010
New Revision: 216768
URL: http://svn.freebsd.org/changeset/base/216768

Log:
  MFC 203532: Fix gcore so that it can have the '-s' flag without hanging.

Modified:
  stable/8/usr.bin/gcore/gcore.c
Directory Properties:
  stable/8/usr.bin/gcore/   (props changed)

Modified: stable/8/usr.bin/gcore/gcore.c
==============================================================================
--- stable/8/usr.bin/gcore/gcore.c	Tue Dec 28 18:37:10 2010	(r216767)
+++ stable/8/usr.bin/gcore/gcore.c	Tue Dec 28 18:56:55 2010	(r216768)
@@ -65,7 +65,6 @@ __FBSDID("$FreeBSD$");
 
 #include <err.h>
 #include <fcntl.h>
-#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -75,7 +74,6 @@ __FBSDID("$FreeBSD$");
 int pflags;
 
 static void	killed(int);
-static void	restart_target(void);
 static void	usage(void) __dead2;
 
 static pid_t pid;
@@ -152,36 +150,28 @@ main(int argc, char *argv[])
 	fd = open(corefile, O_RDWR|O_CREAT|O_TRUNC, DEFFILEMODE);
 	if (fd < 0)
 		err(1, "%s", corefile);
-	if ((pflags & PFLAGS_RESUME) != 0) {
-		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)
 {


More information about the svn-src-stable-8 mailing list