Module: check_mk
Branch: master
Commit: 3b81cf9ed19b4df1ccd98b6d90d9271da4ceaa86
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3b81cf9ed19b4d…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Mon Sep 12 11:45:01 2016 +0200
3801 FIX Fixed race condition with persisted data
The deletion of the persisted file no longer causes
an exception when the file is missing.
---
.werks/3801 | 10 ++++++++++
ChangeLog | 1 +
modules/check_mk_base.py | 17 ++++++++++++-----
3 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/.werks/3801 b/.werks/3801
new file mode 100644
index 0000000..e427475
--- /dev/null
+++ b/.werks/3801
@@ -0,0 +1,10 @@
+Title: Fixed race condition with persisted data
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.4.0i1
+Date: 1473673422
+Class: fix
+
+The deletion of the persisted file no longer causes
+an exception when the file is missing.
diff --git a/ChangeLog b/ChangeLog
index 3255750..aa81cbc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -379,6 +379,7 @@
* 3848 FIX: megaraid_pdisks: Handle "rebuild" state as WARNING instead of
UNKNOWN
* 3849 FIX: check_cpu_peaks: Fixed broken active check
* 3870 FIX: elphase.include: more robust against none type params
+ * 3801 FIX: Fixed race condition with persisted data...
Multisite:
* 3187 notification view: new filter for log command via regex
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index c59b5b3..48b385a 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -507,11 +507,15 @@ def get_realhost_info(hostname, ipaddress, check_type,
max_cache_age,
return info[check_type] # return only data for specified check
def store_persisted_info(hostname, persisted):
- dir = var_dir + "/persisted/"
+ dirname = var_dir + "/persisted/"
if persisted:
- if not os.path.exists(dir):
- os.makedirs(dir)
- file(dir + hostname, "w").write("%r\n" % persisted)
+ if not os.path.exists(dirname):
+ os.makedirs(dirname)
+
+ file_path = "%s/%s" % (dirname, hostname)
+ file("%s.#new" % file_path, "w").write("%r\n" %
persisted)
+ os.rename("%s.#new" % file_path, file_path)
+
verbose("Persisted sections %s.\n" % ",
".join(persisted.keys()))
@@ -543,7 +547,10 @@ def add_persisted_info(hostname, info):
modified = True
if not persisted:
- os.remove(file_path)
+ try:
+ os.remove(file_path)
+ except OSError:
+ pass
elif modified:
store_persisted_info(hostname, persisted)