Reduce frequency of sync() in update_engine logging

update_engine opens an fd to /data/misc/update_engine_logs for writing
logs. This FD is opened with O_SYNC flag to guarantee that logs appear
on disk on a timely fashion. But internally, every LOG() statement would
turn into 3 filesystem write() calls, resulting in 3 fsync() triggered.
Remove the O_SYNC flag and manually invoke fsync() after all 3 writes
are finished to reduce number of fsync() calls by 2/3 .

Test: th
Bug: 315215541
Change-Id: I598c7946d538d6d9b2a45ba132d2ea0283201b71
diff --git a/aosp/logging_android.cc b/aosp/logging_android.cc
index 5940f78..1a0fa9a 100644
--- a/aosp/logging_android.cc
+++ b/aosp/logging_android.cc
@@ -124,7 +124,7 @@
   explicit FileLogger(const string& path) {
     fd_.reset(TEMP_FAILURE_RETRY(
         open(path.c_str(),
-             O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW | O_SYNC,
+             O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW,
              0644)));
     if (fd_ == -1) {
       // Use ALOGE that logs to logd before __android_log_set_logger.
@@ -155,6 +155,7 @@
     WriteToFd(GetPrefix(log_message));
     WriteToFd(message_str);
     WriteToFd("\n");
+    fsync(fd_);
   }
 
  private: