[icinga-checkins] icinga.org: icinga-core/mfriedrich/workers: core: fsync() files before fclose() #2949

git at icinga.org git at icinga.org
Sun Aug 5 23:32:12 CEST 2012


Module: icinga-core
Branch: mfriedrich/workers
Commit: 6b42ecfe3cf822cc3ac5e68d769cf3e77b7287de
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=6b42ecfe3cf822cc3ac5e68d769cf3e77b7287de

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Sun Aug  5 13:04:09 2012 +0200

core: fsync() files before fclose() #2949

otherwise, we setup the errno flag to contain EBADFs, meaning future
debugging calls to strerror() or the %m allocator in strings become
erroneous.

refs #2949

---

 xdata/xrddefault.c |    2 +-
 xdata/xsddefault.c |    6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/xdata/xrddefault.c b/xdata/xrddefault.c
index 677ee13..f90f2fd 100644
--- a/xdata/xrddefault.c
+++ b/xdata/xrddefault.c
@@ -575,8 +575,8 @@ int xrddefault_save_state_information(void) {
 	}
 
 	fflush(fp);
-	result = fclose(fp);
 	fsync(fd);
+	result = fclose(fp);
 
 	/* save/close was successful */
 	if (result == 0) {
diff --git a/xdata/xsddefault.c b/xdata/xsddefault.c
index 704c616..07e6e30 100644
--- a/xdata/xsddefault.c
+++ b/xdata/xsddefault.c
@@ -709,12 +709,12 @@ int xsddefault_save_status_data(void) {
 	/* flush the file to disk */
 	fflush(fp);
 
-	/* close the temp file */
-	result = fclose(fp);
-
 	/* fsync the file so that it is completely written out before moving it */
 	fsync(fd);
 
+	/* close the temp file */
+	result = fclose(fp);
+
 	/* save/close was successful */
 	if (result == 0) {
 





More information about the icinga-checkins mailing list