[CRIU] [PATCH 3/7] mount: use add_to_string() in attach_option()

Stanislav Kinsburskiу skinsbursky at odin.com
Thu Dec 17 02:23:51 PST 2015


17 дек. 2015 г. 11:14 AM пользователь Pavel Emelyanov <xemul at parallels.com> написал:
>
> On 12/16/2015 11:51 PM, Stanislav Kinsburskiy wrote: 
> > 
> > 
> > 16.12.2015 18:45, Pavel Emelyanov пишет: 
> >> On 12/16/2015 06:33 PM, Stanislav Kinsburskiy wrote: 
> >>> Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com> 
> >>> --- 
> >>>   mount.c |   23 +++++------------------ 
> >>>   1 file changed, 5 insertions(+), 18 deletions(-) 
> >>> 
> >>> diff --git a/mount.c b/mount.c 
> >>> index 0c3192a..bcb8a77 100644 
> >>> --- a/mount.c 
> >>> +++ b/mount.c 
> >>> @@ -1163,24 +1163,11 @@ out: 
> >>>   
> >>>   static int attach_option(struct mount_info *pm, char *opt) 
> >>>   { 
> >>> - char *buf; 
> >>> - int len, olen; 
> >>> - 
> >>> - len = strlen(pm->options); 
> >>> - olen = strlen(opt); 
> >>> - buf = xrealloc(pm->options, len + olen + 2); 
> >>> - if (buf == NULL) 
> >>> - return -1; 
> >>> - 
> >>> - if (len && buf[len - 1] != ',') { 
> >>> - buf[len] = ','; 
> >>> - len++; 
> >>> - } 
> >>> - 
> >>> - memcpy(buf + len, opt, olen + 1); 
> >>> - pm->options = buf; 
> >>> - 
> >>> - return 0; 
> >>> + if (pm->options[strlen(pm->options)-1] == ',') 
> >> Isn't it faster to check for pm->options[0] != '\0'? 
> >> 
> > 
> > This check for "," at the end was strange. I don't really understand, 
> > where it comes from. 
> > I though, that the intention is to not duplicate comma when adding 
> > another option. 
> > No? 
>
> Well, the intention was not to put comma in front of the very 
> first option :) Like this 
>
> 1st option attach : str += option 
> >=2nd option attach : str += ',' + option 
>
> If we always do str += ',' + option, then the string would look like 
> ,opt1,opt2,opt3 instead or opt1,opt2,opt3 
>

Ok, I got it. Will change.

> >>> + pm->options = add_to_string(pm->options, "%s", opt); 
> >>> + else 
> >>> + pm->options = add_to_string(pm->options, ",%s", opt); 
> >>> + return pm->options ? 0 : -1; 
> >>>   } 
> >>>   
> >>>   /* Is it mounted w or w/o the newinstance option */ 
> >>> 
> >>> _______________________________________________ 
> >>> CRIU mailing list 
> >>> CRIU at openvz.org 
> >>> https://lists.openvz.org/mailman/listinfo/criu 
> >>> . 
> >>> 
> > 
> > . 
> > 
>



More information about the CRIU mailing list