mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 14:55:39 +00:00
mount: Allocate mountinfo strings dynamically
On the restore path this structure will be used and it will be better to have them char * rather than char[64]. When scanning proc use the %ms specifier for this. Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
@@ -89,14 +89,14 @@ struct proc_mountinfo {
|
|||||||
int mnt_id;
|
int mnt_id;
|
||||||
int parent_mnt_id;
|
int parent_mnt_id;
|
||||||
unsigned int s_dev;
|
unsigned int s_dev;
|
||||||
char root[64];
|
char *root;
|
||||||
char mountpoint[64];
|
char *mountpoint;
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
int master_id;
|
int master_id;
|
||||||
int shared_id;
|
int shared_id;
|
||||||
char fstype[32];
|
char *fstype;
|
||||||
char source[64];
|
char *source;
|
||||||
char options[128];
|
char *options;
|
||||||
struct proc_mountinfo *next;
|
struct proc_mountinfo *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
18
proc_parse.c
18
proc_parse.c
@@ -589,12 +589,12 @@ static int parse_mountinfo_ent(char *str, struct proc_mountinfo *new)
|
|||||||
{
|
{
|
||||||
unsigned int kmaj, kmin;
|
unsigned int kmaj, kmin;
|
||||||
int ret, n;
|
int ret, n;
|
||||||
char opt[64];
|
char *opt;
|
||||||
|
|
||||||
ret = sscanf(str, "%i %i %u:%u %63s %63s %63s %n",
|
ret = sscanf(str, "%i %i %u:%u %ms %ms %ms %n",
|
||||||
&new->mnt_id, &new->parent_mnt_id,
|
&new->mnt_id, &new->parent_mnt_id,
|
||||||
&kmaj, &kmin, new->root, new->mountpoint,
|
&kmaj, &kmin, &new->root, &new->mountpoint,
|
||||||
opt, &n);
|
&opt, &n);
|
||||||
if (ret != 7)
|
if (ret != 7)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -603,18 +603,26 @@ static int parse_mountinfo_ent(char *str, struct proc_mountinfo *new)
|
|||||||
if (parse_mnt_flags(opt, &new->flags))
|
if (parse_mnt_flags(opt, &new->flags))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
free(opt); /* after %ms scanf */
|
||||||
|
|
||||||
str += n;
|
str += n;
|
||||||
if (parse_mnt_opt(str, new, &n))
|
if (parse_mnt_opt(str, new, &n))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
str += n;
|
str += n;
|
||||||
ret = sscanf(str, "%31s %53s %63s", new->fstype, new->source, opt);
|
ret = sscanf(str, "%ms %ms %ms", &new->fstype, &new->source, &opt);
|
||||||
if (ret != 3)
|
if (ret != 3)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
new->options = xmalloc(strlen(opt));
|
||||||
|
if (!new->options)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (parse_sb_opt(opt, &new->flags, new->options))
|
if (parse_sb_opt(opt, &new->flags, new->options))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
free(opt);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user