From cf164e16e81c79ca68d1ac3a7bd86dc9cd46d114 Mon Sep 17 00:00:00 2001 From: Kirill Tkhai Date: Tue, 23 Aug 2016 19:16:39 +0300 Subject: [PATCH] mount: Move binfmt_misc entry restore code to subfunction Also rename restore_binfmt_misc_entry() to write_binfmt_misc_entry() v6: New Signed-off-by: Kirill Tkhai Signed-off-by: Pavel Emelyanov --- criu/mount.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/criu/mount.c b/criu/mount.c index 206a8e2e7..768e7394d 100644 --- a/criu/mount.c +++ b/criu/mount.c @@ -1413,7 +1413,7 @@ out: 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]; @@ -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; @@ -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); }