zdtm.py: call clean_tests_root() from one process only

Submitted by Andrei Vagin on Aug. 31, 2016, 9:26 p.m.

Details

Message ID 1472678766-13002-1-git-send-email-avagin@openvz.org
State Rejected
Series "zdtm.py: call clean_tests_root() from one process only"
Headers show

Commit Message

Andrei Vagin Aug. 31, 2016, 9:26 p.m.
From: Andrei Vagin <avagin@virtuozzo.com>

An atexit hook is executed for forked processes too,
clean_tests_root() has to be called only once.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 test/zdtm.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm.py b/test/zdtm.py
index abcd5ed..3189aff 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -45,11 +45,12 @@  def traceit(f, e, a):
 # Root dir for ns and uns flavors. All tests
 # sit in the same dir
 tests_root = None
+tests_root_pid = -1
 
 
 def clean_tests_root():
 	global tests_root
-	if tests_root:
+	if tests_root and tests_root_pid == os.getpid():
 		os.rmdir(tests_root)
 
 
@@ -57,6 +58,7 @@  def make_tests_root():
 	global tests_root
 	if not tests_root:
 		tests_root = tempfile.mkdtemp("", "criu-root-", "/tmp")
+		tests_root_pid = os.getpid()
 		atexit.register(clean_tests_root)
 	return tests_root