fs/output/FileOutputStream: use open_cloexec()

Support operating systems that don't have O_CLOEXEC.
This commit is contained in:
Max Kellermann 2014-08-07 18:16:11 +02:00
parent 1ca8d7ad45
commit bbea6564fc

View File

@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "FileOutputStream.hxx" #include "FileOutputStream.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "system/fd_util.h"
#include "util/Error.hxx" #include "util/Error.hxx"
#ifdef WIN32 #ifdef WIN32
@ -81,9 +82,9 @@ FileOutputStream::Cancel()
FileOutputStream::FileOutputStream(Path _path, Error &error) FileOutputStream::FileOutputStream(Path _path, Error &error)
:path(_path), :path(_path),
fd(open(path.c_str(), fd(open_cloexec(path.c_str(),
O_WRONLY|O_CLOEXEC|O_CREAT|O_TRUNC|O_NOCTTY, O_WRONLY|O_CREAT|O_TRUNC,
0666)) 0666))
{ {
if (fd < 0) if (fd < 0)
error.FormatErrno("Failed to create %s", path.c_str()); error.FormatErrno("Failed to create %s", path.c_str());