[CRIU] [PATCH 2/3] criu/config: allow init_config properly handle -h/--help

Andrei Vagin avagin at virtuozzo.com
Thu May 10 00:26:37 MSK 2018


On Wed, May 09, 2018 at 02:08:35PM -0700, Andrei Vagin wrote:
> On Wed, May 09, 2018 at 05:17:51PM +0300, Mike Rapoport wrote:
> > When config parsing was split into a separate part the handling of
> > -h/--help option during init_config was broken. Fix it.
> > 
> > Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
> > ---
> >  criu/config.c          | 11 ++++++-----
> >  criu/crtools.c         |  5 ++++-
> >  criu/include/crtools.h |  5 +++--
> >  3 files changed, 13 insertions(+), 8 deletions(-)
> > 
> > diff --git a/criu/config.c b/criu/config.c
> > index 5ff433c..bfaa057 100644
> > --- a/criu/config.c
> > +++ b/criu/config.c
> > @@ -184,16 +184,15 @@ static void init_configuration(int argc, char *argv[], int defaults_forbidden)
> >  	}
> >  }
> >  
> > -void init_config(int argc, char **argv, int *global_cfg_argc, int *user_cfg_argc)
> > +int init_config(int argc, char **argv, int *global_cfg_argc, int *user_cfg_argc,
> > +		bool *usage_error)
> >  {
> >  	int help_or_configs;
> > -	bool usage_error;
> >  
> >  	help_or_configs = passed_help_or_defaults_forbidden(argc, argv);
> >  	if (help_or_configs == 1) {
> > -		usage_error = false;
> > -		printf("goto usage: %d\n", usage_error);
> > -		return;
> > +		*usage_error = false;
> > +		return 1;
> 
> 
> >  	}
> >  
> >  	init_configuration(argc, argv, (help_or_configs == DEFAULT_CONFIGS_FORBIDDEN));
> > @@ -201,4 +200,6 @@ void init_config(int argc, char **argv, int *global_cfg_argc, int *user_cfg_argc
> >  		*global_cfg_argc = count_elements(global_conf);
> >  	if (user_conf != NULL)
> >  		*user_cfg_argc = count_elements(user_conf);
> > +
> > +	return 0;
> >  }
> > diff --git a/criu/crtools.c b/criu/crtools.c
> > index d9645ad..6326797 100644
> > --- a/criu/crtools.c
> > +++ b/criu/crtools.c
> > @@ -391,7 +391,10 @@ int main(int argc, char *argv[], char *envp[])
> >  		return cr_service_work(atoi(argv[2]));
> >  	}
> >  
> > -	init_config(argc, argv, &global_cfg_argc, &user_cfg_argc);
> > +	ret = init_config(argc, argv, &global_cfg_argc, &user_cfg_argc,
> > +			  &usage_error);
> > +	if (ret)
> 		usage_error = false;
> 
> But I think we don't need this. We will detect the -h options, when we
> will parse command line arguments.

I haven't noticed that you added &usage_error as an argument.

> 
> > +		goto usage;
> >  
> >  	while (1) {
> >  		idx = -1;
> > diff --git a/criu/include/crtools.h b/criu/include/crtools.h
> > index 234894f..5ffacb6 100644
> > --- a/criu/include/crtools.h
> > +++ b/criu/include/crtools.h
> > @@ -32,8 +32,9 @@ extern int cr_lazy_pages(bool daemon);
> >  extern int check_add_feature(char *arg);
> >  extern void pr_check_features(const char *offset, const char *sep, int width);
> >  
> > -extern void init_config(int argc, char **argv,
> > -			int *global_cfg_argc, int *user_cfg_argc);
> > +extern int init_config(int argc, char **argv,
> > +		       int *global_cfg_argc, int *user_cfg_argc,
> > +		       bool *usage_error);
> >  
> >  #define PPREP_HEAD_INACTIVE	((struct pprep_head *)-1)
> >  
> > -- 
> > 2.7.4
> > 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list