From owner-svn-src-user@FreeBSD.ORG Sat Aug 16 07:01:43 2014 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5A06913C; Sat, 16 Aug 2014 07:01:43 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3AA99267A; Sat, 16 Aug 2014 07:01:43 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7G71gjE070407; Sat, 16 Aug 2014 07:01:42 GMT (envelope-from pho@FreeBSD.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s7G71g7I069881; Sat, 16 Aug 2014 07:01:42 GMT (envelope-from pho@FreeBSD.org) Message-Id: <201408160701.s7G71g7I069881@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: pho set sender to pho@FreeBSD.org using -f From: Peter Holm Date: Sat, 16 Aug 2014 07:01:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r270037 - user/pho/stress2/misc X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Aug 2014 07:01:43 -0000 Author: pho Date: Sat Aug 16 07:01:42 2014 New Revision: 270037 URL: http://svnweb.freebsd.org/changeset/base/270037 Log: Added new regression test, fixed trailing blanks in old tests. Sponsored by: EMC / Isilon storage division Added: user/pho/stress2/misc/ptrace3.sh (contents, props changed) Modified: user/pho/stress2/misc/ptrace.sh user/pho/stress2/misc/ptrace2.sh Modified: user/pho/stress2/misc/ptrace.sh ============================================================================== --- user/pho/stress2/misc/ptrace.sh Sat Aug 16 03:05:02 2014 (r270036) +++ user/pho/stress2/misc/ptrace.sh Sat Aug 16 07:01:42 2014 (r270037) @@ -37,7 +37,7 @@ cc -o ptrace -Wall -Wextra -g ptrace.c | rm -f ptrace.c cd $here -/tmp/ptrace +/tmp/ptrace rm -f /tmp/ptrace exit Modified: user/pho/stress2/misc/ptrace2.sh ============================================================================== --- user/pho/stress2/misc/ptrace2.sh Sat Aug 16 03:05:02 2014 (r270036) +++ user/pho/stress2/misc/ptrace2.sh Sat Aug 16 07:01:42 2014 (r270037) @@ -43,7 +43,7 @@ cat > race1.c < #include -int +int main(void) { pid_t pid; @@ -92,7 +92,7 @@ cat > race2.c < #include -int +int main(void) { pid_t pid; Added: user/pho/stress2/misc/ptrace3.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/ptrace3.sh Sat Aug 16 07:01:42 2014 (r270037) @@ -0,0 +1,130 @@ +#!/bin/sh + +# +# Copyright (c) 2014 EMC Corp. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# A regression test for a bug introduced in r269656. +# Page fault in proc_realparent+0x70 seen. +# Fixed in r270024. + +# Test scenario by Mark Johnston markj@ + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > ptrace3.c +cc -o ptrace3 -Wall -Wextra -g ptrace3.c || exit 1 +rm -f ptrace3.c +cd $here + +/tmp/ptrace3 + +rm -f /tmp/ptrace3 +exit +EOF +#include +#include +#include + +#include +#include +#include + +/* + * A regression test for a bug introduced in r269656. The test process p creates + * child processes c1 and c2 which do nothing but sleep; a third child process + * (c3) uses ptrace(2) to reparent c1 and c2 from p to c3. Then c3 detaches from + * c1 and c2, causing a crash when c1 and c2 are removed from p's now-corrupt + * orphan list. + */ + +pid_t +sleeper() +{ + pid_t p; + + p = fork(); + if (p == -1) + err(1, "fork"); + else if (p == 0) + while (1) + sleep(1000000); + return (p); +} + +void +attach(pid_t p) +{ + int status; + + if (ptrace(PT_ATTACH, p, 0, 0) == -1) + err(1, "ptrace"); + + if (waitpid(p, &status, 0) == -1) + err(1, "waitpid"); + else if (!WIFSTOPPED(status)) + errx(1, "failed to stop child"); +} + +void +detach(pid_t p) +{ + + if (ptrace(PT_DETACH, p, 0, 0) == -1) + err(1, "ptrace"); +} + +int +main(void) +{ + int status; + pid_t c1, c2, p; + + c1 = sleeper(); + c2 = sleeper(); + + p = fork(); + if (p == -1) { + err(1, "fork"); + } else if (p == 0) { + attach(c1); + attach(c2); + detach(c1); + detach(c2); + } else { + if (waitpid(p, &status, 0) == -1) + err(1, "waitpid"); + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) + errx(1, "child exited abnormally"); + } + + /* Clean up. */ + (void)kill(c1, SIGKILL); + (void)kill(c2, SIGKILL); + + return (0); +}