Module: check_mk
Branch: master
Commit: 96e91b87d88ea5aa9a495a28dca1418cbd7703d8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=96e91b87d88ea5…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Thu May 17 11:57:34 2018 +0200
5812 FIX Fixed Check_MK check helper crashes related to loading of precompiled checks
The latest versions no longer read checks as plain text python files (Werk 6046).
The operation which generates the precompilated file was not atomic, so a file could
be partially written, while being read by another process.
This caused various exceptions in multiple checks.
Change-Id: I5ef5e0359d3aeec7954e0d08fea857a1f40e1fd4
---
.werks/5812 | 13 ++++++++
omd/packages/python/Makefile | 6 ++++
.../python/patches/pycompile_compile_atomic.dif | 35 ++++++++++++++++++++++
3 files changed, 54 insertions(+)
diff --git a/.werks/5812 b/.werks/5812
new file mode 100644
index 0000000..07efb11
--- /dev/null
+++ b/.werks/5812
@@ -0,0 +1,13 @@
+Title: Fixed Check_MK check helper crashes related to loading of precompiled checks
+Level: 2
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1526550541
+Class: fix
+
+The latest versions no longer read checks as plain text python files (Werk 6046).
+The operation which generates the precompilated file was not atomic, so a file could
+be partially written, while being read by another process.
+This caused various exceptions in multiple checks.
diff --git a/omd/packages/python/Makefile b/omd/packages/python/Makefile
index 503535e..8e05038 100644
--- a/omd/packages/python/Makefile
+++ b/omd/packages/python/Makefile
@@ -8,6 +8,12 @@ DIR = $(NAME)-$(VERSION)
build: bin/gcc bin/g++
tar xzf $(DIR).tgz
+
+ set -e ; for p in patches/*.dif ; do \
+ echo "applying $$p..." ; \
+ patch -p1 -b -d $(DIR) < $$p ; \
+ done
+
# Things are a bit tricky here: For PGO/LTO we need a rather recent compiler,
# but we don't want to bake paths to our build system into _sysconfigdata and
# friends. Workaround: Find a recent compiler to be used for building and make a
diff --git a/omd/packages/python/patches/pycompile_compile_atomic.dif
b/omd/packages/python/patches/pycompile_compile_atomic.dif
new file mode 100644
index 0000000..a7e844f
--- /dev/null
+++ b/omd/packages/python/patches/pycompile_compile_atomic.dif
@@ -0,0 +1,35 @@
+diff -r 8edfe539d4c6 Lib/py_compile.py
+--- a/Lib/py_compile.py Mon May 20 10:34:58 2013 -0400
++++ b/Lib/py_compile.py Mon May 20 17:46:50 2013 -0400
+@@ -120,13 +120,24 @@
+ return
+ if cfile is None:
+ cfile = file + (__debug__ and 'c' or 'o')
+- with open(cfile, 'wb') as fc:
+- fc.write('\0\0\0\0')
+- wr_long(fc, timestamp)
+- marshal.dump(codeobject, fc)
+- fc.flush()
+- fc.seek(0, 0)
+- fc.write(MAGIC)
++ # Atomically write the pyc/pyo file. Issue #13146.
++ # id() is used to generate a pseudo-random filename.
++ path_tmp = '{}.{}'.format(cfile, id(cfile))
++ try:
++ with open(path_tmp, 'wb') as fc:
++ fc.write('\0\0\0\0')
++ wr_long(fc, timestamp)
++ marshal.dump(codeobject, fc)
++ fc.flush()
++ fc.seek(0, 0)
++ fc.write(MAGIC)
++ os.rename(path_tmp, cfile)
++ except OSError:
++ try:
++ os.unlink(path_tmp)
++ except OSError:
++ pass
++ raise
+
+ def main(args=None):
+ """Compile several source files.