[CRIU] [PATCH v2] protobuf: use pretty output for unix sockets

Kinsbursky Stanislav skinsbursky at openvz.org
Tue Aug 21 08:22:05 EDT 2012


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

New custom specificator:

'S': output as string (unprintable characters replaced by dots)

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 protobuf.c |   16 ++++++++++++++++
 sk-unix.c  |   30 +-----------------------------
 2 files changed, 17 insertions(+), 29 deletions(-)
-------------- next part --------------
diff --git a/protobuf.c b/protobuf.c
index c800fd5..b4feadd 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -4,6 +4,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <arpa/inet.h>
+#include <ctype.h>
 
 #include <google/protobuf-c/protobuf-c.h>
 
@@ -289,6 +290,21 @@ static int pb_show_pretty(pb_pr_field_t *field)
 	case '%':
 		pr_msg(field->fmt, *(long *)field->data);
 		break;
+	case 'S':
+		{
+			ProtobufCBinaryData *name = (ProtobufCBinaryData *)field->data;
+			int i;
+
+			for (i = 0; i < name->len; i++) {
+				char c = (char)name->data[i];
+
+				if (isprint(c))
+					pr_msg("%c", c);
+				else if (c != 0)
+					pr_msg(".");
+			}
+			break;
+		}
 	case 'A':
 		{
 			char addr[INET_ADDR_LEN] = "<unknown>";
diff --git a/sk-unix.c b/sk-unix.c
index 830d69d..d650f7f 100644
--- a/sk-unix.c
+++ b/sk-unix.c
@@ -451,35 +451,7 @@ static struct unix_sk_info *find_unix_sk_by_ino(int ino)
 
 void show_unixsk(int fd, struct cr_options *o)
 {
-	UnixSkEntry *ue;
-	int ret = 0;
-
-	pr_img_head(CR_FD_UNIXSK);
-
-	while (1) {
-		ret = pb_read_one_eof(fd, &ue, PB_UNIXSK);
-		if (ret <= 0)
-			goto out;
-
-		pr_msg("id %#x ino %#x type %s state %s namelen %4d backlog %4d peer %#x flags %#x uflags %#x",
-			ue->id, ue->ino, sktype2s(ue->type), skstate2s(ue->state),
-			(int)ue->name.len, ue->backlog, ue->peer, ue->flags, ue->uflags);
-
-		if (ue->name.len) {
-			if (!ue->name.data[0])
-				ue->name.data[0] = '@';
-			pr_msg(" --> %s\n", ue->name.data);
-		} else
-			pr_msg("\n");
-		show_fown_cont(ue->fown);
-		pr_msg("\n");
-
-		if (ue->opts)
-			show_socket_opts(ue->opts);
-		unix_sk_entry__free_unpacked(ue, NULL);
-	}
-out:
-	pr_img_tail(CR_FD_UNIXSK);
+	pb_show_plain_pretty(fd, PB_UNIXSK, "1:%#x 2:%#x 3:%d 4:%d 5:%d 6:%d 7:%d 8:%d 11:S");
 }
 
 static int post_open_unix_sk(struct file_desc *d, int fd)


More information about the CRIU mailing list