1 /* Check that closing a pipe with a nonempty buffer works.
3 #output: got: a\nexit: 0\n
15 #include <sys/types.h>
26 char *buf
= malloc (pipemax
* 100);
34 /* The first write should go straight through. */
35 if (write (pip
[1], buf
, 1) != 1)
40 /* The second write should only successful for at most the PIPE_MAX
41 part, but no error. */
42 ret
= write (pip
[1], buf
, pipemax
* 10);
43 if (ret
!= 0 && ret
!= pipemax
- 1 && ret
!= pipemax
)
45 fprintf (stderr
, "ret: %d\n", ret
);
62 /* We need to turn this off because we don't want (to have to model) a
63 SIGPIPE resulting from the close. */
64 if (signal (SIGPIPE
, SIG_IGN
) != SIG_DFL
)
71 fprintf (stderr
, "Bad pipe %d\n", retcode
);
78 pipemax
= fpathconf (pip
[1], _PC_PIPE_BUF
);
83 fprintf (stderr
, "Bad pipemax %d\n", pipemax
);
87 pid
= clone (process
, (char *) stack
+ sizeof (stack
) - 64,
88 (CLONE_VM
| CLONE_FS
| CLONE_FILES
| CLONE_SIGHAND
)
92 fprintf (stderr
, "Bad clone %d\n", pid
);
96 while ((retcode
= read (pip
[0], buf
, 1)) == 0)
101 fprintf (stderr
, "Bad read 1: %d\n", retcode
);
105 printf ("got: %c\n", buf
[0]);
107 if (close (pip
[0]) != 0)
109 perror ("pip close");
113 retcode
= waitpid (pid
, &st
, __WALL
);
115 if (retcode
!= pid
|| !WIFEXITED (st
))
117 fprintf (stderr
, "Bad wait %d:%d %x\n", pid
, retcode
, st
);
122 printf ("exit: %d\n", WEXITSTATUS (st
));
This page took 0.032627 seconds and 4 git commands to generate.