[CRIU] [PATCH] criu: Add exec-cmd option.

Christopher Covington cov at codeaurora.org
Wed Mar 19 13:41:16 PDT 2014


Hi Deyan,

On 03/19/2014 01:39 PM, Deyan Doychev wrote:
> From: Deyan Doychev <deyandoichev at gmail.com>
> 
> The --exec-cmd option specifies a command that will be execve()-ed on successful
> restore. This way the command specified here will become the parent process of
> the restored process tree.
> 
> When this option is specified criu will fork to become a daemon before it starts
> restoring the processes. It also implies the -d option so waiting for the
> restored processes to finish is responsibility of the command specified here.
> 
> This option will be used when restoring LinuX Containers.

I think it might be useful to document why you've chosen this implementation
over the subreaper option (even if the answer is simple). I'm imagining that
one possible benefit of the subreaper option is that the exec'd command could
have its own standard I/O file descriptors. CRIU has -o, though, so I don't
know if sharing would really be a problem. The environment is shared too,
right? But again, I don't know if that'd really be a problem.

> diff --git a/crtools.c b/crtools.c
> index 047ac53..5591225 100644
> --- a/crtools.c
> +++ b/crtools.c

> @@ -390,7 +412,16 @@ int main(int argc, char *argv[])
>  	if (!strcmp(argv[optind], "restore")) {
>  		if (tree_id)
>  			pr_warn("Using -t with criu restore is obsoleted\n");
> -		return cr_restore_tasks() != 0;
> +
> +		ret = cr_restore_tasks();
> +		if (ret == 0 && opts.exec_cmd) {
> +			extern char **environ;
> +			execve(opts.exec_cmd[0], opts.exec_cmd, environ);

Can you use execvp so that users don't have to specify an absolute path?

> +			pr_perror("Failed to exec command %s\n", opts.exec_cmd[0]);
> +			ret = 1;
> +		}
> +
> +		return ret != 0;

In my testing, a non-zero exit code wasn't propagated to the command line on
failure.

>  	}
>  
>  	if (!strcmp(argv[optind], "show"))

I think perf has the same general problem as lxc. While I've been able to
develop other workarounds like using a third program to ptrace attach the
restored process and essentially proxy the SIGCHLD something more
straightforward would be nice. I tested this patch by running perf stat on a
restored process in a 32-bit ARM simulator and it seemed to work.

./criu restore -v4 -o restore.log --exec-cmd "perf stat -v -p $pid -e
instructions:u -o perf.log"

Tested-by: Christopher Covington <cov at codeaurora.org>

Regards,
Christopher

P.S. Apologies for not cross-posting.

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by the Linux Foundation.


More information about the CRIU mailing list