From ba68d61f54bb105c42e186ad5c6f30d7acd8eb4d Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Mon, 20 Jul 2015 12:40:16 +0300 Subject: [PATCH] files: Adjust file position for /dev/kmsg The kernel doesnt allow to call lseek on /dev/kmsg if it has been opened with O_WRONLY mode so our restore procedure fails. Thus if we meet a file which fits the condition above -- set it's position to predefined value which tells criu to not call lseek on restore. Signed-off-by: Cyrill Gorcunov Signed-off-by: Pavel Emelyanov --- files.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/files.c b/files.c index 3e69be731..071fa69c4 100644 --- a/files.c +++ b/files.c @@ -271,6 +271,29 @@ static const struct fdtype_ops *get_misc_dev_ops(int minor) return NULL; } +static const struct fdtype_ops *get_mem_dev_ops(struct fd_parms *p, int minor) +{ + const struct fdtype_ops *ops = NULL; + + switch (minor) { + case 11: + /* + * If /dev/kmsg is opened in write-only mode the file position + * should not be set up upon restore, kernel doesn't allow that. + */ + if ((p->flags & O_ACCMODE) == O_WRONLY && p->pos == 0) + p->pos = -1ULL; + /* + * Fallthrough. + */ + default: + ops = ®file_dump_ops; + break; + }; + + return ops; +} + static int dump_chrdev(struct fd_parms *p, int lfd, struct cr_img *img) { int maj = major(p->stat.st_rdev); @@ -278,7 +301,7 @@ static int dump_chrdev(struct fd_parms *p, int lfd, struct cr_img *img) switch (maj) { case MEM_MAJOR: - ops = ®file_dump_ops; + ops = get_mem_dev_ops(p, minor(p->stat.st_rdev)); break; case MISC_MAJOR: ops = get_misc_dev_ops(minor(p->stat.st_rdev));