MCPcopy Create free account
hub / github.com/ElementsProject/lightning / pipe_close

Function pipe_close

ccan/ccan/closefrom/test/run.c:11–39  ·  view source on GitHub ↗

Open a pipe, do closefrom, check pipe no longer works. */

Source from the content-addressed store, hash-verified

9
10/* Open a pipe, do closefrom, check pipe no longer works. */
11static
12int 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.

Callers 1

mainFunction · 0.85

Calls 1

closefromFunction · 0.85

Tested by

no test coverage detected