Commit bcbb2e86 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

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.
parent ba92935f
......@@ -539,10 +539,21 @@ int reopen_log_file(const char *path)
fd = open(path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC,
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,
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) {
return -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment