| 111 | } |
| 112 | |
| 113 | int pipe_cloexec(int pipefd[2], int flags) |
| 114 | { |
| 115 | #if defined(HAVE_PIPE2) |
| 116 | return pipe2(pipefd, O_CLOEXEC | flags); |
| 117 | #else |
| 118 | if (pipe(pipefd) == -1) |
| 119 | return -1; |
| 120 | |
| 121 | # ifdef _WIN32 |
| 122 | return 0; |
| 123 | # else |
| 124 | /* |
| 125 | * The old-fashioned, race-condition prone way that we have to fall |
| 126 | * back on if pipe2 does not exist. |
| 127 | */ |
| 128 | if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) < 0) { |
| 129 | goto fail; |
| 130 | } |
| 131 | |
| 132 | if (fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) < 0) { |
| 133 | goto fail; |
| 134 | } |
| 135 | |
| 136 | return 0; |
| 137 | |
| 138 | fail: |
| 139 | int save_errno = errno; |
| 140 | VOID_TEMP_FAILURE_RETRY(close(pipefd[0])); |
| 141 | VOID_TEMP_FAILURE_RETRY(close(pipefd[1])); |
| 142 | return (errno = save_errno, -1); |
| 143 | # endif |
| 144 | #endif |
| 145 | } |
| 146 | |
| 147 | |
| 148 | int socket_cloexec(int domain, int type, int protocol) |
no test coverage detected