[CRIU] [PATCH] criu-print: use %# to print hex values w/ width specified

Dmitry Safonov dsafonov at virtuozzo.com
Fri Jul 1 08:37:25 PDT 2016


If we print "0x" with width specifier, it may go away which is not nice:
(00.005258) 21858 fdinfo 0: pos: 0x               0 flags:           100002/0
(00.004589)     Collected: ino 0x    51fd family    2 type    1 port    64000 state 10 src_addr 0.0.0.0

This patch is generated with the following sed one-liner:
find ./* -type f -print0 | xargs -0 sed -i '/pr.*/s/0x%\([0-9]\+\)/%#\1/g'

Don't know if we should change all 0x%*anything* printing to %#*anything*,
but where we use field width I think we should.

Impact: Just bothered by eyes, cleanup.

Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 compel/handle-elf.c |  2 +-
 criu/files.c        |  4 ++--
 criu/fsnotify.c     | 42 +++++++++++++++++++++---------------------
 criu/ipc_ns.c       |  2 +-
 criu/mem.c          | 10 +++++-----
 criu/shmem.c        |  6 +++---
 criu/sk-inet.c      |  2 +-
 7 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/compel/handle-elf.c b/compel/handle-elf.c
index bf038aff0ce8..64616f978d87 100644
--- a/compel/handle-elf.c
+++ b/compel/handle-elf.c
@@ -562,7 +562,7 @@ int __handle_elf(void *mem, size_t size)
 		for (j=0; j < sh->sh_size; j++, k++) {
 			if (k && (k % 8) == 0)
 				pr_out("\n\t");
-			pr_out("0x%02x,", shdata[j]);
+			pr_out("%#02x,", shdata[j]);
 		}
 	}
 	pr_out("};\n");
diff --git a/criu/files.c b/criu/files.c
index 719d0bebdee7..8c51eaf57122 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -278,7 +278,7 @@ int do_dump_gen_file(struct fd_parms *p, int lfd,
 	if (ret < 0)
 		return ret;
 
-	pr_info("fdinfo: type: 0x%2x flags: %#o/%#o pos: 0x%8"PRIx64" fd: %d\n",
+	pr_info("fdinfo: type: %#2x flags: %#o/%#o pos: %#8"PRIx64" fd: %d\n",
 		ops->type, p->flags, (int)p->fd_flags, p->pos, p->fd);
 
 	return pb_write_one(img, &e, PB_FDINFO);
@@ -335,7 +335,7 @@ static int fill_fd_params(struct parasite_ctl *ctl, int fd, int lfd,
 
 	fown_entry__init(&p->fown);
 
-	pr_info("%d fdinfo %d: pos: 0x%16"PRIx64" flags: %16o/%#x\n",
+	pr_info("%d fdinfo %d: pos: %#16"PRIx64" flags: %16o/%#x\n",
 		ctl->pid.real, fd, p->pos, p->flags, (int)p->fd_flags);
 
 	ret = fcntl(lfd, F_GETSIG, 0);
diff --git a/criu/fsnotify.c b/criu/fsnotify.c
index 4035506c744b..4cf2da8268c6 100644
--- a/criu/fsnotify.c
+++ b/criu/fsnotify.c
@@ -204,13 +204,13 @@ static int open_handle(unsigned int s_dev, unsigned long i_ino,
 
 	mntfd = open_mount(s_dev);
 	if (mntfd < 0) {
-		pr_err("Mount root for 0x%08x not found\n", s_dev);
+		pr_err("Mount root for %#08x not found\n", s_dev);
 		goto out;
 	}
 
 	fd = userns_call(open_by_handle, UNS_FDOUT, &handle, sizeof(handle), mntfd);
 	if (fd < 0) {
-		pr_perror("Can't open file handle for 0x%08x:0x%016lx",
+		pr_perror("Can't open file handle for %#08x:%#016lx",
 				s_dev, i_ino);
 	}
 
@@ -307,9 +307,9 @@ static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
 	struct inotify_wd_entry *wd_entry = (struct inotify_wd_entry *) e;
 	InotifyWdEntry *we = &wd_entry->e;
 
-	pr_info("wd: wd 0x%08x s_dev 0x%08x i_ino 0x%16"PRIx64" mask 0x%08x\n",
+	pr_info("wd: wd %#08x s_dev %#08x i_ino %#16"PRIx64" mask %#08x\n",
 			we->wd, we->s_dev, we->i_ino, we->mask);
-	pr_info("\t[fhandle] bytes 0x%08x type 0x%08x __handle 0x%016"PRIx64":0x%016"PRIx64"\n",
+	pr_info("\t[fhandle] bytes %#08x type %#08x __handle %#016"PRIx64":%#016"PRIx64"\n",
 			we->f_handle->bytes, we->f_handle->type,
 			we->f_handle->handle[0], we->f_handle->handle[1]);
 
@@ -339,7 +339,7 @@ static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p)
 	if (ret < 0)
 		return -1;
 	else if (ret > 0)
-		pr_warn("The 0x%08x inotify events will be dropped\n", id);
+		pr_warn("The %#08x inotify events will be dropped\n", id);
 
 	ie.id = id;
 	ie.flags = p->flags;
@@ -357,7 +357,7 @@ static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p)
 		ie.wd[i++] = &we->ify.e;
 	ie.n_wd = wd_list.n;
 
-	pr_info("id 0x%08x flags 0x%08x\n", ie.id, ie.flags);
+	pr_info("id %#08x flags %#08x\n", ie.id, ie.flags);
 	if (pb_write_one(img_from_set(glob_imgset, CR_FD_INOTIFY_FILE), &ie, PB_INOTIFY_FILE))
 		goto free;
 
@@ -401,10 +401,10 @@ static int dump_fanotify_entry(union fdinfo_entries *e, void *arg)
 
 		BUG_ON(!fme->ie);
 
-		pr_info("mark: s_dev 0x%08x i_ino 0x%016"PRIx64" mask 0x%08x\n",
+		pr_info("mark: s_dev %#08x i_ino %#016"PRIx64" mask %#08x\n",
 			fme->s_dev, fme->ie->i_ino, fme->mask);
 
-		pr_info("\t[fhandle] bytes 0x%08x type 0x%08x __handle 0x%016"PRIx64":0x%016"PRIx64"\n",
+		pr_info("\t[fhandle] bytes %#08x type %#08x __handle %#016"PRIx64":%#016"PRIx64"\n",
 			fme->ie->f_handle->bytes, fme->ie->f_handle->type,
 			fme->ie->f_handle->handle[0], fme->ie->f_handle->handle[1]);
 
@@ -424,7 +424,7 @@ static int dump_fanotify_entry(union fdinfo_entries *e, void *arg)
 		}
 		fme->s_dev = m->s_dev;
 
-		pr_info("mark: s_dev 0x%08x mnt_id  0x%08x mask 0x%08x\n",
+		pr_info("mark: s_dev %#08x mnt_id  %#08x mask %#08x\n",
 			fme->s_dev, fme->me->mnt_id, fme->mask);
 
 	}
@@ -449,7 +449,7 @@ static int dump_one_fanotify(int lfd, u32 id, const struct fd_parms *p)
 	if (ret < 0)
 		return -1;
 	else if (ret > 0)
-		pr_warn("The 0x%08x fanotify events will be dropped\n", id);
+		pr_warn("The %#08x fanotify events will be dropped\n", id);
 	ret = -1;
 
 	fe.id = id;
@@ -469,7 +469,7 @@ static int dump_one_fanotify(int lfd, u32 id, const struct fd_parms *p)
 		fe.mark[i++] = &we->ffy.e;
 	fe.n_mark = wd_list.n;
 
-	pr_info("id 0x%08x flags 0x%08x\n", fe.id, fe.flags);
+	pr_info("id %#08x flags %#08x\n", fe.id, fe.flags);
 
 	fe.faflags = wd_list.fsn_params.faflags;
 	fe.evflags = wd_list.fsn_params.evflags;
@@ -518,7 +518,7 @@ static char *get_mark_path(const char *who, struct file_remap *remap,
 
 		mntns_root = mntns_get_root_by_mnt_id(remap->rmnt_id);
 
-		pr_debug("\t\tRestore %s watch for 0x%08x:0x%016lx (via %s)\n",
+		pr_debug("\t\tRestore %s watch for %#08x:%#016lx (via %s)\n",
 			 who, s_dev, i_ino, remap->rpath);
 		*target = openat(mntns_root, remap->rpath, O_PATH);
 	} else if (f_handle->path) {
@@ -561,7 +561,7 @@ static char *get_mark_path(const char *who, struct file_remap *remap,
 		if (read_fd_link(*target, link, sizeof(link)) < 0)
 			link[0] = '\0';
 
-		pr_debug("\t\tRestore %s watch for 0x%08x:0x%016lx (via %s -> %s)\n",
+		pr_debug("\t\tRestore %s watch for %#08x:%#016lx (via %s -> %s)\n",
 				who, s_dev, i_ino, path, link);
 	}
 err:
@@ -689,12 +689,12 @@ static int open_inotify_fd(struct file_desc *d)
 
 	tmp = inotify_init1(info->ife->flags);
 	if (tmp < 0) {
-		pr_perror("Can't create inotify for 0x%08x", info->ife->id);
+		pr_perror("Can't create inotify for %#08x", info->ife->id);
 		return -1;
 	}
 
 	list_for_each_entry(wd_info, &info->marks, list) {
-		pr_info("\tRestore 0x%x wd for 0x%08x\n", wd_info->iwe->wd, wd_info->iwe->id);
+		pr_info("\tRestore 0x%x wd for %#08x\n", wd_info->iwe->wd, wd_info->iwe->id);
 		if (restore_one_inotify(tmp, wd_info)) {
 			close_safe(&tmp);
 			break;
@@ -729,7 +729,7 @@ static int open_fanotify_fd(struct file_desc *d)
 	}
 
 	list_for_each_entry(mark, &info->marks, list) {
-		pr_info("\tRestore fanotify for 0x%08x\n", mark->fme->id);
+		pr_info("\tRestore fanotify for %#08x\n", mark->fme->id);
 		if (restore_one_fanotify(ret, mark)) {
 			close_safe(&ret);
 			break;
@@ -763,7 +763,7 @@ static struct fsnotify_file_info *find_inotify_info(unsigned id)
 		 * wd-s for one inotify in one row, thus sometimes
 		 * we can avoid scanning the inotify_info_head.
 		 */
-		pr_debug("\t\tlast ify for 0x%08x found\n", id);
+		pr_debug("\t\tlast ify for %#08x found\n", id);
 		return last;
 	}
 
@@ -773,7 +773,7 @@ static struct fsnotify_file_info *find_inotify_info(unsigned id)
 			return p;
 		}
 
-	pr_err("Can't find inotify with id 0x%08x\n", id);
+	pr_err("Can't find inotify with id %#08x\n", id);
 	return NULL;
 }
 
@@ -824,7 +824,7 @@ static int collect_fanotify_mark(struct fsnotify_mark_info *mark)
 			return __collect_inotify_mark(p, mark);
 	}
 
-	pr_err("Can't find fanotify with id 0x%08x\n", mark->fme->id);
+	pr_err("Can't find fanotify with id %#08x\n", mark->fme->id);
 	return -1;
 }
 
@@ -836,7 +836,7 @@ static int collect_one_inotify(void *o, ProtobufCMessage *msg, struct cr_img *im
 	info->ife = pb_msg(msg, InotifyFileEntry);
 	INIT_LIST_HEAD(&info->marks);
 	list_add(&info->list, &inotify_info_head);
-	pr_info("Collected id 0x%08x flags 0x%08x\n", info->ife->id, info->ife->flags);
+	pr_info("Collected id %#08x flags %#08x\n", info->ife->id, info->ife->flags);
 
 	for (i = 0; i < info->ife->n_wd; i++) {
 		struct fsnotify_mark_info *mark;
@@ -871,7 +871,7 @@ static int collect_one_fanotify(void *o, ProtobufCMessage *msg, struct cr_img *i
 	info->ffe = pb_msg(msg, FanotifyFileEntry);
 	INIT_LIST_HEAD(&info->marks);
 	list_add(&info->list, &fanotify_info_head);
-	pr_info("Collected id 0x%08x flags 0x%08x\n", info->ffe->id, info->ffe->flags);
+	pr_info("Collected id %#08x flags %#08x\n", info->ffe->id, info->ffe->flags);
 
 	for (i = 0; i < info->ffe->n_mark; i++) {
 		struct fsnotify_mark_info *mark;
diff --git a/criu/ipc_ns.c b/criu/ipc_ns.c
index 19dfb72cf21b..7fa4b03c3673 100644
--- a/criu/ipc_ns.c
+++ b/criu/ipc_ns.c
@@ -38,7 +38,7 @@
 
 static void pr_ipc_desc_entry(unsigned int loglevel, const IpcDescEntry *desc)
 {
-	print_on_level(loglevel, "id: %-10d key: 0x%08x uid: %-10d gid: %-10d "
+	print_on_level(loglevel, "id: %-10d key: %#08x uid: %-10d gid: %-10d "
 		       "cuid: %-10d cgid: %-10d mode: %-10o ",
 		       desc->id, desc->key, desc->uid, desc->gid,
 		       desc->cuid, desc->cgid, desc->mode);
diff --git a/criu/mem.c b/criu/mem.c
index db61aedae4f2..c4c968c30464 100644
--- a/criu/mem.c
+++ b/criu/mem.c
@@ -537,7 +537,7 @@ static int map_private_vma(struct pstree_item *t,
 		    vma->e->shmid != p->e->shmid)
 			break;
 
-		pr_info("COW 0x%016"PRIx64"-0x%016"PRIx64" 0x%016"PRIx64" vma\n",
+		pr_info("COW %#016"PRIx64"-%#016"PRIx64" %#016"PRIx64" vma\n",
 			vma->e->start, vma->e->end, vma->e->pgoff);
 		paddr = decode_pointer(p->premmaped_addr);
 
@@ -561,7 +561,7 @@ static int map_private_vma(struct pstree_item *t,
 		 * The respective memory area was NOT found in the parent.
 		 * Map a new one.
 		 */
-		pr_info("Map 0x%016"PRIx64"-0x%016"PRIx64" 0x%016"PRIx64" vma\n",
+		pr_info("Map %#016"PRIx64"-%#016"PRIx64" %#016"PRIx64" vma\n",
 			vma->e->start, vma->e->end, vma->e->pgoff);
 
 		/*
@@ -600,7 +600,7 @@ static int map_private_vma(struct pstree_item *t,
 	}
 
 	vma->premmaped_addr = (unsigned long) addr;
-	pr_debug("\tpremap 0x%016"PRIx64"-0x%016"PRIx64" -> %016lx\n",
+	pr_debug("\tpremap %#016"PRIx64"-%#016"PRIx64" -> %016lx\n",
 		vma->e->start, vma->e->end, (unsigned long)addr);
 
 	if (vma->e->flags & MAP_GROWSDOWN) { /* Skip gurad page */
@@ -723,7 +723,7 @@ static int restore_priv_vma_content(struct pstree_item *t)
 			 * on demand.
 			 */
 			if (opts.lazy_pages && vma_entry_can_be_lazy(vma->e)) {
-				pr_debug("Lazy restore skips 0x%016"PRIx64"\n", vma->e->start);
+				pr_debug("Lazy restore skips %#016"PRIx64"\n", vma->e->start);
 				pr.skip_pages(&pr, PAGE_SIZE);
 				nr_lazy++;
 				continue;
@@ -908,7 +908,7 @@ int open_vmas(struct pstree_item *t)
 		if (!vma_area_is(vma, VMA_AREA_REGULAR) || !vma->vm_open)
 			continue;
 
-		pr_info("Opening 0x%016"PRIx64"-0x%016"PRIx64" 0x%016"PRIx64" (%x) vma\n",
+		pr_info("Opening %#016"PRIx64"-%#016"PRIx64" %#016"PRIx64" (%x) vma\n",
 				vma->e->start, vma->e->end,
 				vma->e->pgoff, vma->e->status);
 
diff --git a/criu/shmem.c b/criu/shmem.c
index f86a56af659d..e3bc440d0cc5 100644
--- a/criu/shmem.c
+++ b/criu/shmem.c
@@ -318,7 +318,7 @@ int collect_shmem(int pid, struct vma_area *vma)
 	if (!si)
 		return -1;
 
-	pr_info("Add new shmem 0x%"PRIx64" (0x%016"PRIx64"-0x%016"PRIx64")\n",
+	pr_info("Add new shmem 0x%"PRIx64" (%#016"PRIx64"-%#016"PRIx64")\n",
 				vi->shmid, vi->start, vi->end);
 
 	si->shmid = vi->shmid;
@@ -400,9 +400,9 @@ static int open_shmem(int pid, struct vma_area *vma)
 	int flags;
 
 	si = shmem_find(vi->shmid);
-	pr_info("Search for 0x%016"PRIx64" shmem 0x%"PRIx64" %p/%d\n", vi->start, vi->shmid, si, si ? si->pid : -1);
+	pr_info("Search for %#016"PRIx64" shmem 0x%"PRIx64" %p/%d\n", vi->start, vi->shmid, si, si ? si->pid : -1);
 	if (!si) {
-		pr_err("Can't find my shmem 0x%016"PRIx64"\n", vi->start);
+		pr_err("Can't find my shmem %#016"PRIx64"\n", vi->start);
 		return -1;
 	}
 
diff --git a/criu/sk-inet.c b/criu/sk-inet.c
index de1d97384d4d..f4bc51923de9 100644
--- a/criu/sk-inet.c
+++ b/criu/sk-inet.c
@@ -72,7 +72,7 @@ static void show_one_inet(const char *act, const struct inet_sk_desc *sk)
 		pr_perror("Failed to translate address");
 	}
 
-	pr_debug("\t%s: ino 0x%8x family %4d type %4d port %8d "
+	pr_debug("\t%s: ino %#8x family %4d type %4d port %8d "
 		"state %2d src_addr %s\n",
 		act, sk->sd.ino, sk->sd.family, sk->type, sk->src_port,
 		sk->state, src_addr);
-- 
2.9.0



More information about the CRIU mailing list