eden: no pipe2 on macos, manually CLOEXEC

Summary: as above

Reviewed By: simpkins

Differential Revision: D13475713

fbshipit-source-id: 94968251516c6b96e5caa9433d5d24a0b40ea025
This commit is contained in:
Wez Furlong 2018-12-15 19:08:58 -08:00 committed by Facebook Github Bot
parent 79b4ba6ac8
commit 9fca886c54

View File

@ -143,11 +143,27 @@ void DaemonStartupLogger::sendResult(ResultType result) {
setsid();
}
namespace {
void setCloExec(int fd) {
#ifndef FOLLY_HAVE_PIPE2
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
#else
(void)fd;
#endif
}
} // namespace
File DaemonStartupLogger::createPipe() {
// Create the pipe for communication between the processes
std::array<int, 2> pipeFDs;
#ifdef FOLLY_HAVE_PIPE2
auto rc = pipe2(pipeFDs.data(), O_CLOEXEC);
#else
auto rc = pipe(pipeFDs.data());
#endif
checkUnixError(rc, "failed to create communication pipes for daemonization");
setCloExec(pipeFDs[0]);
setCloExec(pipeFDs[1]);
pipe_ = folly::File(pipeFDs[1], /*ownsFd=*/true);
return folly::File(pipeFDs[0], /*ownsFd=*/true);