2 Copyright (C) 2004 Michael J. Silbersack. All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
7 1. Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 2. Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
13 THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #include <sys/types.h>
39 * The goal of this program is to see if fstat reports the correct
40 * data count for a pipe. Prior to revision 1.172 of sys_pipe.c,
41 * 0 would be returned once the pipe entered direct write mode.
43 * Linux (2.6) always returns zero, so it's not a valuable platform
50 char buffer[32768], buffer2[32768], go[] = "go", go2[] = "go2";
51 int desc[2], ipc_coord[2];
59 err(1, "Couldn't allocate data pipe");
61 error = pipe(ipc_coord);
63 err(1, "Couldn't allocate IPC coordination pipe");
66 assert(new_pid != -1);
68 close(new_pid == 0 ? desc[0] : desc[1]);
70 #define SYNC_R(i, _buf) do { \
72 warnx("%d: waiting for synchronization", __LINE__); \
73 if (read(ipc_coord[i], &_buf, sizeof(_buf)) != sizeof(_buf)) \
74 err(1, "failed to synchronize (%s)", (i == 0 ? "parent" : "child")); \
78 #define SYNC_W(i, _buf) do { \
80 warnx("%d: sending synchronization", __LINE__); \
81 if (write(ipc_coord[i], &_buf, sizeof(_buf)) != sizeof(_buf)) \
82 err(1, "failed to synchronize (%s)", (i == 0 ? "child" : "parent")); \
86 #define WRITE(s) do { \
88 if ((_size = write(desc[1], &buffer, s)) != s) \
89 warn("short write; wrote %zd, expected %d", _size, s); \
111 SYNC_W(0, go2); /* XXX: why is this required? */
121 while (successes < 5) {
124 fstat(desc[0], &status);
125 error = read(desc[0], &buffer2, sizeof(buffer2));
127 if (status.st_size != error)
128 err(1, "FAILURE: stat size %jd read size %zd",
129 (intmax_t)status.st_size, error);
131 printf("SUCCESS at stat size %jd read size %zd\n",
132 (intmax_t)status.st_size, error);