[CRIU] Re: [PATCH cr 3/3] crtools: add "pid" to the --namespaces cmdline option arguments

Pavel Emelyanov xemul at parallels.com
Thu Jun 21 04:21:38 EDT 2012


On 06/21/2012 11:14 AM, Andrey Vagin wrote:
> 
> to require dumping pid namespace. Dump and restore will be failed if
> a tress doesn't contain a process init.
> 
> pid namespace will be created implicitly if a process init in the tree.
> 
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  cr-restore.c |    4 ++++
>  crtools.c    |    4 +++-
>  namespaces.c |    3 +++
>  3 files changed, 10 insertions(+), 1 deletions(-)
> 

> diff --git a/cr-restore.c b/cr-restore.c
> index d5c15d9..c9a151d 100644
> --- a/cr-restore.c
> +++ b/cr-restore.c
> @@ -709,6 +709,10 @@ static int restore_root_task(struct pstree_item *init, struct cr_options *opts)
>  	 * the ns contents dumping/restoring. Need to revisit
>  	 * this later.
>  	 */
> +	if (opts->namespaces_flags & CLONE_NEWPID && init->pid.pid != 1) {

Please, use braces and merge this pid == 1 check with the one below

> +		pr_err("Can't restore pid namespace without the process init\n");
> +		return -1;
> +	}
>  
>  	if (init->pid.pid == 1) {
>  		sprintf(proc_mountpoint, "/tmp/crtools-proc.XXXXXX");
> diff --git a/crtools.c b/crtools.c
> index fc0e010..d4d2305 100644
> --- a/crtools.c
> +++ b/crtools.c
> @@ -187,6 +187,8 @@ static int parse_ns_string(const char *ptr)
>  			opts.namespaces_flags |= CLONE_NEWIPC;
>  		else if (!strncmp(ptr, "mnt", 3))
>  			opts.namespaces_flags |= CLONE_NEWNS;
> +		else if (!strncmp(ptr, "pid", 3))
> +			opts.namespaces_flags |= CLONE_NEWPID;
>  		else
>  			goto bad_ns;
>  		ptr += 4;
> @@ -392,7 +394,7 @@ usage:
>  
>  	pr_msg("\n* Special resources support:\n");
>  	pr_msg("  -n|--namespaces       checkpoint/restore namespaces - values must be separated by comma\n");
> -	pr_msg("                        supported: uts, ipc\n");
> +	pr_msg("                        supported: uts, ipc, pid\n");
>  	pr_msg("  -x|--ext-unix-sk      allow external unix connections\n");
>  	pr_msg("     --%s  checkpoint/restore established TCP connections\n", SK_EST_PARAM);
>  
> diff --git a/namespaces.c b/namespaces.c
> index daf6343..303a0da 100644
> --- a/namespaces.c
> +++ b/namespaces.c
> @@ -82,6 +82,9 @@ int dump_namespaces(struct pid *ns_pid, unsigned int ns_flags)
>  
>  	pr_info("Dumping %d(%d)'s namespaces\n", ns_pid->pid, ns_pid->real_pid);
>  
> +	if (opts.namespaces_flags & CLONE_NEWPID && ns_pid->pid != 1)
> +		pr_err("Can't dump a pid namespace without the process init\n");

Only pr_err?

> +
>  	pid = fork();
>  	if (pid < 0) {
>  		pr_perror("Can't fork ns dumper");


More information about the CRIU mailing list