Commit 768d88f2 authored by Stanislav Kinsbursky's avatar Stanislav Kinsbursky Committed by Pavel Emelyanov

protobuf: use pretty output for unix sockets

New custom specificator:

'S': output as string (unprintable characters replaced by dots)
Signed-off-by: 's avatarStanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent eb63547a
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <ctype.h>
#include <google/protobuf-c/protobuf-c.h> #include <google/protobuf-c/protobuf-c.h>
...@@ -289,6 +290,21 @@ static int pb_show_pretty(pb_pr_field_t *field) ...@@ -289,6 +290,21 @@ static int pb_show_pretty(pb_pr_field_t *field)
case '%': case '%':
pr_msg(field->fmt, *(long *)field->data); pr_msg(field->fmt, *(long *)field->data);
break; 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': case 'A':
{ {
char addr[INET_ADDR_LEN] = "<unknown>"; char addr[INET_ADDR_LEN] = "<unknown>";
......
...@@ -451,35 +451,7 @@ static struct unix_sk_info *find_unix_sk_by_ino(int ino) ...@@ -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) void show_unixsk(int fd, struct cr_options *o)
{ {
UnixSkEntry *ue; 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");
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);
} }
static int post_open_unix_sk(struct file_desc *d, int fd) static int post_open_unix_sk(struct file_desc *d, int fd)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment