diff options
Diffstat (limited to 'payload_consumer/file_descriptor.cc')
-rw-r--r-- | payload_consumer/file_descriptor.cc | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/payload_consumer/file_descriptor.cc b/payload_consumer/file_descriptor.cc index 1de615cb..da76327c 100644 --- a/payload_consumer/file_descriptor.cc +++ b/payload_consumer/file_descriptor.cc @@ -21,6 +21,7 @@ #include <sys/ioctl.h> #include <sys/stat.h> #include <sys/types.h> +#include <unistd.h> #include <base/posix/eintr_wrapper.h> @@ -28,6 +29,12 @@ namespace chromeos_update_engine { +EintrSafeFileDescriptor::~EintrSafeFileDescriptor() { + if (IsOpen()) { + Close(); + } +} + bool EintrSafeFileDescriptor::Open(const char* path, int flags, mode_t mode) { CHECK_EQ(fd_, -1); return ((fd_ = HANDLE_EINTR(open(path, flags, mode))) >= 0); @@ -125,11 +132,19 @@ bool EintrSafeFileDescriptor::BlkIoctl(int request, bool EintrSafeFileDescriptor::Flush() { CHECK_GE(fd_, 0); + // Implemented as a No-Op, as delta_performer typically uses |O_DSYNC|, except + // in interactive settings. + fsync(fd_); return true; } bool EintrSafeFileDescriptor::Close() { - CHECK_GE(fd_, 0); + if (fd_ < 0) { + return false; + } + // https://stackoverflow.com/questions/705454/does-linux-guarantee-the-contents-of-a-file-is-flushed-to-disc-after-close + // |close()| doesn't imply |fsync()|, we need to do it manually. + fsync(fd_); if (IGNORE_EINTR(close(fd_))) return false; fd_ = -1; |