Loading init/persistent_properties.cpp +14 −1 Original line number Diff line number Diff line Loading @@ -31,10 +31,11 @@ #include "util.h" using android::base::Dirname; using android::base::ReadFdToString; using android::base::StartsWith; using android::base::WriteStringToFd; using android::base::unique_fd; using android::base::WriteStringToFd; namespace android { namespace init { Loading Loading @@ -191,6 +192,18 @@ Result<void> WritePersistentPropertyFile(const PersistentProperties& persistent_ unlink(temp_filename.c_str()); return Error(saved_errno) << "Unable to rename persistent property file"; } // rename() is atomic with regards to the kernel's filesystem buffers, but the parent // directories must be fsync()'ed otherwise, the rename is not necessarily written to storage. // Note in this case, that the source and destination directories are the same, so only one // fsync() is required. auto dir = Dirname(persistent_property_filename); auto dir_fd = unique_fd{open(dir.c_str(), O_DIRECTORY | O_RDONLY)}; if (dir_fd < 0) { return ErrnoError() << "Unable to open persistent properties directory for fsync()"; } fsync(dir_fd); return {}; } Loading Loading
init/persistent_properties.cpp +14 −1 Original line number Diff line number Diff line Loading @@ -31,10 +31,11 @@ #include "util.h" using android::base::Dirname; using android::base::ReadFdToString; using android::base::StartsWith; using android::base::WriteStringToFd; using android::base::unique_fd; using android::base::WriteStringToFd; namespace android { namespace init { Loading Loading @@ -191,6 +192,18 @@ Result<void> WritePersistentPropertyFile(const PersistentProperties& persistent_ unlink(temp_filename.c_str()); return Error(saved_errno) << "Unable to rename persistent property file"; } // rename() is atomic with regards to the kernel's filesystem buffers, but the parent // directories must be fsync()'ed otherwise, the rename is not necessarily written to storage. // Note in this case, that the source and destination directories are the same, so only one // fsync() is required. auto dir = Dirname(persistent_property_filename); auto dir_fd = unique_fd{open(dir.c_str(), O_DIRECTORY | O_RDONLY)}; if (dir_fd < 0) { return ErrnoError() << "Unable to open persistent properties directory for fsync()"; } fsync(dir_fd); return {}; } Loading