4 # Copyright (c) 2017 Dell EMC Isilon
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 # mkfifo(2), poll(2) with tmpfs(5) scenario.
32 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
37 sed '1,/^EOF/d' < $odir/$0 > $dir/mkfifo7.c
38 mycc -o mkfifo7 -Wall -Wextra -O0 -g mkfifo7.c || exit 1
42 mount | grep -q "on $mntpoint " && umount -f $mntpoint
43 mount -o size=1g -t tmpfs tmpfs $mntpoint
45 fifo=$mntpoint/fifo.file
51 while mount | grep "on $mntpoint " | grep -q tmpfs; do
52 umount $mntpoint || sleep 1
58 #include <sys/param.h>
85 if((fd = open(path, O_RDONLY)) == -1)
87 err(1, "open(%s, O_RDONLY)",
90 warn("open(%s) ro", path);
93 /* Read one character */
96 if ((n = poll(&pfd, 1, 0)) == -1)
103 fprintf(stderr, "read(1): %c\n", ch);
105 fprintf(stderr, "read(1): EOF\n");
110 if ((n = poll(&pfd, 1, 7000)) == -1)
113 fprintf(stderr, "FAIL Expected n == 1, got %d\n", n);
115 r = read(fd, &ch, 1);
119 fprintf(stderr, "read(2): EOF\n");
124 if ((n = poll(&pfd, 1, 7000)) == -1)
127 fprintf(stderr, "FAIL Expected n == 1, got %d\n", n);
129 r = read(fd, &ch, 1);
133 fprintf(stderr, "read(3): %c\n", ch);
137 err(1, "close() in child");
138 _exit(n == 1 ? 0 : 1);
147 if ((fd = open(path, O_WRONLY)) == -1)
149 err(1, "open(%s, O_WRONLY)",
152 warn("open(%s) wr", path);
154 if (write(fd, "a", 1) != 1)
157 warn("close() in parent");
166 if ((pid = fork()) == 0)
170 if (waitpid(pid, &status, 0) != pid)
171 err(1, "waitpid(%d)", pid);
177 main(int argc __unused, char *argv[])
179 int e, i, pids[PARALLEL], status;
182 fprintf(stderr, "Usage: %s <fifo file>\n", argv[0]);
189 if (mkfifo(path, 0640) == -1)
190 err(1, "mkfifo(%s)", path);
192 for (i = 0; i < PARALLEL; i++) {
193 if ((pids[i] = fork()) == 0)
196 for (i = 0; i < PARALLEL; i++) {
197 if (waitpid(pids[i], &status, 0) == -1)
198 err(1, "waitpid(%d)", pids[i]);
199 e += status == 0 ? 0 : 1;