[CRIU] [PATCH v3 2/6] ns: Use CLONE_VM in create_user_ns_hierarhy_fn()

Andrei Vagin avagin at virtuozzo.com
Tue Apr 4 17:10:01 PDT 2017


On Sat, Apr 01, 2017 at 02:37:29PM +0300, Kirill Tkhai wrote:
> This function may call functions like open_proc(),
> so use CLONE_VM to reflect children open files in
> parent memory.
> 
> v3: New
> 
> Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
> ---
>  criu/namespaces.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/criu/namespaces.c b/criu/namespaces.c
> index 6278267f..fc75e5fa 100644
> --- a/criu/namespaces.c
> +++ b/criu/namespaces.c
> @@ -2227,7 +2227,7 @@ static int create_user_ns_hierarhy_fn(void *in_arg)

        map = mmap(NULL, map_size, PROT_WRITE | PROT_READ, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
        if (map == MAP_FAILED) {
                pr_perror("Failed to mmap");
                goto out;
        }
        arg = map + map_size - sizeof(*arg);

now you can allocate arg on the stack

>  		arg->me = child;
>  		futex_init(futex);
>  
> -		pid = clone(create_user_ns_hierarhy_fn, stack, CLONE_NEWUSER | CLONE_FILES | SIGCHLD, arg);
> +		pid = clone(create_user_ns_hierarhy_fn, stack, CLONE_NEWUSER | CLONE_VM | CLONE_FILES | SIGCHLD, arg);
>  		if (pid < 0) {
>  			pr_perror("Can't clone");
>  			goto out;
> @@ -2244,8 +2244,10 @@ static int create_user_ns_hierarhy_fn(void *in_arg)
>  		errno = 0;
>  		if (wait(&status) < 0 || !WIFEXITED(status) || WEXITSTATUS(status)) {

Here you need to use waitpid.

>  			pr_perror("Child process waiting: %d", status);
> +			close_pid_proc();
>  			goto out;
>  		}
> +		close_pid_proc();
>  	}
>  
>  	ret = 0;
> 


More information about the CRIU mailing list