[CRIU] [crtools-bot for Cyrill Gorcunov ] dump: Make sure error code is returned on pr_panic

Cyrill Gorcunov gorcunov at openvz.org
Wed Feb 8 07:31:34 EST 2012


The commit is pushed to "master" and will appear on git://github.com/cyrillos/crtools.git
------>
commit 0998335d9480d861fa3684c66255abff8144141c
Author: Cyrill Gorcunov <gorcunov at openvz.org>
Date:   Wed Feb 8 14:11:54 2012 +0400

    dump: Make sure error code is returned on pr_panic
    
    In case of critical error is happened during checkpoint
    procedure, the program should exit immediately.
    
    Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
    Acked-by: Pavel Emelyanov <xemul at parallels.com>
---
 cr-dump.c          |   23 ++++++++++++-----------
 parasite-syscall.c |   24 ++++++++++++++++--------
 2 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index acee6ee..ce101b1 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1035,6 +1035,7 @@ static int finalize_core(pid_t pid, struct list_head *vma_area_list, struct cr_f
 	unsigned long num, num_anon;
 	struct vma_area *vma_area;
 	struct vma_entry ve;
+	ssize_t bytes;
 	int ret = -1;
 	u64 va;
 
@@ -1056,8 +1057,8 @@ static int finalize_core(pid_t pid, struct list_head *vma_area_list, struct cr_f
 	/* All VMAs first */
 
 	list_for_each_entry(vma_area, vma_area_list, list) {
-		ret = write(fd_core, &vma_area->vma, sizeof(vma_area->vma));
-		if (ret != sizeof(vma_area->vma)) {
+		bytes = write(fd_core, &vma_area->vma, sizeof(vma_area->vma));
+		if (bytes != sizeof(vma_area->vma)) {
 			pr_perror("\nUnable to write vma entry (%li written)", num);
 			goto err;
 		}
@@ -1076,10 +1077,10 @@ static int finalize_core(pid_t pid, struct list_head *vma_area_list, struct cr_f
 
 	pr_info("Appending pages ... ");
 	while (1) {
-		ret = read(fd_pages, &va, sizeof(va));
-		if (!ret)
+		bytes = read(fd_pages, &va, sizeof(va));
+		if (!bytes)
 			break;
-		if (ret != sizeof(va)) {
+		if (bytes != sizeof(va)) {
 			pr_perror("\nUnable to read VA of page (%li written)", num);
 			goto err;
 		}
@@ -1110,9 +1111,9 @@ static int finalize_core(pid_t pid, struct list_head *vma_area_list, struct cr_f
 
 		if (vma_area_is(vma_area, VMA_ANON_PRIVATE) ||
 		    vma_area_is(vma_area, VMA_FILE_PRIVATE)) {
-			ret  = write(fd_core, &va, sizeof(va));
-			ret += sendfile(fd_core, fd_pages, NULL, PAGE_SIZE);
-			if (ret != sizeof(va) + PAGE_SIZE) {
+			bytes  = write(fd_core, &va, sizeof(va));
+			bytes += sendfile(fd_core, fd_pages, NULL, PAGE_SIZE);
+			if (bytes != sizeof(va) + PAGE_SIZE) {
 				pr_perror("\nUnable to write VMA_FILE_PRIVATE|VMA_ANON_PRIVATE "
 					  "page (%li, %li written)",
 					  num, num_anon);
@@ -1120,9 +1121,9 @@ static int finalize_core(pid_t pid, struct list_head *vma_area_list, struct cr_f
 			}
 			num++;
 		} else if (vma_area_is(vma_area, VMA_ANON_SHARED)) {
-			ret  = write(fd_pages_shmem, &va, sizeof(va));
-			ret += sendfile(fd_pages_shmem, fd_pages, NULL, PAGE_SIZE);
-			if (ret != sizeof(va) + PAGE_SIZE) {
+			bytes  = write(fd_pages_shmem, &va, sizeof(va));
+			bytes += sendfile(fd_pages_shmem, fd_pages, NULL, PAGE_SIZE);
+			if (bytes != sizeof(va) + PAGE_SIZE) {
 				pr_perror("\nUnable to write VMA_ANON_SHARED "
 					  "page (%li, %li written)",
 					  num, num_anon);
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 62affd4..4065d4d 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -122,8 +122,10 @@ unsigned long brk_seized(pid_t pid, unsigned long addr)
 	else
 		ret = -1UL;
 
-	if (ptrace(PTRACE_SETREGS, pid, NULL, &regs_orig))
+	if (ptrace(PTRACE_SETREGS, pid, NULL, &regs_orig)) {
 		pr_panic("Can't restore registers (pid: %d)\n", pid);
+		ret = -1UL;
+	}
 err:
 	return ret;
 }
@@ -220,12 +222,16 @@ retry_signal:
 	*result = regs;
 
 err_restore_full:
-	if (ptrace(PTRACE_SETREGS, pid, NULL, &regs_orig))
+	if (ptrace(PTRACE_SETREGS, pid, NULL, &regs_orig)) {
 		pr_panic("Can't restore registers (pid: %d)\n", pid);
+		ret = -1;
+	}
 
 err_restore:
-	if (ptrace_poke_area(pid, (void *)saved, (void *)start_ip, code_syscall_size))
+	if (ptrace_poke_area(pid, (void *)saved, (void *)start_ip, code_syscall_size)) {
 		pr_panic("Crap... Can't restore data (pid: %d)\n", pid);
+		ret = -1;
+	}
 err:
 	return ret;
 }
@@ -530,9 +536,10 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a
 		nrpages_dumped += parasite_dumppages.nrpages_dumped;
 	}
 
-	ret = 0;
-
-	jerr(ptrace(PTRACE_GETREGS, (long)ctl->pid, NULL, &regs_orig), err_restore);
+	if (ptrace(PTRACE_GETREGS, (long)ctl->pid, NULL, &regs_orig)) {
+		pr_err("Can't get registers (pid: %d)\n", ctl->pid);
+		goto err_restore;
+	}
 
 	/* Finally close the descriptor the parasite has opened */
 	if (parasite_dumppages.fd != -1UL) {
@@ -544,7 +551,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a
 
 	if (ptrace(PTRACE_SETREGS, (long)ctl->pid, NULL, &regs_orig)) {
 		pr_panic("Can't restore registers (pid: %d)\n", ctl->pid);
-		ret = -1;
+		goto err_restore;
 	}
 
 	/*
@@ -559,6 +566,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a
 
 	pr_info("\n");
 	pr_info("Summary: %16li pages dumped\n", nrpages_dumped);
+	ret = 0;
 
 err_restore:
 	fchmod(cr_fdset->fds[CR_FD_PAGES], CR_FD_PERM);
@@ -601,8 +609,8 @@ int parasite_cure_seized(struct parasite_ctl *ctl, struct list_head *vma_area_li
 		pr_err("munmap_seized failed (pid: %d)\n", ctl->pid);
 
 	if (ptrace(PTRACE_SETREGS, ctl->pid, NULL, &regs_orig)) {
-		ret = -1;
 		pr_panic("PTRACE_SETREGS failed (pid: %d)\n", ctl->pid);
+		ret = -1;
 	}
 
 	free(ctl);


More information about the CRIU mailing list