This function will invoke `os::cloexec` on all specified file descriptors that are valid (i.e., not `None` and >= 0).
| 184 | // This function will invoke `os::cloexec` on all specified file |
| 185 | // descriptors that are valid (i.e., not `None` and >= 0). |
| 186 | inline Try<Nothing> cloexec( |
| 187 | const InputFileDescriptors& stdinfds, |
| 188 | const OutputFileDescriptors& stdoutfds, |
| 189 | const OutputFileDescriptors& stderrfds) |
| 190 | { |
| 191 | hashset<int> fds = { |
| 192 | stdinfds.read, |
| 193 | stdinfds.write.getOrElse(-1), |
| 194 | stdoutfds.read.getOrElse(-1), |
| 195 | stdoutfds.write, |
| 196 | stderrfds.read.getOrElse(-1), |
| 197 | stderrfds.write |
| 198 | }; |
| 199 | |
| 200 | foreach (int fd, fds) { |
| 201 | if (fd >= 0) { |
| 202 | Try<Nothing> cloexec = os::cloexec(fd); |
| 203 | if (cloexec.isError()) { |
| 204 | return Error(cloexec.error()); |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | return Nothing(); |
| 210 | } |
| 211 | |
| 212 | |
| 213 | // The main entry of the child process. |