From 2e3e75b7239ea6caa042287ad720326236ddd762 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Mon, 12 Nov 2007 17:10:18 +0000
Subject: [PATCH] Call fsync() after modifying /etc/hosts.

This is a critical file. Breaking it would be very bad. Thus, if the system
crashes before the data is synched to the disk, it should have the complete
file afterwards.

Reviewed-by: iustinp
---
 lib/utils.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/utils.py b/lib/utils.py
index 193fde812..53fa6f26c 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -775,6 +775,7 @@ def SetEtcHostsEntry(file_name, ip, hostname, aliases):
         out.write('\n')
 
         out.flush()
+        os.fsync(out)
         os.rename(tmpname, file_name)
       finally:
         f.close()
@@ -810,6 +811,7 @@ def RemoveEtcHostsEntry(file_name, hostname):
           out.write(line)
 
         out.flush()
+        os.fsync(out)
         os.rename(tmpname, file_name)
       finally:
         f.close()
-- 
GitLab