svn commit: r359819 - user/pho/stress2/misc

Peter Holm pho at FreeBSD.org
Sun Apr 12 05:57:08 UTC 2020


Author: pho
Date: Sun Apr 12 05:57:07 2020
New Revision: 359819
URL: https://svnweb.freebsd.org/changeset/base/359819

Log:
  Added more sendfile() regression tests.

Added:
  user/pho/stress2/misc/sendfile18.sh   (contents, props changed)
  user/pho/stress2/misc/sendfile19.sh   (contents, props changed)
  user/pho/stress2/misc/sendfile20.sh   (contents, props changed)

Added: user/pho/stress2/misc/sendfile18.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/misc/sendfile18.sh	Sun Apr 12 05:57:07 2020	(r359819)
@@ -0,0 +1,126 @@
+#!/bin/sh
+
+#
+# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+#
+# Copyright (c) 2020 Mark Johnston <markj at FreeBSD.org>
+#
+# 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$
+#
+
+# "Fatal trap 9: general protection fault while in kernel mode" seen:
+# https://people.freebsd.org/~pho/stress/log/sendfile15-4.txt
+
+# Mark wrote:
+# It took me some time but I managed to get a repro.  Here is what I did:
+# - Create a malloc-backed md(4) device with a UFS filesystem.  Configure
+#   a gnop provider with -q 100 -d 10, i.e., always delay reads by 10ms.
+# - Write a small file (e.g., 4KB) to the filesystem.
+# - In a loop, unmount the filesystem, mount it, and run the test program.
+# The test program:
+# - creates a PF_LOCAL socket pair <s1, s2>,
+# - opens the input file,
+# - sends the file over s1,
+# - closes s1,
+# - sleeps for a second before exiting (and closing s2)
+# 
+# Using a separate filesystem ensures that the input file is not cached
+# when the test program runs, so sendfile will perform an async getpages
+# and place the "future" mbufs in s2's receive buffer.  The gnop delay
+# ensures that the I/O request will not be completed before s1 is closed,
+# and because s1 is closed uipc_ready() will free the promised mbufs and
+# return ECONNRESET.  Because of the sleep, s2's receive buffer will not
+# be scanned until after the uipc_ready() call.
+
+# Fixed by r359778
+
+[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1
+kldstat | grep -q geom_nop || { gnop load 2>/dev/null || exit 0 &&
+    notloaded=1; }
+gnop status || exit 1
+
+. ../default.cfg
+
+dir=/tmp
+odir=`pwd`
+cd $dir
+sed '1,/^EOF/d' < $odir/$0 > $dir/sendfile18.c
+mycc -o sendfile18 -Wall -Wextra -O0 -g sendfile18.c || exit 1
+rm -f sendfile18.c
+cd $odir
+
+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
+gnop create /dev/md$mdstart
+newfs $newfs_flags /dev/md$mdstart.nop > /dev/null
+mount /dev/md$mdstart.nop $mntpoint
+chmod 777 $mntpoint
+gnop configure -q 100 -d 10 /dev/md$mdstart.nop
+set +e
+
+dd if=/dev/zero of=$mntpoint/file bs=4k count=1 status=none
+
+start=`date +%s`
+while [ $((`date +%s` - start)) -lt 5 ]; do
+	umount $mntpoint
+	mount /dev/md$mdstart.nop $mntpoint
+	/tmp/sendfile18 $mntpoint/file
+done
+umount $mntpoint
+
+gnop destroy /dev/md$mdstart.nop
+mdconfig -d -u $mdstart
+[ $notloaded ] && gnop unload
+
+exit 0
+EOF
+#include <sys/socket.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+main(int argc __unused, char **argv)
+{
+        int fd, sd[2];
+
+        if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sd) != 0)
+                err(1, "socketpair");
+
+        fd = open(argv[1], O_RDONLY | O_DIRECT);
+        if (fd < 0)
+                err(1, "open");
+
+        if (sendfile(fd, sd[0], 0, 4096, NULL, NULL, 0) != 0)
+                err(1, "sendfile");
+        close(sd[0]);
+        sleep(1);
+
+        return (0);
+}

Added: user/pho/stress2/misc/sendfile19.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/misc/sendfile19.sh	Sun Apr 12 05:57:07 2020	(r359819)
@@ -0,0 +1,249 @@
+#!/bin/sh
+
+#
+# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+#
+# Copyright (c) 2020 Peter Holm <pho at FreeBSD.org>
+#
+# 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$
+#
+
+# "panic: Memory modified after free" seen:
+# https://people.freebsd.org/~pho/stress/log/sendfile19.txt
+# Broken by r358995-r359002
+# Fixed by r359778
+
+. ../default.cfg
+
+[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
+[ -z "$nfs_export" ] && exit 0
+ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 ||
+    exit 0
+
+odir=`pwd`
+cd /tmp
+sed '1,/^EOF/d' < $odir/$0 > sendfile19.c
+mycc -o sendfile19 -Wall sendfile19.c -pthread || exit 1
+rm -f sendfile19.c
+
+(cd $odir/../testcases/swap; ./swap -t 5m -i 20 -l 100) &
+sleep 5
+mount | grep "$mntpoint" | grep -q nfs && umount $mntpoint
+mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint
+
+cd $mntpoint
+parallel=1000
+for i in `jot $parallel`; do
+	size=`jot -r 1 1 $((2 * 1024 * 1024))`
+	dd if=/dev/zero of=input.$i bs=$size count=1 status=none
+done
+cd $odir
+while mount | grep "$mntpoint " | grep -q nfs; do
+	umount -f $mntpoint
+done
+sleep 1
+mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint
+spid=$!
+cd $mntpoint
+pids=
+for i in `jot $parallel`; do
+	/tmp/sendfile19 input.$i output.$i 1234$i &
+	pids="$pids $!"
+done
+for p in $pids; do
+	wait $p
+done
+for i in `jot $parallel`; do
+	rm -f input.$i output.$i
+done
+while pkill swap; do :; done
+wait $spid
+
+cd $odir
+umount $mntpoint
+while mount | grep "$mntpoint " | grep -q nfs; do
+	umount -f $mntpoint
+done
+rm -f /tmp/sendfile19
+exit 0
+EOF
+/* Slightly modified scenario from sendfile.sh */
+#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 <sys/param.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+int port;
+char *inputFile;
+char *outputFile;
+int bufsize = 4096;
+
+static void
+reader(void) {
+	int tcpsock, msgsock;
+	int on;
+	socklen_t len;
+	struct sockaddr_in inetaddr, inetpeer;
+	int n, t, *buf, fd;
+
+	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) {
+	int tcpsock, on;
+	struct sockaddr_in inetaddr;
+	struct hostent *hostent;
+	struct stat statb;
+	int i, r, fd;
+	off_t off = 0;
+#if 1
+	size_t size;
+#endif
+
+	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__);
+
+#if 1		/* livelock trigger */
+		size = getpagesize() -4;
+		if (setsockopt(tcpsock, SOL_SOCKET, SO_SNDBUF, (void *)&size,
+		    sizeof(size)) < 0)
+			err(1, "setsockopt(SO_SNDBUF), %s:%d",
+			    __FILE__, __LINE__);
+#endif
+
+		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, SF_NOCACHE) == -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);
+}

Added: user/pho/stress2/misc/sendfile20.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/pho/stress2/misc/sendfile20.sh	Sun Apr 12 05:57:07 2020	(r359819)
@@ -0,0 +1,250 @@
+#!/bin/sh
+
+#
+# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+#
+# Copyright (c) 2020 Peter Holm <pho at FreeBSD.org>
+#
+# 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$
+#
+
+# "panic: vm_page_assert_xbusied: page not exclusive busy" seen:
+# https://people.freebsd.org/~pho/stress/log/sendfile20.txt
+# Fixed by r359778
+
+. ../default.cfg
+
+[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
+[ -z "$nfs_export" ] && exit 0
+ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1 ||
+    exit 0
+
+odir=`pwd`
+cd /tmp
+sed '1,/^EOF/d' < $odir/$0 > sendfile20.c
+mycc -o sendfile20 -Wall sendfile20.c -pthread || exit 1
+rm -f sendfile20.c
+
+(cd $odir/../testcases/swap; ./swap -t 5m -i 20 -l 100) &
+sleep 5
+mount | grep "$mntpoint" | grep -q nfs && umount $mntpoint
+mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint
+
+cd $mntpoint
+parallel=2000
+for i in `jot $parallel`; do
+	size=`jot -r 1 1 $((1024 * 1024))`
+	dd if=/dev/zero of=input.$i bs=$size count=1 status=none
+done
+cd $odir
+while mount | grep "$mntpoint " | grep -q nfs; do
+	umount -f $mntpoint
+done
+sleep 1
+mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export $mntpoint
+spid=$!
+cd $mntpoint
+pids=
+for i in `jot $parallel`; do
+	/tmp/sendfile20 input.$i output.$i 1234$i &
+	pids="$pids $!"
+done
+sleep 30
+while pkill sendfile20; do :; done
+for p in $pids; do
+	wait $p
+done
+for i in `jot $parallel`; do
+#	cmp input.$i output.$i || { echo FAIL; ls -l input$i output$i; }
+	rm -f input.$i output.$i
+done
+while pkill swap; do :; done
+wait $spid
+
+cd $odir
+umount $mntpoint
+while mount | grep "$mntpoint " | grep -q nfs; do
+	umount -f $mntpoint
+done
+rm -f /tmp/sendfile20
+exit 0
+EOF
+#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 <sys/param.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+int port;
+char *inputFile;
+char *outputFile;
+int bufsize = 4096;
+
+static void
+reader(void) {
+	int tcpsock, msgsock;
+	int on;
+	socklen_t len;
+	struct sockaddr_in inetaddr, inetpeer;
+	int n, t, *buf, fd;
+
+	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) {
+	int tcpsock, on;
+	struct sockaddr_in inetaddr;
+	struct hostent *hostent;
+	struct stat statb;
+	int i, r, fd;
+	off_t off = 0;
+#if 1
+	size_t size;
+#endif
+
+	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__);
+
+#if 1		/* livelock trigger */
+		size = getpagesize() -4;
+		if (setsockopt(tcpsock, SOL_SOCKET, SO_SNDBUF, (void *)&size,
+		    sizeof(size)) < 0)
+			err(1, "setsockopt(SO_SNDBUF), %s:%d",
+			    __FILE__, __LINE__);
+#endif
+
+		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, SF_NOCACHE) == -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);
+}


More information about the svn-src-user mailing list