[CRIU] [RFC PATCH 03/21] zdtm: zdtm.py: remove directories before recreating them in __construct_root(); fix TOCTTOU in clean()

Ivan Shapovalov intelfx at intelfx.name
Fri Feb 19 06:50:26 PST 2016


Signed-off-by: Ivan Shapovalov <intelfx at intelfx.name>
---
 test/zdtm.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/test/zdtm.py b/test/zdtm.py
index 3caf227..ef521f4 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -214,6 +214,11 @@ class ns_flavor:
 
 	def __construct_root(self):
 		for dir in self.__root_dirs:
+			try:
+			    shutil.rmtree(self.root + dir)
+			except OSError as e:
+			    if e.errno != errno.ENOENT:
+				raise
 			os.mkdir(self.root + dir)
 			os.chmod(self.root + dir, 0777)
 
@@ -258,8 +263,11 @@ class ns_flavor:
 		for d in ns_flavor.__root_dirs:
 			p = './' + d
 			print 'Remove %s' % p
-			if os.access(p, os.F_OK):
-				shutil.rmtree('./' + d)
+			try:
+			    shutil.rmtree('./' + d)
+			except OSError as e:
+			    if e.errno != errno.ENOENT:
+				raise
 
 		if os.access('./.constructed', os.F_OK):
 			os.unlink('./.constructed')
-- 
2.7.1



More information about the CRIU mailing list