From a08aa44064dcadfed48383a08d0e73ad22f01386 Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Mon, 21 Dec 2020 20:25:47 +0000 Subject: [PATCH] criu-ns: Extract mount new /proc into a function By extracting this code into a function the main code becomes smaller and more obvious. Signed-off-by: Radostin Stoyanov --- scripts/criu-ns | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/scripts/criu-ns b/scripts/criu-ns index de9308035..89e52c9ab 100755 --- a/scripts/criu-ns +++ b/scripts/criu-ns @@ -56,6 +56,18 @@ else: _umount.restype = ctypes.c_int +def _mount_new_proc(): + """ + Mount new /proc filesystem. + """ + if _mount(None, b"/", None, MS_SLAVE|MS_REC, None): + _errno = ctypes.get_errno() + raise OSError(_errno, errno.errorcode[_errno]) + if _mount(b'proc', b'/proc', b'proc', 0, None): + _errno = ctypes.get_errno() + raise OSError(_errno, errno.errorcode[_errno]) + + def run_criu(): print(sys.argv) os.execlp('criu', *['criu'] + sys.argv[1:]) @@ -69,14 +81,7 @@ def wrap_restore(): criu_pid = os.fork() if criu_pid == 0: - # Mount new /proc - if _mount(None, b"/", None, MS_SLAVE|MS_REC, None) != 0: - _errno = ctypes.get_errno() - raise OSError(_errno, errno.errorcode[_errno]) - - if _mount(b'proc', b'/proc', b'proc', 0, None) != 0: - _errno = ctypes.get_errno() - raise OSError(_errno, errno.errorcode[_errno]) + _mount_new_proc() # Spawn CRIU binary run_criu()