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 ...@@ -17,6 +17,7 @@ import random
import string import string
import imp import imp
import socket import socket
import fcntl
os.chdir(os.path.dirname(os.path.abspath(__file__))) os.chdir(os.path.dirname(os.path.abspath(__file__)))
...@@ -138,19 +139,22 @@ class ns_flavor: ...@@ -138,19 +139,22 @@ class ns_flavor:
self.__copy_one(lib) self.__copy_one(lib)
def init(self, test_bin, deps): def init(self, test_bin, deps):
print "Construct root for %s" % test_bin
subprocess.check_call(["mount", "--make-private", "--bind", ".", self.root]) subprocess.check_call(["mount", "--make-private", "--bind", ".", self.root])
if not os.access(self.root + "/.constructed", os.F_OK): if not os.access(self.root + "/.constructed", os.F_OK):
for dir in ["/bin", "/sbin", "/etc", "/lib", "/lib64", "/dev", "/tmp", "/usr"]: with open(os.path.abspath(__file__)) as o:
os.mkdir(self.root + dir) fcntl.flock(o, fcntl.LOCK_EX)
os.chmod(self.root + dir, 0777) if not os.access(self.root + "/.constructed", os.F_OK):
print "Construct root for %s" % test_bin
os.mknod(self.root + "/dev/tty", stat.S_IFCHR, os.makedev(5, 0)) for dir in ["/bin", "/sbin", "/etc", "/lib", "/lib64", "/dev", "/tmp", "/usr"]:
os.chmod(self.root + "/dev/tty", 0666) os.mkdir(self.root + dir)
os.mknod(self.root + "/.constructed", stat.S_IFREG | 0600) os.chmod(self.root + dir, 0777)
for ldir in [ "/bin", "/sbin", "/lib", "/lib64" ]:
os.symlink(".." + ldir, self.root + "/usr" + ldir) os.mknod(self.root + "/dev/tty", stat.S_IFCHR, os.makedev(5, 0))
os.chmod(self.root + "/dev/tty", 0666)
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) self.__copy_libs(test_bin)
for dep in deps: 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