[CRIU] [PATCH 1/2] crtools/usage: error on excessive subcommands

Kir Kolyshkin kir at openvz.org
Mon Jan 9 11:01:26 PST 2017


Looks good, thanks!

Reviewed-by: Kir Kolyshkin <kir at openvz.org>

On 01/09/2017 08:59 AM, Dmitry Safonov wrote:
> Before:
>    [~]# criu check lazy_pages
>    Looks good.
>    [~]# criu check --feature lazy_pages
>    Error (criu/kerndat.c:588): Lazy pages are not available
> After:
>    [~]# criu check lazy_pages
>    Error: excessive parameters for command check
>    ...skipped usage() output...
>
> Just a little improvement, not to mislead anyone.
>
> Cc: Kir Kolyshkin <kir at openvz.org>
> Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
> ---
>   criu/crtools.c | 16 ++++++++++++++--
>   1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/criu/crtools.c b/criu/crtools.c
> index 06b2fa781892..ea470e4a75f8 100644
> --- a/criu/crtools.c
> +++ b/criu/crtools.c
> @@ -214,6 +214,7 @@ int main(int argc, char *argv[], char *envp[])
>   	int ret = -1;
>   	bool usage_error = true;
>   	bool has_exec_cmd = false;
> +	bool has_sub_command;
>   	int opt, idx;
>   	int log_level = LOG_UNSET;
>   	char *imgs_dir = ".";
> @@ -649,8 +650,10 @@ int main(int argc, char *argv[], char *envp[])
>   		goto usage;
>   	}
>   
> +	has_sub_command = (argc - optind) > 1;
> +
>   	if (has_exec_cmd) {
> -		if (argc - optind <= 1) {
> +		if (!has_sub_command) {
>   			pr_msg("Error: --exec-cmd requires a command\n");
>   			goto usage;
>   		}
> @@ -670,6 +673,13 @@ int main(int argc, char *argv[], char *envp[])
>   			return 1;
>   		memcpy(opts.exec_cmd, &argv[optind + 1], (argc - optind - 1) * sizeof(char *));
>   		opts.exec_cmd[argc - optind - 1] = NULL;
> +	} else {
> +		/* No subcommands except for cpuinfo and restore --exec-cmd */
> +		if (strcmp(argv[optind], "cpuinfo") && has_sub_command) {
> +			pr_msg("Error: excessive parameter%s for command %s\n",
> +				(argc - optind) > 2 ? "s" : "", argv[optind]);
> +			goto usage;
> +		}
>   	}
>   
>   	/* We must not open imgs dir, if service is called */
> @@ -781,8 +791,10 @@ int main(int argc, char *argv[], char *envp[])
>   		return cr_dedup() != 0;
>   
>   	if (!strcmp(argv[optind], "cpuinfo")) {
> -		if (!argv[optind + 1])
> +		if (!argv[optind + 1]) {
> +			pr_msg("Error: cpuinfo requires an action: dump or check\n");
>   			goto usage;
> +		}
>   		if (!strcmp(argv[optind + 1], "dump"))
>   			return cpuinfo_dump();
>   		else if (!strcmp(argv[optind + 1], "check"))



More information about the CRIU mailing list