1 /* FIXME: Do something tricky to ensure we really do loop in read_all. */
3 #include <ccan/read_write_all/read_write_all.h>
4 #include <ccan/read_write_all/read_write_all.c>
5 #include <ccan/tap/tap.h>
15 static volatile int sigcount;
16 static int p2c[2], c2p[2];
17 static void got_signal(int sig)
21 if (write(p2c[1], &c, 1) == 1)
25 /* < PIPE_BUF *will* be atomic. But > PIPE_BUF only *might* be non-atomic. */
26 #define BUFSZ (1024*1024)
35 buffer = calloc(BUFSZ, 2);
38 /* We fork and torture parent. */
39 if (pipe(p2c) != 0 || pipe(c2p) != 0)
46 /* Child. Make sure parent ready, then write in two parts. */
47 if (read(p2c[0], &c, 1) != 1)
49 memset(buffer, 0xff, BUFSZ*2);
50 if (!write_all(c2p[1], buffer, BUFSZ))
52 if (kill(getppid(), SIGUSR1) != 0)
54 /* Make sure they get signal. */
55 if (read(p2c[0], &c, 1) != 1)
57 if (write(c2p[1], buffer, BUFSZ) != BUFSZ)
66 signal(SIGUSR1, got_signal);
67 ok1(write(p2c[1], &c, 1) == 1);
68 ok1(read_all(c2p[0], buffer, BUFSZ*2));
69 ok1(memchr(buffer, 0, BUFSZ*2) == NULL);
71 ok1(wait(&status) == child);
72 ok(WIFEXITED(status) && WEXITSTATUS(status) == 0,
73 "WIFEXITED(status) = %u, WEXITSTATUS(status) = %u",
74 WIFEXITED(status), WEXITSTATUS(status));