still serv_close bug...
[mit-jos.git] / user / testfdsharing.c
blob330544cb4748ef7daa4078820c1365ee439d7db8
1 #include <inc/lib.h>
3 char buf[512], buf2[512];
5 void
6 umain(void)
8 int fd, r, n, n2;
10 if ((fd = open("motd", O_RDONLY)) < 0)
11 panic("open motd: %e", fd);
12 seek(fd, 0);
13 if ((n = readn(fd, buf, sizeof buf)) <= 0)
14 panic("readn: %e", n);
16 if ((r = fork()) < 0)
17 panic("fork: %e", r);
18 if (r == 0) {
19 seek(fd, 0);
20 cprintf("going to read in child (might page fault if your sharing is buggy)\n");
21 if ((n2 = readn(fd, buf2, sizeof buf2)) != n2)
22 panic("read in parent got %d, read in child got %d", n, n2);
23 if (memcmp(buf, buf2, n) != 0)
24 panic("read in parent got different bytes from read in child");
25 cprintf("read in child succeeded\n");
26 seek(fd, 0);
27 close(fd);
28 exit();
30 wait(r);
31 if ((n2 = readn(fd, buf2, sizeof buf2)) != n)
32 panic("read in parent got %d, then got %d", n, n2);
33 cprintf("read in parent succeeded\n");