src: Use fcntl and FD_CLOEXEC if O_CLOEXEC is undefined

We may run into race condition if execve is called at the same time
when fcntl is called.  But we just does this for now to compile
nghttp2 applications under older kernel.
This commit is contained in:
Tatsuhiro Tsujikawa 2014-10-08 23:44:38 +09:00
parent ba92935f64
commit bcbb2e8649
1 changed files with 13 additions and 2 deletions

View File

@ -539,10 +539,21 @@ int reopen_log_file(const char *path)
fd = open(path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, fd = open(path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP); S_IRUSR | S_IWUSR | S_IRGRP);
} }
#else // !__ANDROID__ && !ANDROID #elif defined O_CLOEXEC
auto fd = open(path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, auto fd = open(path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP); S_IRUSR | S_IWUSR | S_IRGRP);
#endif // !__ANDROID__ && !ANDROID #else // !O_CLOEXEC
auto fd = open(path, O_WRONLY | O_APPEND | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP);
// We get race condition if execve is called at the same time.
if(fd != -1) {
fcntl(fd, F_SETFD, FD_CLOEXEC);
}
#endif // !O_CLOEXEC
if(fd == -1) { if(fd == -1) {
return -1; return -1;