Commit d88a52f1 authored by Kinsbursky Stanislav's avatar Kinsbursky Stanislav Committed by Pavel Emelyanov

protobuf: use generic show function for processes tree

Signed-off-by: 's avatarStanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 8c72187b
...@@ -258,64 +258,37 @@ void show_creds(int fd, struct cr_options *o) ...@@ -258,64 +258,37 @@ void show_creds(int fd, struct cr_options *o)
pb_show_vertical(fd, creds_entry); pb_show_vertical(fd, creds_entry);
} }
static int show_collect_pstree(int fd_pstree, struct list_head *collect) static void pstree_handler(int fd, void *obj, int collect)
{ {
PstreeEntry *e; PstreeEntry *e = obj;
struct pstree_item *item = NULL;
pr_img_head(CR_FD_PSTREE); if (!collect)
return;
while (1) {
int ret;
struct pstree_item *item = NULL;
e = NULL;
ret = pb_read_eof(fd_pstree, &e, pstree_entry);
if (ret <= 0)
goto out;
pr_msg("pid: %8d ppid %8d pgid: %8d sid %8d n_threads: %8d\n",
(int)e->pid, (int)e->ppid, (int)e->pgid,
(int)e->sid, (int)e->n_threads);
if (collect) {
item = xzalloc(sizeof(struct pstree_item));
if (!item)
return -1;
item->pid.virt = e->pid;
item->nr_threads = e->n_threads;
item->threads = xzalloc(sizeof(u32) * e->n_threads);
if (!item->threads) {
xfree(item);
return -1;
}
list_add_tail(&item->list, collect);
}
if (e->n_threads) { item = xzalloc(sizeof(struct pstree_item));
pr_msg(" \\\n"); if (!item)
pr_msg(" --- threads: "); return;
while (e->n_threads--) {
pr_msg(" %6d", (int)e->threads[e->n_threads]);
if (item)
item->threads[e->n_threads].virt = e->threads[e->n_threads];
}
pr_msg("\n");
}
pstree_entry__free_unpacked(e, NULL); item->pid.virt = e->pid;
item->nr_threads = e->n_threads;
item->threads = xzalloc(sizeof(u32) * e->n_threads);
if (!item->threads) {
xfree(item);
return;
} }
out: list_add_tail(&item->list, &pstree_list);
if (e) }
pstree_entry__free_unpacked(e, NULL);
pr_img_tail(CR_FD_PSTREE); void show_collect_pstree(int fd, int collect)
return 0; {
pb_show_plain_payload(fd, pstree_entry, pstree_handler, collect);
} }
void show_pstree(int fd_pstree, struct cr_options *o) void show_pstree(int fd, struct cr_options *o)
{ {
show_collect_pstree(fd_pstree, NULL); show_collect_pstree(fd, 0);
} }
static inline char *task_state_str(int state) static inline char *task_state_str(int state)
...@@ -424,17 +397,12 @@ err: ...@@ -424,17 +397,12 @@ err:
static int cr_show_all(struct cr_options *opts) static int cr_show_all(struct cr_options *opts)
{ {
struct pstree_item *item = NULL, *tmp; struct pstree_item *item = NULL, *tmp;
LIST_HEAD(pstree_list);
int i, ret = -1, fd, pid; int i, ret = -1, fd, pid;
fd = open_image_ro(CR_FD_PSTREE); fd = open_image_ro(CR_FD_PSTREE);
if (fd < 0) if (fd < 0)
goto out; goto out;
show_collect_pstree(fd, 1);
ret = show_collect_pstree(fd, &pstree_list);
if (ret)
goto out;
close(fd); close(fd);
fd = open_image_ro(CR_FD_SK_QUEUES); fd = open_image_ro(CR_FD_SK_QUEUES);
......
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