Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Jan 2009 15:54:03 GMT
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 156866 for review
Message-ID:  <200901291554.n0TFs3LN089192@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=156866

Change 156866 by rwatson@rwatson_freebsd_capabilities on 2009/01/29 15:53:27

	New regression test: confirm that when a process that has created
	process descriptor children dies, its children also die.  This is
	a little different than the regression test that checks that
	closing a descriptor kills the child, as it exercises the case
	where the parent is dead by the time the child dies.

Affected files ...

.. //depot/projects/trustedbsd/capabilities/src/tools/regression/procdesc/procdesc_test.c#6 edit

Differences ...

==== //depot/projects/trustedbsd/capabilities/src/tools/regression/procdesc/procdesc_test.c#6 (text+ko) ====

@@ -30,7 +30,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $P4: //depot/projects/trustedbsd/capabilities/src/tools/regression/procdesc/procdesc_test.c#5 $
+ * $P4: //depot/projects/trustedbsd/capabilities/src/tools/regression/procdesc/procdesc_test.c#6 $
  */
 
 #include <sys/types.h>
@@ -58,8 +58,8 @@
 main(int argc, char *argv[])
 {
 	struct stat sb;
-	pid_t pid, realpid;
-	int fd;
+	pid_t parentpid, pid, realpid;
+	int error, fd, pipefd[2];
 
 	printf("1. pdfork() and allow to exit before close().\n");
 
@@ -182,6 +182,42 @@
 		if (errno != ECHILD)
 			err(-1, "waitpid unexpected error %d", errno);
 	}
+	close(fd);
+
+	printf("5. Confirm killing parent kills child\n");
+
+	if (pipe(pipefd) < 0)
+		err(-1, "pipe");
+	parentpid = fork();
+	if (parentpid < 0)
+		err(-1, "fork");
+	if (parentpid == 0) {
+		realpid = pdfork(&fd);
+		if (realpid < 0)
+			err(-1, "pdfork");
+		if (realpid == 0) {
+			while (1)
+				sleep(1);
+		} else {
+			if (write(pipefd[1], &realpid, sizeof(realpid)) < 0)
+				err(-1, "write");
+		}
+		exit(0);
+	} else {
+		if (read(pipefd[0], &realpid, sizeof(realpid)) < 0)
+			err(-1, "read");
+		pid = waitpid(parentpid, NULL, 0);
+		if (pid != parentpid)
+			errx(-1, "waitpid returned unexpected pid %d", pid);
+		sleep(1);
+		error = kill(realpid, 0);
+		if (error < 0 && errno != ESRCH)
+			err(-1, "process didn't die");
+		if (error == 0)
+			errx(-1, "process didn't die");
+	}
+	close(pipefd[0]);
+	close(pipefd[1]);
 
 	exit(0);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200901291554.n0TFs3LN089192>