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 5import os 6import subprocess 7import sys 8import tempfile 9 10# Parent passes base path as first argument. 11child_path = os.path.join(sys.argv[1], "mountns-enter-child.py") 12 13# Mount tmpfs. 14tmpdir = tempfile.mkdtemp(prefix="newns-", dir="/tmp") 15ret = subprocess.check_call(["mount", "tmpfs", tmpdir, "-t", "tmpfs"]) 16test_file = os.path.join(tmpdir, "test") 17with open(test_file, "w") as t: 18 print >> t, "test" 19 20# Exec child and enter existing mount namespace. 21ret = subprocess.call(["/sbin/minijail0", "-V", "/proc/1/ns/mnt", "--", 22 sys.executable, child_path, test_file]) 23 24# Clean up. 25subprocess.check_call("umount %s" % tmpdir, shell=True) 26os.rmdir(tmpdir) 27 28# Return child's exit status. 29sys.exit(ret) 30