Open a pipe, do closefrom, check pipe no longer works. */
| 9 | |
| 10 | /* Open a pipe, do closefrom, check pipe no longer works. */ |
| 11 | static |
| 12 | int pipe_close(void) |
| 13 | { |
| 14 | int fds[2]; |
| 15 | ssize_t wres; |
| 16 | |
| 17 | char buf = '\0'; |
| 18 | |
| 19 | if (pipe(fds) < 0) |
| 20 | return 0; |
| 21 | |
| 22 | /* Writing to the write end should succeed, the |
| 23 | * pipe is working. */ |
| 24 | do { |
| 25 | wres = write(fds[1], &buf, 1); |
| 26 | } while ((wres < 0) && (errno == EINTR)); |
| 27 | if (wres < 0) |
| 28 | return 0; |
| 29 | |
| 30 | closefrom(STDERR_FILENO + 1); |
| 31 | |
| 32 | /* Writing to the write end should fail because |
| 33 | * everything should be closed. */ |
| 34 | do { |
| 35 | wres = write(fds[1], &buf, 1); |
| 36 | } while ((wres < 0) && (errno == EINTR)); |
| 37 | |
| 38 | return (wres < 0) && (errno == EBADF); |
| 39 | } |
| 40 | |
| 41 | /* Open a pipe, fork, do closefrom in child, read pipe from parent, |
| 42 | * parent should see EOF. |