Skip to content

Commit

Permalink
mount: Move binfmt_misc entry restore code to subfunction
Browse files Browse the repository at this point in the history
Also rename restore_binfmt_misc_entry() to write_binfmt_misc_entry()

v6: New
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
  • Loading branch information
Kirill Tkhai authored and xemul committed Sep 13, 2016
1 parent 84cba65 commit 398e7d3
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions criu/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ static int binfmt_misc_dump(struct mount_info *pm)
return ret;
}

static int restore_binfmt_misc_entry(char *mp, char *buf, BinfmtMiscEntry *bme)
static int write_binfmt_misc_entry(char *mp, char *buf, BinfmtMiscEntry *bme)
{
int fd, len, ret = -1;
char path[PATH_MAX+1];
Expand Down Expand Up @@ -1493,6 +1493,31 @@ static int make_bfmtm_magic_str(char *buf, BinfmtMiscEntry *bme)
return 1;
}

static int binfmt_misc_restore_bme(struct mount_info *mi, BinfmtMiscEntry *bme, char *buf)
{
int ret;

/* :name:type:offset:magic/extension:mask:interpreter:flags */
if ((!bme->magic && !bme->extension) || !bme->interpreter) {
pr_perror("binfmt_misc: bad dump");
ret = -1;
} else if (bme->magic) {
ret = make_bfmtm_magic_str(buf, bme);
} else if (bme->extension) {
/* :name:E::extension::interpreter:flags */
ret = snprintf(buf, BINFMT_MISC_STR, ":%s:E::%s::%s:%s",
bme->name, bme->extension, bme->interpreter,
bme->flags ? : "\0");
}

if (ret > 0) {
pr_debug("binfmt_misc_pattern=%s\n", buf);
ret = write_binfmt_misc_entry(mi->mountpoint, buf, bme);
}

return ret;
}

static int binfmt_misc_restore(struct mount_info *mi)
{
struct cr_img *img;
Expand All @@ -1516,23 +1541,7 @@ static int binfmt_misc_restore(struct mount_info *mi)
if (ret <= 0)
break;

/* :name:type:offset:magic/extension:mask:interpreter:flags */
if ((!bme->magic && !bme->extension) || !bme->interpreter) {
pr_perror("binfmt_misc: bad dump");
ret = -1;
} else if (bme->magic) {
ret = make_bfmtm_magic_str(buf, bme);
} else if (bme->extension) {
/* :name:E::extension::interpreter:flags */
ret = snprintf(buf, BINFMT_MISC_STR, ":%s:E::%s::%s:%s",
bme->name, bme->extension, bme->interpreter,
bme->flags ? : "\0");
}

if (ret > 0) {
pr_debug("binfmt_misc_pattern=%s\n", buf);
ret = restore_binfmt_misc_entry(mi->mountpoint, buf, bme);
}
ret = binfmt_misc_restore_bme(mi, bme, buf);

binfmt_misc_entry__free_unpacked(bme, NULL);
}
Expand Down

0 comments on commit 398e7d3

Please sign in to comment.