[CRIU] [PATCH 1/4] proc_parse: search the uid/gid options only for sb opts

Pavel Emelyanov xemul at parallels.com
Thu Aug 13 08:30:22 PDT 2015


On 08/11/2015 06:33 PM, Andrey Vagin wrote:
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  proc_parse.c | 37 +++++++++++++++++++++++--------------
>  1 file changed, 23 insertions(+), 14 deletions(-)
> 
> diff --git a/proc_parse.c b/proc_parse.c
> index 00e2b7b..1f58f7f 100644
> --- a/proc_parse.c
> +++ b/proc_parse.c
> @@ -846,16 +846,33 @@ struct opt2flag {
>  	unsigned flag;
>  };
>  
> +bool sb_opt_cb(char *opt, char *unknown, size_t *uoff)

static

> +{
> +	unsigned int id;
> +
> +	if (sscanf(opt, "gid=%d", &id) == 1) {
> +		*uoff += sprintf(unknown + *uoff, "gid=%d", userns_gid(id));
> +		unknown[*uoff] = ',';
> +		(*uoff)++;
> +		return true;
> +	} else if (sscanf(opt, "uid=%d", &id) == 1) {
> +		*uoff += sprintf(unknown + *uoff, "uid=%d", userns_uid(id));
> +		unknown[*uoff] = ',';
> +		(*uoff)++;
> +		return true;
> +	}
> +	return false;
> +}
> +
>  static int do_opt2flag(char *opt, unsigned *flags,
> -		const struct opt2flag *opts, char *unknown)
> +		const struct opt2flag *opts, char *unknown,
> +		bool (*cb)(char *opt, char *unknown, size_t *uoff))
>  {
>  	int i;
>  	char *end;
>  	size_t uoff = 0;
>  
>  	while (1) {
> -		unsigned int id;
> -
>  		end = strchr(opt, ',');
>  		if (end)
>  			*end = '\0';
> @@ -866,15 +883,7 @@ static int do_opt2flag(char *opt, unsigned *flags,
>  				break;
>  			}
>  
> -		if (sscanf(opt, "gid=%d", &id) == 1) {
> -			uoff += sprintf(unknown + uoff, "gid=%d", userns_gid(id));
> -			unknown[uoff] = ',';
> -			uoff++;
> -		} else if (sscanf(opt, "uid=%d", &id) == 1) {
> -			uoff += sprintf(unknown + uoff, "uid=%d", userns_uid(id));
> -			unknown[uoff] = ',';
> -			uoff++;
> -		} else if (opts[i].opt == NULL) {
> +		if (opts[i].opt == NULL && cb && !cb(opt, unknown, &uoff)) {
>  			if (!unknown) {
>  				pr_err("Unknown option [%s]\n", opt);
>  				return -1;
> @@ -913,7 +922,7 @@ static int parse_mnt_flags(char *opt, unsigned *flags)
>  		{ },
>  	};
>  
> -	if (do_opt2flag(opt, flags, mnt_opt2flag, NULL))
> +	if (do_opt2flag(opt, flags, mnt_opt2flag, NULL, NULL))
>  		return -1;
>  
>  	/* Otherwise the kernel assumes RELATIME by default */
> @@ -934,7 +943,7 @@ static int parse_sb_opt(char *opt, unsigned *flags, char *uopt)
>  		{ },
>  	};
>  
> -	return do_opt2flag(opt, flags, sb_opt2flag, uopt);
> +	return do_opt2flag(opt, flags, sb_opt2flag, uopt, sb_opt_cb);
>  }
>  
>  static int parse_mnt_opt(char *str, struct mount_info *mi, int *off)
> 



More information about the CRIU mailing list