From owner-svn-src-user@freebsd.org  Mon Oct  2 06:48:57 2017
Return-Path: <owner-svn-src-user@freebsd.org>
Delivered-To: svn-src-user@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id AE769E37ED0
 for <svn-src-user@mailman.ysv.freebsd.org>;
 Mon,  2 Oct 2017 06:48:57 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2610:1c1:1:6068::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 78AD9817F7;
 Mon,  2 Oct 2017 06:48:57 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.37])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v926musP085007;
 Mon, 2 Oct 2017 06:48:56 GMT (envelope-from pho@FreeBSD.org)
Received: (from pho@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id v926muvH085006;
 Mon, 2 Oct 2017 06:48:56 GMT (envelope-from pho@FreeBSD.org)
Message-Id: <201710020648.v926muvH085006@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org
 using -f
From: Peter Holm <pho@FreeBSD.org>
Date: Mon, 2 Oct 2017 06:48:56 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-user@freebsd.org
Subject: svn commit: r324188 - user/pho/stress2/misc
X-SVN-Group: user
X-SVN-Commit-Author: pho
X-SVN-Commit-Paths: user/pho/stress2/misc
X-SVN-Commit-Revision: 324188
X-SVN-Commit-Repository: base
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.23
Precedence: list
List-Id: "SVN commit messages for the experimental &quot; user&quot;
 src tree" <svn-src-user.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-user/>
List-Post: <mailto:svn-src-user@freebsd.org>
List-Help: <mailto:svn-src-user-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Mon, 02 Oct 2017 06:48:57 -0000

Author: pho
Date: Mon Oct  2 06:48:56 2017
New Revision: 324188
URL: https://svnweb.freebsd.org/changeset/base/324188

Log:
  Fix typo in the exit statement noted by jilles@
  Add note that not breaking out on fsck failure is on purpose.
  Remove reference to now unused $i.
  
  Reported by:	jilles@
  Sponsored by:	Dell EMC Isilon

Modified:
  user/pho/stress2/misc/trim4.sh

Modified: user/pho/stress2/misc/trim4.sh
==============================================================================
--- user/pho/stress2/misc/trim4.sh	Mon Oct  2 06:05:19 2017	(r324187)
+++ user/pho/stress2/misc/trim4.sh	Mon Oct  2 06:48:56 2017	(r324188)
@@ -41,9 +41,10 @@ mdconfig -l | grep -q md$mdstart &&  mdconfig -d -u $m
 size="1g"
 [ $# -eq 0 ] && trim=-t
 [ "$newfs_flags" = "-U" ] && flag="-j"
+s=0
 start=`date +%s`
 while [ $((`date +%s` - start)) -lt $((15 * 60)) ]; do
-	echo "Test #$i `date '+%T'`"
+	echo "Test `date '+%T'`"
 	echo "mdconfig -a -t swap -s $size -u $mdstart"
 	mdconfig -a -t swap -s $size -u $mdstart || exit 1
 	bsdlabel -w md$mdstart auto
@@ -62,7 +63,8 @@ while [ $((`date +%s` - start)) -lt $((15 * 60)) ]; do
 	while mount | grep $mntpoint | grep -q /dev/md; do
 		umount $mntpoint || sleep 1
 	done
-	checkfs /dev/md${mdstart}$part; s=$?
+#	Do not break in case of fsck error
+	checkfs /dev/md${mdstart}$part || s=$?
 	mdconfig -d -u $mdstart
 done
-exit $?
+exit $s

From owner-svn-src-user@freebsd.org  Mon Oct  2 09:11:49 2017
Return-Path: <owner-svn-src-user@freebsd.org>
Delivered-To: svn-src-user@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 35259E3A5B8
 for <svn-src-user@mailman.ysv.freebsd.org>;
 Mon,  2 Oct 2017 09:11:49 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2610:1c1:1:6068::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 0BBBB77A;
 Mon,  2 Oct 2017 09:11:48 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.37])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v929Bmnc045705;
 Mon, 2 Oct 2017 09:11:48 GMT (envelope-from pho@FreeBSD.org)
Received: (from pho@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id v929BmYW045704;
 Mon, 2 Oct 2017 09:11:48 GMT (envelope-from pho@FreeBSD.org)
Message-Id: <201710020911.v929BmYW045704@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org
 using -f
From: Peter Holm <pho@FreeBSD.org>
Date: Mon, 2 Oct 2017 09:11:48 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-user@freebsd.org
Subject: svn commit: r324192 - user/pho/stress2/misc
X-SVN-Group: user
X-SVN-Commit-Author: pho
X-SVN-Commit-Paths: user/pho/stress2/misc
X-SVN-Commit-Revision: 324192
X-SVN-Commit-Repository: base
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.23
Precedence: list
List-Id: "SVN commit messages for the experimental &quot; user&quot;
 src tree" <svn-src-user.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-user/>
List-Post: <mailto:svn-src-user@freebsd.org>
List-Help: <mailto:svn-src-user-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Mon, 02 Oct 2017 09:11:49 -0000

Author: pho
Date: Mon Oct  2 09:11:48 2017
New Revision: 324192
URL: https://svnweb.freebsd.org/changeset/base/324192

Log:
  Added a scenario for "sendfile(2) && block size > page size".
  
  Sponsored by:	Dell EMC Isilon

Added:
  user/pho/stress2/misc/sendfile11.sh   (contents, props changed)

Added: user/pho/stress2/misc/sendfile11.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/misc/sendfile11.sh	Mon Oct  2 09:11:48 2017	(r324192)
@@ -0,0 +1,229 @@
+#!/bin/sh
+
+#
+# Copyright (c) 2017 Dell EMC Isilon
+# 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$
+#
+
+[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
+
+# sendfile(2) && block size > page size:
+# panic: vnode_pager_generic_getpages: sector size 8192 too large
+
+. ../default.cfg
+
+odir=`pwd`
+cd /tmp
+sed '1,/^EOF/d' < $odir/$0 > sendfile11.c
+mycc -o sendfile11 -Wall sendfile11.c -pthread || exit 1
+rm -f sendfile11.c
+
+set -e
+mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint
+[ -c /dev/md$mdstart ] &&  mdconfig -d -u $mdstart
+mdconfig -a -t swap -s 2g -u $mdstart
+
+dd if=/dev/random of=/tmp/geli.key bs=64 count=1 > /dev/null 2>&1
+echo test | geli init -s 8192 -J - -K /tmp/geli.key /dev/md$mdstart > /dev/null
+echo test | geli attach -j - -k /tmp/geli.key /dev/md$mdstart
+newfs $newfs_flags /dev/md$mdstart.eli > /dev/null
+
+mount /dev/md${mdstart}.eli $mntpoint
+chmod 777 $mntpoint
+set +e
+
+cd $mntpoint
+dd if=/dev/zero of=file bs=1m count=512
+(cd $odir/../testcases/swap; ./swap -t 5m -i 20 -h -l 100) &
+sleep 5
+/tmp/sendfile11 file output 12345; s=$?
+cd $odir
+while pkill swap; do
+	sleep 1
+done
+wait
+
+while mount | grep $mntpoint | grep -q /dev/md; do
+	umount $mntpoint || sleep 1
+done
+checkfs /dev/md${mdstart}.eli || s=$?
+geli kill /dev/md$mdstart.eli
+mdconfig -d -u $mdstart
+rm -f /tmp/geli.key /tmp/sendfile11
+exit $s
+EOF
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define BUFSIZE 8192
+
+static int port;
+static char *inputFile;
+static char *outputFile;
+
+static void
+reader(void) {
+	struct sockaddr_in inetaddr, inetpeer;
+	socklen_t len;
+	int tcpsock, msgsock;
+	int *buf, fd, n, on, t;
+
+	on = 1;
+	if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+		err(1, "socket(), %s:%d", __FILE__, __LINE__);
+
+	if (setsockopt(tcpsock,
+	    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
+		err(1, "setsockopt(), %s:%d", __FILE__, __LINE__);
+
+	inetaddr.sin_family = AF_INET;
+	inetaddr.sin_addr.s_addr = INADDR_ANY;
+	inetaddr.sin_port = htons(port);
+	inetaddr.sin_len = sizeof(inetaddr);
+
+	if (bind(tcpsock,
+	    (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0)
+		err(1, "bind(), %s:%d", __FILE__, __LINE__);
+
+	if (listen(tcpsock, 5) < 0)
+		err(1, "listen(), %s:%d", __FILE__, __LINE__);
+
+	len = sizeof(inetpeer);
+	if ((msgsock = accept(tcpsock,
+	    (struct sockaddr *)&inetpeer, &len)) < 0)
+		err(1, "accept(), %s:%d", __FILE__, __LINE__);
+
+	t = 0;
+	if ((buf = malloc(BUFSIZE)) == NULL)
+			err(1, "malloc(%d), %s:%d", BUFSIZE, __FILE__, __LINE__);
+
+	if ((fd = open(outputFile, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1)
+			err(1, "open(%s)", outputFile);
+
+	for (;;) {
+		if ((n = read(msgsock, buf, BUFSIZE)) < 0)
+			err(1, "read(), %s:%d", __FILE__, __LINE__);
+		t += n;
+		if (n == 0) break;
+
+		if ((write(fd, buf, n)) != n)
+			err(1, "write");
+	}
+	close(msgsock);
+	close(fd);
+	return;
+}
+
+static void
+writer(void) {
+	struct sockaddr_in inetaddr;
+	struct hostent *hostent;
+	struct stat statb;
+	off_t off = 0;
+	size_t size;
+	int i, fd, on, r, tcpsock;
+
+	on = 1;
+	for (i = 1; i < 5; i++) {
+		if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+			err(1, "socket(), %s:%d", __FILE__, __LINE__);
+
+		if (setsockopt(tcpsock,
+		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
+			err(1, "setsockopt(), %s:%d", __FILE__, __LINE__);
+
+		size = getpagesize() -4;
+		if (setsockopt(tcpsock,
+		    SOL_SOCKET, SO_SNDBUF, (void *)&size, sizeof(size)) < 0)
+			err(1, "setsockopt(SO_SNDBUF), %s:%d", __FILE__, __LINE__);
+
+		hostent = gethostbyname ("localhost");
+		memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr,
+			sizeof (struct in_addr));
+
+		inetaddr.sin_family = AF_INET;
+		inetaddr.sin_addr.s_addr = INADDR_ANY;
+		inetaddr.sin_port = htons(port);
+		inetaddr.sin_len = sizeof(inetaddr);
+
+		r = connect(tcpsock, (struct sockaddr *) &inetaddr,
+			sizeof(inetaddr));
+		if (r == 0)
+			break;
+		sleep(1);
+		close(tcpsock);
+	}
+	if (r < 0)
+		err(1, "connect(), %s:%d", __FILE__, __LINE__);
+
+        if (stat(inputFile, &statb) != 0)
+                err(1, "stat(%s)", inputFile);
+
+	if ((fd = open(inputFile, O_RDONLY)) == -1)
+		err(1, "open(%s)", inputFile);
+
+	if (sendfile(fd, tcpsock, 0, statb.st_size, NULL, &off, 0) == -1)
+		err(1, "sendfile");
+
+	return;
+}
+
+int
+main(int argc, char **argv)
+{
+	pid_t pid;
+
+	if (argc != 4) {
+		fprintf(stderr, "Usage: %s <inputFile outputFile portNumber\n", argv[0]);
+			return (1);
+	}
+	inputFile = argv[1];
+	outputFile = argv[2];
+	port = atoi(argv[3]);
+
+	if ((pid = fork()) == 0) {
+		writer();
+		exit(EXIT_SUCCESS);
+
+	} else if (pid > 0) {
+		reader();
+		kill(pid, SIGINT);
+	} else
+		err(1, "fork(), %s:%d",  __FILE__, __LINE__);
+
+	return (0);
+}

From owner-svn-src-user@freebsd.org  Tue Oct  3 07:00:27 2017
Return-Path: <owner-svn-src-user@freebsd.org>
Delivered-To: svn-src-user@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4B38CE3307C
 for <svn-src-user@mailman.ysv.freebsd.org>;
 Tue,  3 Oct 2017 07:00:27 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2610:1c1:1:6068::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 2798B676D7;
 Tue,  3 Oct 2017 07:00:27 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.37])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v9370Q1h085779;
 Tue, 3 Oct 2017 07:00:26 GMT (envelope-from pho@FreeBSD.org)
Received: (from pho@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id v9370Q8D085778;
 Tue, 3 Oct 2017 07:00:26 GMT (envelope-from pho@FreeBSD.org)
Message-Id: <201710030700.v9370Q8D085778@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org
 using -f
From: Peter Holm <pho@FreeBSD.org>
Date: Tue, 3 Oct 2017 07:00:26 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-user@freebsd.org
Subject: svn commit: r324230 - user/pho/stress2/misc
X-SVN-Group: user
X-SVN-Commit-Author: pho
X-SVN-Commit-Paths: user/pho/stress2/misc
X-SVN-Commit-Revision: 324230
X-SVN-Commit-Repository: base
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.23
Precedence: list
List-Id: "SVN commit messages for the experimental &quot; user&quot;
 src tree" <svn-src-user.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-user/>
List-Post: <mailto:svn-src-user@freebsd.org>
List-Help: <mailto:svn-src-user-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Oct 2017 07:00:27 -0000

Author: pho
Date: Tue Oct  3 07:00:26 2017
New Revision: 324230
URL: https://svnweb.freebsd.org/changeset/base/324230

Log:
  Added a sendfile(2) test scenario.
  
  Sponsored by:	Dell EMC Isilon

Added:
  user/pho/stress2/misc/sendfile12.sh   (contents, props changed)

Added: user/pho/stress2/misc/sendfile12.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/misc/sendfile12.sh	Tue Oct  3 07:00:26 2017	(r324230)
@@ -0,0 +1,243 @@
+#!/bin/sh
+
+#
+# Copyright (c) 2017 Dell EMC Isilon
+# 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$
+#
+
+[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
+
+# Test scenario suggestion by alc@
+
+# sendfile(2) using SF_NOCACHE and a mmap'ed file with touched pages.
+# "panic: vm_page_free_toq: freeing mapped page 0xc49e53bc" seen:
+# https://people.freebsd.org/~pho/stress/log/sendfile12.txt
+
+. ../default.cfg
+
+odir=`pwd`
+cd /tmp
+sed '1,/^EOF/d' < $odir/$0 > sendfile12.c
+mycc -o sendfile12 -Wall sendfile12.c -pthread || exit 1
+rm -f sendfile12.c
+
+set -e
+mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint
+[ -c /dev/md$mdstart ] &&  mdconfig -d -u $mdstart
+mdconfig -a -t swap -s 1g -u $mdstart
+newfs $newfs_flags /dev/md$mdstart > /dev/null
+
+mount /dev/md${mdstart} $mntpoint
+chmod 777 $mntpoint
+set +e
+
+cd $mntpoint
+dd if=/dev/zero of=file bs=1m count=512
+(cd $odir/../testcases/swap; ./swap -t 5m -i 20 -h -l 100) &
+sleep 5
+/tmp/sendfile12 file output 12345; s=$?
+cd $odir
+while pkill swap; do
+	sleep 1
+done
+wait
+
+while mount | grep $mntpoint | grep -q /dev/md; do
+	umount $mntpoint || sleep 1
+done
+checkfs /dev/md${mdstart} || s=$?
+mdconfig -d -u $mdstart
+rm -f /tmp/sendfile12
+exit $s
+EOF
+#include <sys/param.h>
+#include <sys/mman.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define BUFSIZE 8192
+
+static int port;
+static char *inputFile;
+static char *outputFile;
+
+static void
+reader(void) {
+	struct sockaddr_in inetaddr, inetpeer;
+	socklen_t len;
+	int tcpsock, msgsock;
+	int *buf, fd, n, on, t;
+
+	on = 1;
+	if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+		err(1, "socket(), %s:%d", __FILE__, __LINE__);
+
+	if (setsockopt(tcpsock,
+	    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
+		err(1, "setsockopt(), %s:%d", __FILE__, __LINE__);
+
+	inetaddr.sin_family = AF_INET;
+	inetaddr.sin_addr.s_addr = INADDR_ANY;
+	inetaddr.sin_port = htons(port);
+	inetaddr.sin_len = sizeof(inetaddr);
+
+	if (bind(tcpsock,
+	    (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0)
+		err(1, "bind(), %s:%d", __FILE__, __LINE__);
+
+	if (listen(tcpsock, 5) < 0)
+		err(1, "listen(), %s:%d", __FILE__, __LINE__);
+
+	len = sizeof(inetpeer);
+	if ((msgsock = accept(tcpsock,
+	    (struct sockaddr *)&inetpeer, &len)) < 0)
+		err(1, "accept(), %s:%d", __FILE__, __LINE__);
+
+	t = 0;
+	if ((buf = malloc(BUFSIZE)) == NULL)
+		err(1, "malloc(%d), %s:%d", BUFSIZE, __FILE__, __LINE__);
+
+	if ((fd = open(outputFile, O_RDWR | O_CREAT | O_TRUNC, 0640)) ==
+	    -1)
+		err(1, "open(%s)", outputFile);
+
+	for (;;) {
+		if ((n = read(msgsock, buf, BUFSIZE)) < 0)
+			err(1, "read(), %s:%d", __FILE__, __LINE__);
+		t += n;
+		if (n == 0) break;
+
+		if ((write(fd, buf, n)) != n)
+			err(1, "write");
+	}
+	close(msgsock);
+	close(fd);
+	return;
+}
+
+static void
+writer(void) {
+	struct sockaddr_in inetaddr;
+	struct hostent *hostent;
+	struct stat statb;
+	off_t off = 0;
+	size_t size;
+	int i, fd, on, r, tcpsock;
+	char *cp;
+
+	on = 1;
+	for (i = 1; i < 5; i++) {
+		if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+			err(1, "socket(), %s:%d", __FILE__, __LINE__);
+
+		if (setsockopt(tcpsock,
+		    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
+			err(1, "setsockopt(), %s:%d", __FILE__, __LINE__);
+
+		size = getpagesize() -4;
+		if (setsockopt(tcpsock,
+		    SOL_SOCKET, SO_SNDBUF, (void *)&size, sizeof(size)) < 0)
+			err(1, "setsockopt(SO_SNDBUF), %s:%d", __FILE__,
+			    __LINE__);
+
+		hostent = gethostbyname ("localhost");
+		memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr,
+			sizeof (struct in_addr));
+
+		inetaddr.sin_family = AF_INET;
+		inetaddr.sin_addr.s_addr = INADDR_ANY;
+		inetaddr.sin_port = htons(port);
+		inetaddr.sin_len = sizeof(inetaddr);
+
+		r = connect(tcpsock, (struct sockaddr *) &inetaddr,
+			sizeof(inetaddr));
+		if (r == 0)
+			break;
+		sleep(1);
+		close(tcpsock);
+	}
+	if (r < 0)
+		err(1, "connect(), %s:%d", __FILE__, __LINE__);
+
+        if (stat(inputFile, &statb) != 0)
+                err(1, "stat(%s)", inputFile);
+
+	if ((fd = open(inputFile, O_RDWR)) == -1)
+		err(1, "open(%s)", inputFile);
+
+	if ((cp = mmap(NULL, statb.st_size, PROT_READ | PROT_WRITE,
+	    MAP_SHARED, fd, 0)) == MAP_FAILED)
+		err(1, "mmap");
+	cp[0] = 1;
+
+	if (sendfile(fd, tcpsock, 0, statb.st_size, NULL, &off, SF_NOCACHE)
+	    == -1)
+		err(1, "sendfile");
+
+	return;
+}
+
+int
+main(int argc, char **argv)
+{
+	pid_t pid;
+	int e, s;
+
+	if (argc != 4) {
+		fprintf(stderr,
+		    "Usage: %s <inputFile outputFile portNumber\n", argv[0]);
+			return (1);
+	}
+	e = 0;
+	inputFile = argv[1];
+	outputFile = argv[2];
+	port = atoi(argv[3]);
+
+	if ((pid = fork()) == 0) {
+		writer();
+		exit(EXIT_SUCCESS);
+
+	} else if (pid > 0) {
+		reader();
+		kill(pid, SIGINT);
+		waitpid(pid, &s, 0);
+		if (s != 0)
+			e = 1;
+	} else
+		err(1, "fork(), %s:%d",  __FILE__, __LINE__);
+
+	return (e);
+}

From owner-svn-src-user@freebsd.org  Tue Oct  3 07:01:26 2017
Return-Path: <owner-svn-src-user@freebsd.org>
Delivered-To: svn-src-user@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0A187E331C1
 for <svn-src-user@mailman.ysv.freebsd.org>;
 Tue,  3 Oct 2017 07:01:26 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2610:1c1:1:6068::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 CC5D967957;
 Tue,  3 Oct 2017 07:01:25 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.37])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v9371Omu086536;
 Tue, 3 Oct 2017 07:01:24 GMT (envelope-from pho@FreeBSD.org)
Received: (from pho@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id v9371OrC086535;
 Tue, 3 Oct 2017 07:01:24 GMT (envelope-from pho@FreeBSD.org)
Message-Id: <201710030701.v9371OrC086535@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org
 using -f
From: Peter Holm <pho@FreeBSD.org>
Date: Tue, 3 Oct 2017 07:01:24 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-user@freebsd.org
Subject: svn commit: r324231 - user/pho/stress2/misc
X-SVN-Group: user
X-SVN-Commit-Author: pho
X-SVN-Commit-Paths: user/pho/stress2/misc
X-SVN-Commit-Revision: 324231
X-SVN-Commit-Repository: base
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.23
Precedence: list
List-Id: "SVN commit messages for the experimental &quot; user&quot;
 src tree" <svn-src-user.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-user/>
List-Post: <mailto:svn-src-user@freebsd.org>
List-Help: <mailto:svn-src-user-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Oct 2017 07:01:26 -0000

Author: pho
Date: Tue Oct  3 07:01:24 2017
New Revision: 324231
URL: https://svnweb.freebsd.org/changeset/base/324231

Log:
  Return error status. Style fix.
  
  Sponsored by:	Dell EMC Isilon

Modified:
  user/pho/stress2/misc/sendfile11.sh

Modified: user/pho/stress2/misc/sendfile11.sh
==============================================================================
--- user/pho/stress2/misc/sendfile11.sh	Tue Oct  3 07:00:26 2017	(r324230)
+++ user/pho/stress2/misc/sendfile11.sh	Tue Oct  3 07:01:24 2017	(r324231)
@@ -129,10 +129,11 @@ reader(void) {
 
 	t = 0;
 	if ((buf = malloc(BUFSIZE)) == NULL)
-			err(1, "malloc(%d), %s:%d", BUFSIZE, __FILE__, __LINE__);
+		err(1, "malloc(%d), %s:%d", BUFSIZE, __FILE__, __LINE__);
 
-	if ((fd = open(outputFile, O_RDWR | O_CREAT | O_TRUNC, 0640)) == -1)
-			err(1, "open(%s)", outputFile);
+	if ((fd = open(outputFile, O_RDWR | O_CREAT | O_TRUNC, 0640)) ==
+	    -1)
+		err(1, "open(%s)", outputFile);
 
 	for (;;) {
 		if ((n = read(msgsock, buf, BUFSIZE)) < 0)
@@ -169,7 +170,8 @@ writer(void) {
 		size = getpagesize() -4;
 		if (setsockopt(tcpsock,
 		    SOL_SOCKET, SO_SNDBUF, (void *)&size, sizeof(size)) < 0)
-			err(1, "setsockopt(SO_SNDBUF), %s:%d", __FILE__, __LINE__);
+			err(1, "setsockopt(SO_SNDBUF), %s:%d", __FILE__,
+			    __LINE__);
 
 		hostent = gethostbyname ("localhost");
 		memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr,
@@ -206,11 +208,14 @@ int
 main(int argc, char **argv)
 {
 	pid_t pid;
+	int e, s;
 
 	if (argc != 4) {
-		fprintf(stderr, "Usage: %s <inputFile outputFile portNumber\n", argv[0]);
+		fprintf(stderr,
+		    "Usage: %s <inputFile outputFile portNumber\n", argv[0]);
 			return (1);
 	}
+	e = 0;
 	inputFile = argv[1];
 	outputFile = argv[2];
 	port = atoi(argv[3]);
@@ -222,8 +227,11 @@ main(int argc, char **argv)
 	} else if (pid > 0) {
 		reader();
 		kill(pid, SIGINT);
+		waitpid(pid, &s, 0);
+		if (s != 0)
+			e = 1;
 	} else
 		err(1, "fork(), %s:%d",  __FILE__, __LINE__);
 
-	return (0);
+	return (e);
 }

From owner-svn-src-user@freebsd.org  Tue Oct  3 07:03:12 2017
Return-Path: <owner-svn-src-user@freebsd.org>
Delivered-To: svn-src-user@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id EEC50E33217
 for <svn-src-user@mailman.ysv.freebsd.org>;
 Tue,  3 Oct 2017 07:03:12 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2610:1c1:1:6068::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 C835367B0D;
 Tue,  3 Oct 2017 07:03:12 +0000 (UTC) (envelope-from pho@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.37])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v9373BqJ089524;
 Tue, 3 Oct 2017 07:03:11 GMT (envelope-from pho@FreeBSD.org)
Received: (from pho@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id v9373BI0089521;
 Tue, 3 Oct 2017 07:03:11 GMT (envelope-from pho@FreeBSD.org)
Message-Id: <201710030703.v9373BI0089521@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org
 using -f
From: Peter Holm <pho@FreeBSD.org>
Date: Tue, 3 Oct 2017 07:03:11 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-user@freebsd.org
Subject: svn commit: r324232 - user/pho/stress2/misc
X-SVN-Group: user
X-SVN-Commit-Author: pho
X-SVN-Commit-Paths: user/pho/stress2/misc
X-SVN-Commit-Revision: 324232
X-SVN-Commit-Repository: base
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.23
Precedence: list
List-Id: "SVN commit messages for the experimental &quot; user&quot;
 src tree" <svn-src-user.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-user/>
List-Post: <mailto:svn-src-user@freebsd.org>
List-Help: <mailto:svn-src-user-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Oct 2017 07:03:13 -0000

Author: pho
Date: Tue Oct  3 07:03:11 2017
New Revision: 324232
URL: https://svnweb.freebsd.org/changeset/base/324232

Log:
  Return error code. Style fix.
  
  Sponsored by:	Dell EMC Isilon

Modified:
  user/pho/stress2/misc/holdcnt0.sh
  user/pho/stress2/misc/holdcnt02.sh
  user/pho/stress2/misc/holdcnt03.sh

Modified: user/pho/stress2/misc/holdcnt0.sh
==============================================================================
--- user/pho/stress2/misc/holdcnt0.sh	Tue Oct  3 07:01:24 2017	(r324231)
+++ user/pho/stress2/misc/holdcnt0.sh	Tue Oct  3 07:03:11 2017	(r324232)
@@ -57,18 +57,19 @@ newfs md${mdstart}$part > /dev/null
 mount /dev/md${mdstart}$part $mntpoint
 
 (cd $mntpoint; /tmp/holdcnt0) &
+pid=$!
 sleep 5
 while kill -0 $! 2> /dev/null; do
 	(cd ../testcases/swap; ./swap -t 1m -i 1) > /dev/null 2>&1
 done
-wait
+wait $pid; s=$?
 
 while mount | grep -q md${mdstart}$part; do
 	umount $mntpoint || sleep 1
 done
 mdconfig -d -u $mdstart
 rm -f /tmp/holdcnt0
-exit 0
+exit $s
 EOF
 /*
    A test that causes the page daemon to generate cached pages
@@ -77,6 +78,10 @@ EOF
 */
 
 #include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -84,9 +89,6 @@ EOF
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -96,17 +98,17 @@ EOF
 #define WPARALLEL 2
 
 static jmp_buf jbuf;
-off_t maxsize;
-int ps;
+static off_t maxsize;
+static int ps;
 static char *buf;
-volatile char val;
+static volatile char val;
 
 static void
 hand(int i __unused) {  /* handler */
         longjmp(jbuf, 1);
 }
 
-void
+static void
 cleanup(void)
 {
 	int i;
@@ -118,15 +120,16 @@ cleanup(void)
 	}
 }
 
-void
+static void
 init(void)
 {
-	char file[80];
 	int fd, i;
+	char file[80];
 
 	for (i = 0; i < FILES; i++) {
 		snprintf(file, sizeof(file), "f%06d", i);
-		if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1)
+		if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644)) ==
+		    -1)
 			err(1, "open(%s)", file);
 		if (write(fd, buf, BUFSIZE) != BUFSIZE)
 			err(1, "write");
@@ -135,13 +138,13 @@ init(void)
 
 }
 
-void
+static void
 writer(void)
 {
+	struct stat statbuf;
+	time_t start;
 	int fd, i;
 	char file[80];
-	time_t start;
-	struct stat statbuf;
 
 	setproctitle("writer");
 	start = time(NULL);
@@ -170,14 +173,14 @@ err:
 	_exit(0);
 }
 
-void
+static void
 reader(void)
 {
-	int fd, i, j, n;
+	struct stat statbuf;
 	void *p;
 	size_t len;
+	int fd, i, j, n;
 	char file[80];
-	struct stat statbuf;
 
 	setproctitle("reader");
 	signal(SIGSEGV, hand);
@@ -201,7 +204,8 @@ reader(void)
 				continue;
 			}
 			len = statbuf.st_size;
-			if ((p = mmap(p, len, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED)
+			if ((p = mmap(p, len, PROT_READ, MAP_SHARED, fd, 0))
+			    == MAP_FAILED)
 				err(1, "mmap()");
 			close(fd);
 			n = statbuf.st_size / ps;
@@ -220,28 +224,32 @@ reader(void)
 int
 main(void)
 {
-	int i;
+	pid_t rpid[RPARALLEL], wpid[WPARALLEL];
+	int e, i, s;
 
 	maxsize = 2LL * 1024 * 1024 * 1024 / FILES;
 	buf = malloc(BUFSIZE);
 	ps = getpagesize();
 
 	init();
+	e = 0;
 	for (i = 0; i < WPARALLEL; i++) {
-		if (fork() == 0)
+		if ((wpid[i] = fork()) == 0)
 			writer();
 	}
 	for (i = 0; i < RPARALLEL; i++) {
-		if (fork() == 0)
+		if ((rpid[i] = fork()) == 0)
 			reader();
 	}
 
 	for (i = 0; i < WPARALLEL; i++)
-		wait(NULL);
+		waitpid(wpid[i], &s, 0);
+	e += s == 0 ? 0 : 1;
 	for (i = 0; i < RPARALLEL; i++)
-		wait(NULL);
+		waitpid(rpid[i], &s, 0);
+	e += s == 0 ? 0 : 1;
 
 	free(buf);
 
-	return (0);
+	return (e);
 }

Modified: user/pho/stress2/misc/holdcnt02.sh
==============================================================================
--- user/pho/stress2/misc/holdcnt02.sh	Tue Oct  3 07:01:24 2017	(r324231)
+++ user/pho/stress2/misc/holdcnt02.sh	Tue Oct  3 07:03:11 2017	(r324232)
@@ -47,12 +47,13 @@ cd $here
 
 trap "rm -f /tmp/holdcnt02 `dirname $diskimage`/f000???" EXIT INT
 (cd `dirname $diskimage`; /tmp/holdcnt02) &
+pid=$!
 sleep 5
 while kill -0 $! 2> /dev/null; do
 	(cd ../testcases/swap; ./swap -t 1m -i 1) > /dev/null 2>&1
 done
-wait
-exit 0
+wait $pid
+exit
 EOF
 /*
    A test that causes the page daemon to generate cached pages
@@ -61,6 +62,10 @@ EOF
 */
 
 #include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -68,9 +73,6 @@ EOF
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -80,17 +82,17 @@ EOF
 #define WPARALLEL 2
 
 static jmp_buf jbuf;
-off_t maxsize;
-int ps;
+static off_t maxsize;
+static int ps;
 static char *buf;
-volatile char val;
+static volatile char val;
 
 static void
 hand(int i __unused) {  /* handler */
         longjmp(jbuf, 1);
 }
 
-void
+static void
 cleanup(void)
 {
 	int i;
@@ -102,15 +104,16 @@ cleanup(void)
 	}
 }
 
-void
+static void
 init(void)
 {
-	char file[80];
 	int fd, i;
+	char file[80];
 
 	for (i = 0; i < FILES; i++) {
 		snprintf(file, sizeof(file), "f%06d", i);
-		if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1)
+		if ((fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644)) ==
+		    -1)
 			err(1, "open(%s)", file);
 		if (write(fd, buf, BUFSIZE) != BUFSIZE)
 			err(1, "write");
@@ -119,7 +122,7 @@ init(void)
 
 }
 
-void
+static void
 writer(void)
 {
 	int fd, i;
@@ -154,7 +157,7 @@ err:
 	_exit(0);
 }
 
-void
+static void
 reader(void)
 {
 	int fd, i, j, n;
@@ -185,7 +188,8 @@ reader(void)
 				continue;
 			}
 			len = statbuf.st_size;
-			if ((p = mmap(p, len, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED)
+			if ((p = mmap(p, len, PROT_READ, MAP_SHARED, fd, 0))
+			    == MAP_FAILED)
 				err(1, "mmap()");
 			close(fd);
 			n = statbuf.st_size / ps;
@@ -204,28 +208,32 @@ reader(void)
 int
 main(void)
 {
-	int i;
+	pid_t rpid[RPARALLEL], wpid[WPARALLEL];
+	int e, i, s;
 
 	maxsize = 2LL * 1024 * 1024 * 1024 / FILES;
 	buf = malloc(BUFSIZE);
 	ps = getpagesize();
 
 	init();
+	e = 0;
 	for (i = 0; i < WPARALLEL; i++) {
-		if (fork() == 0)
+		if ((wpid[i] = fork()) == 0)
 			writer();
 	}
 	for (i = 0; i < RPARALLEL; i++) {
-		if (fork() == 0)
+		if ((rpid[i] = fork()) == 0)
 			reader();
 	}
 
 	for (i = 0; i < WPARALLEL; i++)
-		wait(NULL);
+		waitpid(wpid[i], &s, 0);
+	e += s == 0 ? 0 : 1;
 	for (i = 0; i < RPARALLEL; i++)
-		wait(NULL);
+		waitpid(rpid[i], &s, 0);
+	e += s == 0 ? 0 : 1;
 
 	free(buf);
 
-	return (0);
+	return (e);
 }

Modified: user/pho/stress2/misc/holdcnt03.sh
==============================================================================
--- user/pho/stress2/misc/holdcnt03.sh	Tue Oct  3 07:01:24 2017	(r324231)
+++ user/pho/stress2/misc/holdcnt03.sh	Tue Oct  3 07:03:11 2017	(r324232)
@@ -37,7 +37,7 @@
 
 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
 [ `swapinfo | wc -l` -eq 1 ] && exit 0
-[ `sysctl -n hw.physmem` -lt $((9 * 1024 * 1024 * 1024)) ] && exit 0
+[ `sysctl -n hw.physmem` -lt $((32 * 1024 * 1024 * 1024)) ] && exit 0
 
 . ../default.cfg
 
@@ -50,12 +50,13 @@ cd $here
 
 trap "rm -f /tmp/holdcnt03 `dirname $diskimage`/f000???" EXIT INT
 (cd `dirname $diskimage`; /tmp/holdcnt03) &
+pid=$!
 sleep 5
 while kill -0 $! 2> /dev/null; do
 	(cd ../testcases/swap; ./swap -t 1m -i 1) > /dev/null 2>&1
 done
-wait
-exit 0
+wait $pid
+exit
 EOF
 /*
    A test that causes the page daemon to generate cached pages
@@ -64,6 +65,10 @@ EOF
 */
 
 #include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -71,9 +76,6 @@ EOF
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -83,8 +85,8 @@ EOF
 #define WPARALLEL 2
 
 static jmp_buf jbuf;
-off_t maxsize;
-int ps;
+static off_t maxsize;
+static int ps;
 static char *buf;
 
 static void
@@ -92,7 +94,7 @@ hand(int i __unused) {  /* handler */
         longjmp(jbuf, 1);
 }
 
-void
+static void
 cleanup(void)
 {
 	int i;
@@ -104,7 +106,7 @@ cleanup(void)
 	}
 }
 
-void
+static void
 init(void)
 {
 	char file[80];
@@ -121,7 +123,7 @@ init(void)
 
 }
 
-void
+static void
 writer(void)
 {
 	int fd, i;
@@ -156,7 +158,7 @@ err:
 	_exit(0);
 }
 
-void
+static void
 touch(void)
 {
 	int fd, i, j, n;
@@ -201,31 +203,36 @@ touch(void)
 	}
 	_exit(0);
 }
+
 int
 main(void)
 {
-	int i;
+	pid_t rpid[RPARALLEL], wpid[WPARALLEL];
+	int e, i, s;
 
 	maxsize = 2LL * 1024 * 1024 * 1024 / FILES;
 	buf = malloc(BUFSIZE);
 	ps = getpagesize();
 
 	init();
+	e = 0;
 	for (i = 0; i < WPARALLEL; i++) {
-		if (fork() == 0)
+		if ((wpid[i] = fork()) == 0)
 			writer();
 	}
 	for (i = 0; i < RPARALLEL; i++) {
-		if (fork() == 0)
+		if ((rpid[i] = fork()) == 0)
 			touch();
 	}
 
 	for (i = 0; i < WPARALLEL; i++)
-		wait(NULL);
+		waitpid(wpid[i], &s, 0);
+	e += s == 0 ? 0 : 1;
 	for (i = 0; i < RPARALLEL; i++)
-		wait(NULL);
+		waitpid(rpid[i], &s, 0);
+	e += s == 0 ? 0 : 1;
 
 	free(buf);
 
-	return (0);
+	return (e);
 }