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

git at icinga.org git at icinga.org
Sun Aug 19 19:44:44 CEST 2012


Module: icinga-core
Branch: r1.7
Commit: 34dc538fb495a446c47fa6cbea04c60256c438d2
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=34dc538fb495a446c47fa6cbea04c60256c438d2

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

---

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

diff --git a/Changelog b/Changelog
index 2b52426..b08582c 100644
--- a/Changelog
+++ b/Changelog
@@ -17,6 +17,7 @@ FIXES
 * core: add hint on icinga.cfg package location, and tip to read Changelog CHANGES on upgrades #2879 - MF
 * core: bail out early with config error if resource.cfg macros contain NULL values #2879 - MF
 * core: fix logical bug on icinga.cfg detection on config read #2879 - MF
+* core: fsync() files before fclose() (Andreas Ericsson) #2948 - MF
 
 * idoutils: fix icinga mysql db creation script grants access to all dbs #2917 - MF
 
diff --git a/xdata/xrddefault.c b/xdata/xrddefault.c
index 541d3d2..144056d 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 42e0b08..31b67aa 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