1 # Copyright 2014 The Chromium OS Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import os 6 import subprocess 7 import sys 8 import tempfile 9 10 # Parent passes base path as first argument. 11 child_path = os.path.join(sys.argv[1], "mountns-enter-child.py") 12 13 # Mount tmpfs. 14 tmpdir = tempfile.mkdtemp(prefix="newns-", dir="/tmp") 15 ret = subprocess.check_call(["mount", "tmpfs", tmpdir, "-t", "tmpfs"]) 16 test_file = os.path.join(tmpdir, "test") 17 with open(test_file, "w") as t: 18 print >> t, "test" 19 20 # Exec child and enter existing mount namespace. 21 ret = subprocess.call(["/sbin/minijail0", "-V", "/proc/1/ns/mnt", "--", 22 sys.executable, child_path, test_file]) 23 24 # Clean up. 25 subprocess.check_call("umount %s" % tmpdir, shell=True) 26 os.rmdir(tmpdir) 27 28 # Return child's exit status. 29 sys.exit(ret) 30