Enable the FD_CLOEXEC on the given fd to avoid fd leaks. * This function should be invoked for fd's on specific places * where fork + execve system calls are called. */
| 108 | * This function should be invoked for fd's on specific places |
| 109 | * where fork + execve system calls are called. */ |
| 110 | int anetCloexec(int fd) { |
| 111 | int r; |
| 112 | int flags; |
| 113 | |
| 114 | do { |
| 115 | r = fcntl(fd, F_GETFD); |
| 116 | } while (r == -1 && errno == EINTR); |
| 117 | |
| 118 | if (r == -1 || (r & FD_CLOEXEC)) |
| 119 | return r; |
| 120 | |
| 121 | flags = r | FD_CLOEXEC; |
| 122 | |
| 123 | do { |
| 124 | r = fcntl(fd, F_SETFD, flags); |
| 125 | } while (r == -1 && errno == EINTR); |
| 126 | |
| 127 | return r; |
| 128 | } |
| 129 | |
| 130 | /* Set TCP keep alive option to detect dead peers. The interval option |
| 131 | * is only used for Linux as we are using Linux-specific APIs to set |
no test coverage detected