diff options
-rw-r--r-- | src/LogInit.cxx | 2 | ||||
-rw-r--r-- | src/fs/FileSystem.cxx | 1 | ||||
-rw-r--r-- | src/fs/FileSystem.hxx | 13 | ||||
-rw-r--r-- | src/output/plugins/FifoOutputPlugin.cxx | 4 | ||||
-rw-r--r-- | src/unix/PidFile.hxx | 9 |
5 files changed, 13 insertions, 16 deletions
diff --git a/src/LogInit.cxx b/src/LogInit.cxx index 16786609a..43dddb847 100644 --- a/src/LogInit.cxx +++ b/src/LogInit.cxx @@ -62,7 +62,7 @@ open_log_file(void) { assert(!out_path.IsNull()); - return OpenFile(out_path, O_CREAT | O_WRONLY | O_APPEND, 0666); + return OpenFile(out_path, O_CREAT | O_WRONLY | O_APPEND, 0666).Steal(); } static void diff --git a/src/fs/FileSystem.cxx b/src/fs/FileSystem.cxx index 874ac9a14..6da574a8e 100644 --- a/src/fs/FileSystem.cxx +++ b/src/fs/FileSystem.cxx @@ -22,6 +22,7 @@ #include "AllocatedPath.hxx" #include "Limits.hxx" #include "system/Error.hxx" +#include "system/fd_util.h" #include <errno.h> #include <fcntl.h> diff --git a/src/fs/FileSystem.hxx b/src/fs/FileSystem.hxx index 2c5a2cdf5..913c3592b 100644 --- a/src/fs/FileSystem.hxx +++ b/src/fs/FileSystem.hxx @@ -22,9 +22,8 @@ #include "check.h" #include "Traits.hxx" -#include "system/fd_util.h" - #include "Path.hxx" +#include "system/UniqueFileDescriptor.hxx" #ifdef WIN32 #include <fileapi.h> @@ -53,14 +52,12 @@ FOpen(Path file, PathTraitsFS::const_pointer_type mode) /** * Wrapper for open_cloexec() that uses #Path names. */ -static inline int +static inline UniqueFileDescriptor OpenFile(Path file, int flags, int mode) { -#ifdef WIN32 - return _topen(file.c_str(), flags, mode); -#else - return open_cloexec(file.c_str(), flags, mode); -#endif + UniqueFileDescriptor fd; + fd.Open(file.c_str(), flags, mode); + return fd; } /* diff --git a/src/output/plugins/FifoOutputPlugin.cxx b/src/output/plugins/FifoOutputPlugin.cxx index da7b6de67..6c0e1b739 100644 --- a/src/output/plugins/FifoOutputPlugin.cxx +++ b/src/output/plugins/FifoOutputPlugin.cxx @@ -153,12 +153,12 @@ FifoOutput::OpenFifo() try { Check(); - input = OpenFile(path, O_RDONLY|O_NONBLOCK|O_BINARY, 0); + input = OpenFile(path, O_RDONLY|O_NONBLOCK|O_BINARY, 0).Steal(); if (input < 0) throw FormatErrno("Could not open FIFO \"%s\" for reading", path_utf8.c_str()); - output = OpenFile(path, O_WRONLY|O_NONBLOCK|O_BINARY, 0); + output = OpenFile(path, O_WRONLY|O_NONBLOCK|O_BINARY, 0).Steal(); if (output < 0) throw FormatErrno("Could not open FIFO \"%s\" for writing", path_utf8.c_str()); diff --git a/src/unix/PidFile.hxx b/src/unix/PidFile.hxx index 0cb476755..80e073c22 100644 --- a/src/unix/PidFile.hxx +++ b/src/unix/PidFile.hxx @@ -38,7 +38,7 @@ public: if (path.IsNull()) return; - fd = OpenFile(path, O_WRONLY|O_CREAT|O_TRUNC, 0666); + fd = OpenFile(path, O_WRONLY|O_CREAT|O_TRUNC, 0666).Steal(); if (fd < 0) { const std::string utf8 = path.ToUTF8(); FormatFatalSystemError("Failed to create pid file \"%s\"", @@ -90,14 +90,14 @@ gcc_pure static inline pid_t ReadPidFile(Path path) noexcept { - int fd = OpenFile(path, O_RDONLY, 0); - if (fd < 0) + auto fd = OpenFile(path, O_RDONLY, 0); + if (!fd.IsDefined()) return -1; pid_t pid = -1; char buffer[32]; - auto nbytes = read(fd, buffer, sizeof(buffer) - 1); + auto nbytes = fd.Read(buffer, sizeof(buffer) - 1); if (nbytes > 0) { buffer[nbytes] = 0; @@ -107,7 +107,6 @@ ReadPidFile(Path path) noexcept pid = value; } - close(fd); return pid; } |