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:
parent
ba92935f64
commit
bcbb2e8649
15
src/util.cc
15
src/util.cc
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue