From owner-p4-projects@FreeBSD.ORG Thu Jan 29 15:54:04 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id D38061065670; Thu, 29 Jan 2009 15:54:03 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8F008106566B for ; Thu, 29 Jan 2009 15:54:03 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 60FDD8FC19 for ; Thu, 29 Jan 2009 15:54:03 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n0TFs3tv089194 for ; Thu, 29 Jan 2009 15:54:03 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n0TFs3LN089192 for perforce@freebsd.org; Thu, 29 Jan 2009 15:54:03 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Thu, 29 Jan 2009 15:54:03 GMT Message-Id: <200901291554.n0TFs3LN089192@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 156866 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jan 2009 15:54:05 -0000 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 @@ -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); }