[CRIU] [PATCH 3/4] pr_perror(): print error at the end of line

Kir Kolyshkin kir at openvz.org
Mon Jan 30 12:18:39 EST 2012


This is a standard convention to print error message (i.e. strerror(errno))
at the end of line, like this:

	Cannot remove file: Permission denied

So pr_perror is fixed to follow this convention (using GNU extension
%m helps a lot here). Unfortunately, due to this we have to make
pr_perror() print a new line character, too, so we had to strip it
from the all pr_perror() invocations.

Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 cr-dump.c          |   46 ++++++++++++++++++------------------
 cr-restore.c       |   66 ++++++++++++++++++++++++++--------------------------
 cr-show.c          |    6 ++--
 crtools.c          |    8 +++---
 files.c            |   22 ++++++++--------
 include/util.h     |    7 ++---
 log.c              |    2 +-
 namespaces.c       |   14 +++++-----
 parasite-syscall.c |    2 +-
 proc_parse.c       |    8 +++---
 ptrace.c           |    4 +-
 sockets.c          |   30 +++++++++++-----------
 util.c             |    8 +++---
 13 files changed, 111 insertions(+), 112 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index dbae3d6..286ff01 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -104,7 +104,7 @@ static int dump_one_reg_file(int type, struct fd_parms *p, int lfd,
 	snprintf(fd_str, sizeof(fd_str), "/proc/self/fd/%d", lfd);
 	len = readlink(fd_str, big_buffer, sizeof(big_buffer) - 1);
 	if (len < 0) {
-		pr_perror("Can't readlink %s\n", fd_str);
+		pr_perror("Can't readlink %s", fd_str);
 		goto err;
 	}
 
@@ -151,7 +151,7 @@ static int dump_cwd(int pid_dir, struct cr_fdset *cr_fdset)
 
 	fd = open_proc(pid_dir, "cwd");
 	if (fd < 0) {
-		pr_perror("Failed to openat cwd\n");
+		pr_perror("Failed to openat cwd");
 		return -1;
 	}
 
@@ -172,7 +172,7 @@ static int dump_pipe_and_data(int lfd, struct pipe_entry *e,
 
 	pr_info("Dumping data from pipe %x\n", e->pipeid);
 	if (pipe(steal_pipe) < 0) {
-		pr_perror("Can't create pipe for stealing data\n");
+		pr_perror("Can't create pipe for stealing data");
 		goto err;
 	}
 
@@ -185,7 +185,7 @@ static int dump_pipe_and_data(int lfd, struct pipe_entry *e,
 	has_bytes = tee(lfd, steal_pipe[1], pipe_size, SPLICE_F_NONBLOCK);
 	if (has_bytes < 0) {
 		if (errno != EAGAIN) {
-			pr_perror("Can't pick pipe data\n");
+			pr_perror("Can't pick pipe data");
 			goto err_close;
 		} else
 			has_bytes = 0;
@@ -199,7 +199,7 @@ static int dump_pipe_and_data(int lfd, struct pipe_entry *e,
 		ret = splice(steal_pipe[0], NULL, fd_pipes,
 			     NULL, has_bytes, 0);
 		if (ret < 0) {
-			pr_perror("Can't push pipe data\n");
+			pr_perror("Can't push pipe data");
 			goto err_close;
 		}
 	}
@@ -254,12 +254,12 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, int lfd,
 		if (err != 1)
 			return err;
 
-		pr_perror("Failed to open %d/%d\n", pid_fd_dir, p->fd_name);
+		pr_perror("Failed to open %d/%d", pid_fd_dir, p->fd_name);
 		return -1;
 	}
 
 	if (fstat(lfd, &st_buf) < 0) {
-		pr_perror("Can't get stat on %d\n", p->fd_name);
+		pr_perror("Can't get stat on %d", p->fd_name);
 		goto out_close;
 	}
 
@@ -283,7 +283,7 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, int lfd,
 
 	if (S_ISFIFO(st_buf.st_mode)) {
 		if (fstatfs(lfd, &stfs_buf) < 0) {
-			pr_perror("Can't fstatfs on %d\n", p->fd_name);
+			pr_perror("Can't fstatfs on %d", p->fd_name);
 			return -1;
 		}
 
@@ -306,7 +306,7 @@ static int read_fd_params(pid_t pid, int pid_dir, char *fd, struct fd_parms *p)
 
 	file = fopen_proc(pid_dir, "fdinfo/%s", fd);
 	if (!file) {
-		pr_perror("Can't open %d's %s fdinfo\n", pid, fd);
+		pr_perror("Can't open %d's %s fdinfo", pid, fd);
 		return -1;
 	}
 
@@ -337,13 +337,13 @@ static int dump_task_files(pid_t pid, int pid_dir, struct cr_fdset *cr_fdset)
 	pr_info("----------------------------------------\n");
 
 	if (dump_cwd(pid_dir, cr_fdset)) {
-		pr_perror("Can't dump %d's cwd %s\n", pid);
+		pr_perror("Can't dump %d's cwd %s", pid);
 		return -1;
 	}
 
 	fd_dir = opendir_proc(pid_dir, "fd");
 	if (!fd_dir) {
-		pr_perror("Can't open %d's fd\n", pid);
+		pr_perror("Can't open %d's fd", pid);
 		return -1;
 	}
 
@@ -487,7 +487,7 @@ static int get_task_sigmask(pid_t pid, int pid_dir, u64 *task_sigset)
 	 */
 	file = fopen_proc(pid_dir, "status");
 	if (!file) {
-		pr_perror("Can't open %d status\n", pid);
+		pr_perror("Can't open %d status", pid);
 		goto err;
 	}
 
@@ -511,7 +511,7 @@ static int get_task_auxv(pid_t pid, int pid_dir, struct core_entry *core)
 	int ret, i;
 
 	if (fd < 0) {
-		pr_perror("Can't open %d's auxv\n", pid);
+		pr_perror("Can't open %d's auxv", pid);
 		return -1;
 	}
 
@@ -522,7 +522,7 @@ static int get_task_auxv(pid_t pid, int pid_dir, struct core_entry *core)
 			break;
 		else if (ret != sizeof(core->tc.mm_saved_auxv[0])) {
 			ret = -1;
-			pr_perror("Error readind %d's auxv[%d]\n",
+			pr_perror("Error readind %d's auxv[%d]",
 				  pid, i);
 			goto err;
 		}
@@ -542,7 +542,7 @@ static int get_task_personality(pid_t pid, int pid_dir, u32 *personality)
 
 	file = fopen_proc(pid_dir, "personality");
 	if (!file) {
-		pr_perror("Can't open %d personality\n", pid);
+		pr_perror("Can't open %d personality", pid);
 		goto err;
 	}
 
@@ -733,7 +733,7 @@ static int parse_threads(pid_t pid, int pid_dir, struct pstree_item *item)
 
 	dir = opendir_proc(pid_dir, "task");
 	if (!dir) {
-		pr_perror("Can't open %d/task\n", pid);
+		pr_perror("Can't open %d/task", pid);
 		return -1;
 	}
 
@@ -773,7 +773,7 @@ static int parse_children(pid_t pid, int pid_dir, struct pstree_item *item)
 
 		file = fopen_proc(pid_dir, "task/%d/children", item->threads[i]);
 		if (!file) {
-			pr_perror("Can't open %d children %d\n",
+			pr_perror("Can't open %d children %d",
 				  pid, item->threads[i]);
 			goto err;
 		}
@@ -983,7 +983,7 @@ static int finalize_core(pid_t pid, struct list_head *vma_area_list, struct cr_f
 	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)) {
-			pr_perror("\nUnable to write vma entry (%li written)\n", num);
+			pr_perror("\nUnable to write vma entry (%li written)", num);
 			goto err;
 		}
 		num++;
@@ -1005,7 +1005,7 @@ static int finalize_core(pid_t pid, struct list_head *vma_area_list, struct cr_f
 		if (!ret)
 			break;
 		if (ret != sizeof(va)) {
-			pr_perror("\nUnable to read VA of page (%li written)\n", num);
+			pr_perror("\nUnable to read VA of page (%li written)", num);
 			goto err;
 		}
 
@@ -1039,7 +1039,7 @@ static int finalize_core(pid_t pid, struct list_head *vma_area_list, struct cr_f
 			ret += sendfile(fd_core, fd_pages, NULL, PAGE_SIZE);
 			if (ret != sizeof(va) + PAGE_SIZE) {
 				pr_perror("\nUnable to write VMA_FILE_PRIVATE|VMA_ANON_PRIVATE "
-					  "page (%li, %li written)\n",
+					  "page (%li, %li written)",
 					  num, num_anon);
 				goto err;
 			}
@@ -1049,7 +1049,7 @@ static int finalize_core(pid_t pid, struct list_head *vma_area_list, struct cr_f
 			ret += sendfile(fd_pages_shmem, fd_pages, NULL, PAGE_SIZE);
 			if (ret != sizeof(va) + PAGE_SIZE) {
 				pr_perror("\nUnable to write VMA_ANON_SHARED "
-					  "page (%li, %li written)\n",
+					  "page (%li, %li written)",
 					  num, num_anon);
 				goto err;
 			}
@@ -1069,7 +1069,7 @@ err:
 	return ret;
 
 err_strno:
-	pr_perror("Error catched\n");
+	pr_perror("Error catched");
 	goto err;
 }
 
@@ -1193,7 +1193,7 @@ static int dump_one_task(struct pstree_item *item, struct cr_fdset *cr_fdset)
 
 	pid_dir = open_pid_proc(pid);
 	if (pid_dir < 0) {
-		pr_perror("Can't open %d proc dir\n", pid);
+		pr_perror("Can't open %d proc dir", pid);
 		goto err;
 	}
 
diff --git a/cr-restore.c b/cr-restore.c
index 4c94936..5874892 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -160,7 +160,7 @@ static int shmem_wait_and_open(int pid, struct shmem_info *si)
 	if (ret >= 0)
 		return ret;
 	else if (ret < 0)
-		pr_perror("     %d: Can't stat shmem at %s\n",
+		pr_perror("     %d: Can't stat shmem at %s",
 			  si->pid, path);
 	return ret;
 }
@@ -351,14 +351,14 @@ static int shmem_remap(void *old_addr, void *new_addr, unsigned long size)
 
 	fd = open(path, O_RDWR);
 	if (fd < 0) {
-		pr_perror("open(%s) failed\n", path);
+		pr_perror("open(%s) failed", path);
 		return -1;
 	}
 
 	ret = mmap(new_addr, size, PROT_READ | PROT_WRITE,
 		   MAP_SHARED | MAP_FIXED, fd, 0);
 	if (ret != new_addr) {
-		pr_perror("mmap failed\n");
+		pr_perror("mmap failed");
 		return -1;
 	}
 
@@ -374,7 +374,7 @@ static int prepare_shared(int ps_fd)
 
 	shmems = mmap(NULL, SHMEMS_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0);
 	if (shmems == MAP_FAILED) {
-		pr_perror("Can't map shmem\n");
+		pr_perror("Can't map shmem");
 		return -1;
 	}
 
@@ -382,7 +382,7 @@ static int prepare_shared(int ps_fd)
 
 	task_entries = mmap(NULL, TASK_ENTRIES_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0);
 	if (task_entries == MAP_FAILED) {
-		pr_perror("Can't map shmem\n");
+		pr_perror("Can't map shmem");
 		return -1;
 	}
 	task_entries->nr = 0;
@@ -390,7 +390,7 @@ static int prepare_shared(int ps_fd)
 
 	pipes = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0);
 	if (pipes == MAP_FAILED) {
-		pr_perror("Can't map pipes\n");
+		pr_perror("Can't map pipes");
 		return -1;
 	}
 
@@ -544,7 +544,7 @@ static int try_fixup_shared_map(int pid, struct vma_entry *vi, int fd)
 		pr_info("%d: Fixing %lx vma to %lx/%d shmem -> %d\n",
 			pid, vi->start, si->shmid, si->pid, sh_fd);
 		if (sh_fd < 0) {
-			pr_perror("%d: Can't open shmem\n", pid);
+			pr_perror("%d: Can't open shmem", pid);
 			return -1;
 		}
 
@@ -553,7 +553,7 @@ static int try_fixup_shared_map(int pid, struct vma_entry *vi, int fd)
 		pr_info("%d: Fixed %lx vma %lx/%d shmem -> %d\n",
 			pid, vi->start, si->shmid, si->pid, sh_fd);
 		if (write(fd, vi, sizeof(*vi)) != sizeof(*vi)) {
-			pr_perror("%d: Can't write img\n", pid);
+			pr_perror("%d: Can't write img", pid);
 			return -1;
 		}
 	}
@@ -573,7 +573,7 @@ static int fixup_vma_fds(int pid, int fd)
 
 		ret = read(fd, &vi, sizeof(vi));
 		if (ret < 0) {
-			pr_perror("%d: Can't read vma_entry\n", pid);
+			pr_perror("%d: Can't read vma_entry", pid);
 		} else if (ret != sizeof(vi)) {
 			pr_err("%d: Incomplete vma_entry (%d != %d)\n",
 			       pid, ret, sizeof(vi));
@@ -655,7 +655,7 @@ static int fixup_pages_data(int pid, int fd)
 			break;
 
 		if (ret < 0 || ret != sizeof(va)) {
-			pr_perror("%d: Can't read virtual address\n", pid);
+			pr_perror("%d: Can't read virtual address", pid);
 			return -1;
 		}
 
@@ -706,7 +706,7 @@ static int prepare_and_sigreturn(int pid)
 		return -1;
 
 	if (fstat(fd, &buf)) {
-		pr_perror("%d: Can't stat\n", pid);
+		pr_perror("%d: Can't stat", pid);
 		return -1;
 	}
 
@@ -715,19 +715,19 @@ static int prepare_and_sigreturn(int pid)
 
 	fd_new = open(path, O_RDWR | O_CREAT | O_TRUNC, CR_FD_PERM);
 	if (fd_new < 0) {
-		pr_perror("%d: Can't open new image\n", pid);
+		pr_perror("%d: Can't open new image", pid);
 		return -1;
 	}
 
 	pr_info("%d: Preparing restore image %s (%li bytes)\n", pid, path, buf.st_size);
 	if (sendfile(fd_new, fd, NULL, buf.st_size) != buf.st_size) {
-		pr_perror("%d: sendfile failed\n", pid);
+		pr_perror("%d: sendfile failed", pid);
 		return -1;
 	}
 	close(fd);
 
 	if (fstat(fd_new, &buf)) {
-		pr_perror("%d: Can't stat\n", pid);
+		pr_perror("%d: Can't stat", pid);
 		return -1;
 	}
 
@@ -784,7 +784,7 @@ static int restore_pipe_data(struct pipe_entry *e, int wfd, int pipes_fd)
 	while (size != e->bytes) {
 		ret = splice(pipes_fd, NULL, wfd, NULL, e->bytes, 0);
 		if (ret < 0) {
-			pr_perror("\t%x: Error splicing data\n", e->pipeid);
+			pr_perror("\t%x: Error splicing data", e->pipeid);
 			return -1;
 		}
 		if (ret == 0) {
@@ -807,7 +807,7 @@ static int create_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int
 	pr_info("\t%d: Creating pipe %x%s\n", pid, e->pipeid, pipe_is_rw(pi) ? "(rw)" : "");
 
 	if (pipe(pfd) < 0) {
-		pr_perror("%d: Can't create pipe\n", pid);
+		pr_perror("%d: Can't create pipe", pid);
 		return -1;
 	}
 
@@ -887,7 +887,7 @@ static int attach_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int
 			tmp = dup2(tmp, e->fd);
 
 		if (tmp < 0) {
-			pr_perror("%d: Can't duplicate %d->%d\n",
+			pr_perror("%d: Can't duplicate %d->%d",
 					pid, tmp, e->fd);
 			return -1;
 		}
@@ -901,7 +901,7 @@ static int attach_pipe(int pid, struct pipe_entry *e, struct pipe_info *pi, int
 
 	fd = open(path, e->flags);
 	if (fd < 0) {
-		pr_perror("%d: Can't attach pipe\n", pid);
+		pr_perror("%d: Can't attach pipe", pid);
 		return -1;
 	}
 
@@ -1155,7 +1155,7 @@ static int restore_one_zobie(int pid, int exit_code)
 		}
 
 		if (kill(pid, signr) < 0)
-			pr_perror("Can't kill myself, will just exit\n");
+			pr_perror("Can't kill myself, will just exit");
 
 		exit_code = 0;
 	}
@@ -1235,7 +1235,7 @@ static inline int fork_with_pid(int pid, unsigned long ns_clone_flags)
 	stack = mmap(NULL, STACK_SIZE, PROT_WRITE | PROT_READ,
 			MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS, -1, 0);
 	if (stack == MAP_FAILED) {
-		pr_perror("Failed to map stack for kid\n");
+		pr_perror("Failed to map stack for kid");
 		goto err;
 	}
 
@@ -1244,12 +1244,12 @@ static inline int fork_with_pid(int pid, unsigned long ns_clone_flags)
 	ca.clone_flags = ns_clone_flags;
 	ca.fd = open(LAST_PID_PATH, O_RDWR);
 	if (ca.fd < 0) {
-		pr_perror("%d: Can't open %s\n", pid, LAST_PID_PATH);
+		pr_perror("%d: Can't open %s", pid, LAST_PID_PATH);
 		goto err;
 	}
 
 	if (flock(ca.fd, LOCK_EX)) {
-		pr_perror("%d: Can't lock %s\n", pid, LAST_PID_PATH);
+		pr_perror("%d: Can't lock %s", pid, LAST_PID_PATH);
 		goto err;
 	}
 
@@ -1260,11 +1260,11 @@ static inline int fork_with_pid(int pid, unsigned long ns_clone_flags)
 			ns_clone_flags | SIGCHLD, &ca);
 
 	if (ret < 0)
-		pr_perror("Can't fork for %d\n", pid);
+		pr_perror("Can't fork for %d", pid);
 
 err_unlock:
 	if (flock(ca.fd, LOCK_UN))
-		pr_perror("%d: Can't unlock %s\n", pid, LAST_PID_PATH);
+		pr_perror("%d: Can't unlock %s", pid, LAST_PID_PATH);
 
 err:
 	if (stack != MAP_FAILED)
@@ -1320,7 +1320,7 @@ static int restore_task_with_children(void *_arg)
 	sigdelset(&blockmask, SIGCHLD);
 	ret = sigprocmask(SIG_BLOCK, &blockmask, NULL);
 	if (ret) {
-		pr_perror("%d: Can't block signals\n", pid);
+		pr_perror("%d: Can't block signals", pid);
 		exit(1);
 	}
 
@@ -1328,7 +1328,7 @@ static int restore_task_with_children(void *_arg)
 
 	fd = open_image_ro_nocheck(FMT_FNAME_PSTREE, pstree_pid);
 	if (fd < 0) {
-		pr_perror("%d: Can't reopen pstree image\n", pid);
+		pr_perror("%d: Can't reopen pstree image", pid);
 		exit(1);
 	}
 
@@ -1352,7 +1352,7 @@ static int restore_task_with_children(void *_arg)
 
 		ret = read(fd, pids, i);
 		if (ret != i) {
-			pr_perror("%d: Can't read children pids\n", pid);
+			pr_perror("%d: Can't read children pids", pid);
 			exit(1);
 		}
 
@@ -1379,7 +1379,7 @@ static int restore_root_task(int fd, struct cr_options *opts)
 
 	ret = read(fd, &e, sizeof(e));
 	if (ret != sizeof(e)) {
-		pr_perror("Can't read root pstree entry\n");
+		pr_perror("Can't read root pstree entry");
 		return -1;
 	}
 
@@ -1493,7 +1493,7 @@ static long restorer_get_vma_hint(pid_t pid, struct list_head *self_vma_list, lo
 	while (1) {
 		ret = read(fd, &vma, sizeof(vma));
 		if (ret && ret != sizeof(vma)) {
-			pr_perror("Can't read vma entry from core-%d\n", pid);
+			pr_perror("Can't read vma entry from core-%d", pid);
 			goto err_or_found;
 		}
 
@@ -1666,7 +1666,7 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
 
 	fd_core = open_image_ro_nocheck(FMT_FNAME_CORE_OUT, pid);
 	if (fd_core < 0)
-		pr_perror("Can't open core-out-%d\n", pid);
+		pr_perror("Can't open core-out-%d", pid);
 
 	if (get_image_path(self_vmas_path, sizeof(self_vmas_path),
 			   FMT_FNAME_VMAS, pid))
@@ -1682,7 +1682,7 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
 	// unlink(self_vmas_path);
 
 	if (fd_self_vmas < 0) {
-		pr_perror("Can't open %s\n", self_vmas_path);
+		pr_perror("Can't open %s", self_vmas_path);
 		goto err;
 	}
 
@@ -1690,7 +1690,7 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
 	list_for_each_entry(vma_area, &self_vma_list, list) {
 		ret = write(fd_self_vmas, &vma_area->vma, sizeof(vma_area->vma));
 		if (ret != sizeof(vma_area->vma)) {
-			pr_perror("\nUnable to write vma entry (%li written)\n", num);
+			pr_perror("\nUnable to write vma entry (%li written)", num);
 			goto err;
 		}
 		num++;
@@ -1710,7 +1710,7 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
 	while (1) {
 		ret = read_img_eof(fd_pstree, &pstree_entry);
 		if (ret <= 0) {
-			pr_perror("Pid %d not found in process tree\n", pid);
+			pr_perror("Pid %d not found in process tree", pid);
 			goto err;
 		}
 
diff --git a/cr-show.c b/cr-show.c
index 267380a..74ecbf3 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -89,7 +89,7 @@ static void show_files(int fd_files)
 		if (e.len) {
 			int ret = read(fd_files, local_buf, e.len);
 			if (ret != e.len) {
-				pr_perror("Can't read %d bytes\n", e.len);
+				pr_perror("Can't read %d bytes", e.len);
 				goto out;
 			}
 			local_buf[e.len] = 0;
@@ -429,7 +429,7 @@ static void show_core(int fd_core, bool show_content)
 	bool is_thread;
 
 	if (fstat(fd_core, &stat)) {
-		pr_perror("Can't get stat on core file\n");
+		pr_perror("Can't get stat on core file");
 		goto out;
 	}
 
@@ -469,7 +469,7 @@ static int cr_parse_file(struct cr_options *opts)
 
 	fd = open(opts->show_dump_file, O_RDONLY);
 	if (fd < 0) {
-		pr_perror("Can't open %s\n", opts->show_dump_file);
+		pr_perror("Can't open %s", opts->show_dump_file);
 		goto err;
 	}
 
diff --git a/crtools.c b/crtools.c
index 926d26b..560c609 100644
--- a/crtools.c
+++ b/crtools.c
@@ -148,13 +148,13 @@ struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask, struct cr_fdset
 
 		ret = unlink(path);
 		if (ret && errno != ENOENT) {
-			pr_perror("Unable to unlink %s\n", path);
+			pr_perror("Unable to unlink %s", path);
 			goto err;
 		}
 
 		ret = open(path, O_RDWR | O_CREAT | O_EXCL, CR_FD_PERM);
 		if (ret < 0) {
-			pr_perror("Unable to open %s\n", path);
+			pr_perror("Unable to open %s", path);
 			goto err;
 		}
 
@@ -191,7 +191,7 @@ struct cr_fdset *prep_cr_fdset_for_restore(int pid, unsigned long use_mask)
 
 		ret = open(path, O_RDWR, CR_FD_PERM);
 		if (ret < 0) {
-			pr_perror("Unable to open %s\n", path);
+			pr_perror("Unable to open %s", path);
 			goto err;
 		}
 
@@ -303,7 +303,7 @@ int main(int argc, char *argv[])
 	}
 
 	if (!getcwd(image_dir, sizeof(image_dir))) {
-		pr_perror("can't get currect directory\n");
+		pr_perror("can't get currect directory");
 		return -1;
 	}
 
diff --git a/files.c b/files.c
index 483b7cc..626ab79 100644
--- a/files.c
+++ b/files.c
@@ -90,13 +90,13 @@ int prepare_fdinfo_global()
 {
 	fdinfo_descs = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0);
 	if (fdinfo_descs == MAP_FAILED) {
-		pr_perror("Can't map fdinfo_descs\n");
+		pr_perror("Can't map fdinfo_descs");
 		return -1;
 	}
 
 	fdinfo_list = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0);
 	if (fdinfo_list == MAP_FAILED) {
-		pr_perror("Can't map fdinfo_list\n");
+		pr_perror("Can't map fdinfo_list");
 		return -1;
 	}
 	return 0;
@@ -177,7 +177,7 @@ int prepare_fd_pid(int pid)
 		if (ret == 0)
 			break;
 		if (ret != sizeof(e)) {
-			pr_perror("%d: Read fdinfo failed %d (expected %li)\n",
+			pr_perror("%d: Read fdinfo failed %d (expected %li)",
 				  pid, ret, sizeof(e));
 			return -1;
 		}
@@ -205,7 +205,7 @@ static int open_fe_fd(struct fdinfo_entry *fe, int fd)
 
 	tmp = open(path, fe->flags);
 	if (tmp < 0) {
-		pr_perror("Can't open file %s\n", path);
+		pr_perror("Can't open file %s", path);
 		return -1;
 	}
 
@@ -225,7 +225,7 @@ static int restore_cwd(struct fdinfo_entry *fe, int fd)
 	pr_info("Restore CWD %s\n", path);
 	ret = chdir(path);
 	if (ret < 0) {
-		pr_perror("Can't change dir %s\n", path);
+		pr_perror("Can't change dir %s", path);
 		return -1;
 	}
 
@@ -279,7 +279,7 @@ static int open_transport_fd(int pid, struct fdinfo_entry *fe,
 	}
 	ret = bind(sock, &saddr, sun_len);
 	if (ret < 0) {
-		pr_perror("Can't bind unix socket %s\n", saddr.sun_path + 1);
+		pr_perror("Can't bind unix socket %s", saddr.sun_path + 1);
 		return -1;
 	}
 
@@ -406,7 +406,7 @@ static int recv_fd(int sock)
 
 	cmsg = CMSG_FIRSTHDR(&msg);
 	if (!cmsg->cmsg_type == SCM_RIGHTS) {
-		pr_perror("got control message of unknown type %d\n",
+		pr_perror("got control message of unknown type %d",
 							  cmsg->cmsg_type);
 		return -1;
 	}
@@ -422,7 +422,7 @@ static int receive_fd(int pid, struct fdinfo_entry *fe, struct fdinfo_desc *fi)
 		if (fi->addr != fe->addr) {
 			tmp = dup2(fi->addr, fe->addr);
 			if (tmp < 0) {
-				pr_perror("Can't duplicate fd %d %d\n",
+				pr_perror("Can't duplicate fd %d %d",
 						fi->addr, fe->addr);
 				return -1;
 			}
@@ -533,7 +533,7 @@ int prepare_fds(int pid)
 
 	fdinfo_fd = open_image_ro(CR_FD_FDINFO, pid);
 	if (fdinfo_fd < 0) {
-		pr_perror("%d: Can't open pipes img\n", pid);
+		pr_perror("%d: Can't open pipes img", pid);
 		return -1;
 	}
 
@@ -548,7 +548,7 @@ int prepare_fds(int pid)
 				break;
 
 			if (ret != sizeof(fe)) {
-				pr_perror("%d: Bad fdinfo entry\n", pid);
+				pr_perror("%d: Bad fdinfo entry", pid);
 				goto err;
 			}
 
@@ -613,6 +613,6 @@ int try_fixup_file_map(int pid, struct vma_entry *vma_entry, int fd)
 
 	return 0;
 err:
-	pr_perror("%d: Can't fixup vma\n", pid);
+	pr_perror("%d: Can't fixup vma", pid);
 	return -1;
 }
diff --git a/include/util.h b/include/util.h
index efe1b03..b44165e 100644
--- a/include/util.h
+++ b/include/util.h
@@ -83,8 +83,7 @@ extern void printk(const char *format, ...);
 
 #define pr_perror(fmt, ...)					\
 	do {							\
-		pr_err("%s: " fmt,  strerror(errno),		\
-			##__VA_ARGS__);				\
+		pr_err(fmt ": %m\n", ##__VA_ARGS__);		\
 	} while (0)
 
 #ifndef BUG_ON_HANDLER
@@ -131,7 +130,7 @@ static inline int write_img_buf(int fd, void *ptr, int size)
 		return 0;
 
 	if (ret < 0)
-		pr_perror("Can't write img file\n");
+		pr_perror("Can't write img file");
 	else
 		pr_err("Img trimmed %d/%d\n", ret, size);
 	return -1;
@@ -156,7 +155,7 @@ static inline int read_img_buf_eof(int fd, void *ptr, int size)
 		return 0;
 
 	if (ret < 0)
-		pr_perror("Can't read img file\n");
+		pr_perror("Can't read img file");
 	else
 		pr_err("Img trimmed %d/%d\n", ret, size);
 	return -1;
diff --git a/log.c b/log.c
index a080cb0..8d1929a 100644
--- a/log.c
+++ b/log.c
@@ -40,7 +40,7 @@ int init_log(const char *name)
 	if (name) {
 		fd = open(name, O_CREAT | O_WRONLY);
 		if (fd == -1) {
-			pr_perror("Can't create log file %s\n", name);
+			pr_perror("Can't create log file %s", name);
 			return -1;
 		}
 	}
diff --git a/namespaces.c b/namespaces.c
index 6370bc2..3792bb4 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -15,13 +15,13 @@ static int switch_ns(int pid, int type, char *ns)
 	snprintf(buf, sizeof(buf), "/proc/%d/ns/%s", pid, ns);
 	nsfd = open(buf, O_RDONLY);
 	if (nsfd < 0) {
-		pr_perror("Can't open ipcns file\n");
+		pr_perror("Can't open ipcns file");
 		goto out;
 	}
 
 	ret = setns(nsfd, type);
 	if (ret < 0)
-		pr_perror("Can't setns %d/%s\n", pid, ns);
+		pr_perror("Can't setns %d/%s", pid, ns);
 
 	close(nsfd);
 out:
@@ -52,7 +52,7 @@ static int dump_uts_ns(int ns_pid, struct cr_fdset *fdset)
 
 	ret = uname(&ubuf);
 	if (ret < 0) {
-		pr_perror("Error calling uname\n");
+		pr_perror("Error calling uname");
 		return ret;
 	}
 
@@ -100,7 +100,7 @@ int dump_namespaces(int ns_pid)
 
 	pid = fork();
 	if (pid < 0) {
-		pr_perror("Can't fork ns dumper\n");
+		pr_perror("Can't fork ns dumper");
 		return -1;
 	}
 
@@ -111,7 +111,7 @@ int dump_namespaces(int ns_pid)
 
 	ret = waitpid(pid, &status, 0);
 	if (ret != pid) {
-		pr_perror("Can't wait ns dumper\n");
+		pr_perror("Can't wait ns dumper");
 		return -1;
 	}
 
@@ -147,7 +147,7 @@ static int prepare_uts_str(int fd, char *n)
 				"/proc/sys/kernel/%s", n);
 		fd = open(path, O_WRONLY);
 		if (fd < 0) {
-			pr_perror("Can't open %s\n", path);
+			pr_perror("Can't open %s", path);
 			return -1;
 		}
 
@@ -156,7 +156,7 @@ static int prepare_uts_str(int fd, char *n)
 		ret = write(fd, str, len);
 		close(fd);
 		if (ret != len) {
-			pr_perror("Can't write %s to %s\n",
+			pr_perror("Can't write %s to %s",
 					str, path);
 			return -1;
 		}
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 480e07e..6a3f797 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -349,7 +349,7 @@ static int parasite_prep_file(int type, struct parasite_dump_file_args *fa,
 		return -1;
 
 	if (fchmod(fdset->fds[type], CR_FD_PERM_DUMP)) {
-		pr_perror("Can't change permissions on %d file\n", type);
+		pr_perror("Can't change permissions on %d file", type);
 		return -1;
 	}
 
diff --git a/proc_parse.c b/proc_parse.c
index ebe1c90..85c4493 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -30,7 +30,7 @@ int parse_maps(pid_t pid, int pid_dir, struct list_head *vma_area_list, bool use
 
 	maps = fopen_proc(pid_dir, "maps");
 	if (!maps) {
-		pr_perror("Can't open %d's maps\n", pid);
+		pr_perror("Can't open %d's maps", pid);
 		goto err;
 	}
 
@@ -72,7 +72,7 @@ int parse_maps(pid_t pid, int pid_dir, struct list_head *vma_area_list, bool use
 			vma_area->vm_file_fd = openat(dirfd(map_files_dir), path, O_RDONLY);
 			if (vma_area->vm_file_fd < 0) {
 				if (errno != ENOENT) {
-					pr_perror("Failed opening %d's map %Lu\n", pid, start);
+					pr_perror("Failed opening %d's map %Lu", pid, start);
 					goto err;
 				}
 			}
@@ -115,7 +115,7 @@ int parse_maps(pid_t pid, int pid_dir, struct list_head *vma_area_list, bool use
 		if (vma_area->vm_file_fd >= 0) {
 
 			if (fstat(vma_area->vm_file_fd, &st_buf) < 0) {
-				pr_perror("Failed fstat on %d's map %Lu\n", pid, start);
+				pr_perror("Failed fstat on %d's map %Lu", pid, start);
 				goto err;
 			}
 			if (!S_ISREG(st_buf.st_mode)) {
@@ -296,7 +296,7 @@ int parse_pid_status(int pid_dir, struct proc_status_creds *cr)
 
 	f = fopen_proc(pid_dir, "status");
 	if (f == NULL) {
-		pr_perror("Can't open proc status\n");
+		pr_perror("Can't open proc status");
 		return -1;
 	}
 
diff --git a/ptrace.c b/ptrace.c
index b106ec2..1b3d583 100644
--- a/ptrace.c
+++ b/ptrace.c
@@ -39,13 +39,13 @@ int seize_task(pid_t pid)
 	ret = ptrace(PTRACE_SEIZE, pid, NULL,
 		       (void *)(unsigned long)PTRACE_SEIZE_DEVEL);
 	if (ret < 0) {
-		pr_perror("Can't seize task\n");
+		pr_perror("Can't seize task");
 		goto err;
 	}
 
 	ret = ptrace(PTRACE_INTERRUPT, pid, NULL, NULL);
 	if (ret < 0) {
-		pr_perror("Can't interrupt task\n");
+		pr_perror("Can't interrupt task");
 		goto err;
 	}
 
diff --git a/sockets.c b/sockets.c
index bd5e769..fd306ec 100644
--- a/sockets.c
+++ b/sockets.c
@@ -453,7 +453,7 @@ static int unix_collect_one(struct unix_diag_msg *m, struct rtattr **tb)
 
 			uv = RTA_DATA(tb[UNIX_DIAG_VFS]);
 			if (stat(name, &st)) {
-				pr_perror("Can't stat socket %d(%s)\n",
+				pr_perror("Can't stat socket %d(%s)",
 						m->udiag_ino, name);
 				goto err;
 			}
@@ -560,7 +560,7 @@ static int collect_sockets_nl(int nl, void *req, int size,
 	iov.iov_len	= size;
 
 	if (sendmsg(nl, &msg, 0) < 0) {
-		pr_perror("Can't send request message\n");
+		pr_perror("Can't send request message");
 		goto err;
 	}
 
@@ -581,7 +581,7 @@ static int collect_sockets_nl(int nl, void *req, int size,
 			if (errno == EINTR)
 				continue;
 			else {
-				pr_perror("Error receiving nl report\n");
+				pr_perror("Error receiving nl report");
 				goto err;
 			}
 		}
@@ -682,7 +682,7 @@ try_again:
 				attempts--;
 				goto try_again; /* FIXME - use avagin@'s waiters */
 			}
-			pr_perror("Can't restore connection (c)\n");
+			pr_perror("Can't restore connection (c)");
 			return -1;
 		}
 
@@ -727,7 +727,7 @@ static int run_accept_jobs(void)
 		unix_show_job("Run acc", aj->fd, -1);
 		fd = accept(aj->fd, NULL, NULL);
 		if (fd < 0) {
-			pr_perror("Can't restore connection (s)\n");
+			pr_perror("Can't restore connection (s)");
 			return -1;
 		}
 
@@ -784,7 +784,7 @@ static int run_connect_jobs_dgram(void)
 		}
 
 		if (connect(d->fd, (struct sockaddr *)&b->addr, sizeof(b->addr)) < 0) {
-			pr_perror("Can't connect peer %d on fd %d\n",
+			pr_perror("Can't connect peer %d on fd %d",
 				  d->peer, d->fd);
 			goto err;
 		}
@@ -840,7 +840,7 @@ static int open_unix_sk_dgram(int sk, struct unix_sk_entry *ue, int img_fd)
 			unlink(addr.sun_path);
 		if (bind(sk, (struct sockaddr *)&addr,
 			 sizeof(addr.sun_family) + ue->namelen) < 0) {
-			pr_perror("Can't bind socket\n");
+			pr_perror("Can't bind socket");
 			goto err;
 		}
 
@@ -914,12 +914,12 @@ static int open_unix_sk_stream(int sk, struct unix_sk_entry *ue, int img_fd)
 			unlink(addr.sun_path);
 		if (bind(sk, (struct sockaddr *)&addr,
 			 sizeof(addr.sun_family) + ue->namelen) < 0) {
-			pr_perror("Can't bind socket\n");
+			pr_perror("Can't bind socket");
 			goto err;
 		}
 
 		if (listen(sk, ue->backlog) < 0) {
-			pr_perror("Can't listen socket\n");
+			pr_perror("Can't listen socket");
 			goto err;
 		}
 
@@ -962,12 +962,12 @@ static int open_unix_sk_stream(int sk, struct unix_sk_entry *ue, int img_fd)
 
 			prep_conn_addr(ue->id, &addr, &len);
 			if (bind(sk, (struct sockaddr *)&addr, len) < 0) {
-				pr_perror("Can't bind socket\n");
+				pr_perror("Can't bind socket");
 				goto err;
 			}
 
 			if (listen(sk, 1) < 0) {
-				pr_perror("Can't listen socket\n");
+				pr_perror("Can't listen socket");
 				goto err;
 			}
 
@@ -1034,7 +1034,7 @@ static int open_unix_sk(struct unix_sk_entry *ue, int *img_fd)
 
 	sk = socket(PF_UNIX, ue->type, 0);
 	if (sk < 0) {
-		pr_perror("Can't create unix socket\n");
+		pr_perror("Can't create unix socket");
 		return -1;
 	}
 
@@ -1113,7 +1113,7 @@ static int open_inet_sk(struct inet_sk_entry *ie, int *img_fd)
 
 	sk = socket(ie->family, ie->type, ie->proto);
 	if (sk < 0) {
-		pr_perror("Can't create unix socket\n");
+		pr_perror("Can't create unix socket");
 		return -1;
 	}
 
@@ -1127,12 +1127,12 @@ static int open_inet_sk(struct inet_sk_entry *ie, int *img_fd)
 	memcpy(&addr.sin_addr.s_addr, ie->src_addr, sizeof(unsigned int) * 4);
 
 	if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
-		pr_perror("Inet socket bind failed\n");
+		pr_perror("Inet socket bind failed");
 		goto err;
 	}
 
 	if (listen(sk, ie->backlog) == -1) {
-		pr_perror("listen() failed on %d\n", sk);
+		pr_perror("listen() failed on %d", sk);
 		goto err;
 	}
 
diff --git a/util.c b/util.c
index de22151..5ee6e50 100644
--- a/util.c
+++ b/util.c
@@ -100,7 +100,7 @@ int close_safe(int *fd)
 		if (!ret)
 			*fd = -1;
 		else
-			pr_perror("Unable to close fd: %d\n", *fd);
+			pr_perror("Unable to close fd: %d", *fd);
 	}
 
 	return ret;
@@ -128,7 +128,7 @@ int reopen_fd_as_safe(int new_fd, int old_fd, bool allow_reuse_fd)
 
 		tmp = dup2(old_fd, new_fd);
 		if (tmp < 0) {
-			pr_perror("Dup %d -> %d failed\n", old_fd, new_fd);
+			pr_perror("Dup %d -> %d failed", old_fd, new_fd);
 			return tmp;
 		}
 
@@ -146,7 +146,7 @@ int move_img_fd(int *img_fd, int want_fd)
 
 		tmp = dup(*img_fd);
 		if (tmp < 0) {
-			pr_perror("Can't dup file\n");
+			pr_perror("Can't dup file");
 			return -1;
 		}
 
@@ -213,7 +213,7 @@ int open_pid_proc(pid_t pid)
 	sprintf(path, "/proc/%d", pid);
 	fd = open(path, O_RDONLY);
 	if (fd < 0)
-		pr_perror("Can't open %s\n", path);
+		pr_perror("Can't open %s", path);
 	return fd;
 }
 
-- 
1.7.4.4



More information about the CRIU mailing list