Commit bada2929 authored by Pavel Emelyanov's avatar Pavel Emelyanov

zdtm.py: Fix race in root construction

If two ns_flavor.init() are called in parallel then all the os.mkdir()
calls would end up with EEXISTS exception.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a9632060
......@@ -17,6 +17,7 @@ import random
import string
import imp
import socket
import fcntl
os.chdir(os.path.dirname(os.path.abspath(__file__)))
......@@ -138,19 +139,22 @@ class ns_flavor:
self.__copy_one(lib)
def init(self, test_bin, deps):
print "Construct root for %s" % test_bin
subprocess.check_call(["mount", "--make-private", "--bind", ".", self.root])
if not os.access(self.root + "/.constructed", os.F_OK):
with open(os.path.abspath(__file__)) as o:
fcntl.flock(o, fcntl.LOCK_EX)
if not os.access(self.root + "/.constructed", os.F_OK):
print "Construct root for %s" % test_bin
for dir in ["/bin", "/sbin", "/etc", "/lib", "/lib64", "/dev", "/tmp", "/usr"]:
os.mkdir(self.root + dir)
os.chmod(self.root + dir, 0777)
os.mknod(self.root + "/dev/tty", stat.S_IFCHR, os.makedev(5, 0))
os.chmod(self.root + "/dev/tty", 0666)
os.mknod(self.root + "/.constructed", stat.S_IFREG | 0600)
for ldir in [ "/bin", "/sbin", "/lib", "/lib64" ]:
os.symlink(".." + ldir, self.root + "/usr" + ldir)
os.mknod(self.root + "/.constructed", stat.S_IFREG | 0600)
self.__copy_libs(test_bin)
for dep in deps:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment