summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael E Brown <michael_e_brown@dell.com>2007-12-06 10:36:02 -0600
committerMichael E Brown <michael_e_brown@dell.com>2007-12-06 10:36:02 -0600
commitb572e9d52906ed969e790f1c896a7cefa6eeeb27 (patch)
tree5a7fa8b85db21e52aab3e09a593440661bdd3de1
parentaf73fa7d2354208f85cec98aad821f1c50a55645 (diff)
downloadmock-b572e9d52906ed969e790f1c896a7cefa6eeeb27.tar.gz
mock-b572e9d52906ed969e790f1c896a7cefa6eeeb27.tar.xz
mock-b572e9d52906ed969e790f1c896a7cefa6eeeb27.zip
add unshare
-rwxr-xr-xpy/mock.py6
-rw-r--r--py/mock/util.py28
2 files changed, 29 insertions, 5 deletions
diff --git a/py/mock.py b/py/mock.py
index e8623de..d742f39 100755
--- a/py/mock.py
+++ b/py/mock.py
@@ -431,6 +431,12 @@ def main(ret):
if options.mode not in ('chroot', 'shell', 'install', 'installdeps') and config_opts['clean']:
chroot.clean()
+ # New namespace starting from here
+ try:
+ mock.util.unshare(mock.util.CLONE_NEWNS)
+ except:
+ log.info("Namespace unshare failed.")
+
if options.mode == 'init':
chroot.init()
diff --git a/py/mock/util.py b/py/mock/util.py
index 4710a4b..0f74ac3 100644
--- a/py/mock/util.py
+++ b/py/mock/util.py
@@ -190,16 +190,34 @@ personality_defs['ppc64'] = 0x0000
personality_defs['i386'] = 0x0008
personality_defs['ppc'] = 0x0008
+import ctypes
+_libc = ctypes.cdll.LoadLibrary("libc.so.6")
+_errno = ctypes.c_int.in_dll(_libc, "errno")
+_libc.personality.argtypes = [ctypes.c_ulong]
+_libc.personality.restype = ctypes.c_int
+
decorate(traceLog())
def condPersonality(per=None):
if personality_defs.get(per, None) is None: return
- import ctypes
- _libc = ctypes.cdll.LoadLibrary("libc.so.6")
- _libc.personality.argtypes = [ctypes.c_ulong]
- _libc.personality.restype = ctypes.c_int
- _libc.personality(personality_defs[per])
+ res = _libc.personality(personality_defs[per])
+ if res:
+ raise OSError(_errno.value, os.strerror(_errno.value))
getLog().debug("set personality (setarch)")
+CLONE_NEWNS = 0x00020000
+
+decorate(traceLog())
+def unshare(flags):
+ getLog().debug("Unsharing. Flags: %s" % flags)
+ try:
+ _libc.unshare.argtypes = [ctypes.c_int,]
+ _libc.unshare.restype = ctypes.c_int
+ res = _libc.unshare(flags)
+ if res:
+ raise OSError(_errno.value, os.strerror(_errno.value))
+ except AttributeError, e:
+ pass
+
# logger =
# output = [1|0]
# chrootPath