Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dump: Show task comm early #2064

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions criu/cr-dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ static int pre_dump_one_task(struct pstree_item *item, InventoryEntry *parent_ie
vm_area_list_init(&vmas);

pr_info("========================================\n");
pr_info("Pre-dumping task (pid: %d)\n", pid);
pr_info("Pre-dumping task (pid: %d comm: %s)\n", pid, __task_comm_info(pid));
pr_info("========================================\n");

/*
Expand Down Expand Up @@ -1545,7 +1545,7 @@ static int dump_one_task(struct pstree_item *item, InventoryEntry *parent_ie)
vm_area_list_init(&vmas);

pr_info("========================================\n");
pr_info("Dumping task (pid: %d)\n", pid);
pr_info("Dumping task (pid: %d comm: %s)\n", pid, __task_comm_info(pid));
pr_info("========================================\n");

if (item->pid->state == TASK_DEAD)
Expand Down Expand Up @@ -2113,7 +2113,7 @@ int cr_dump_tasks(pid_t pid)
int ret = -1;

pr_info("========================================\n");
pr_info("Dumping processes (pid: %d)\n", pid);
pr_info("Dumping processes (pid: %d comm: %s)\n", pid, __task_comm_info(pid));
pr_info("========================================\n");

/*
Expand Down
3 changes: 3 additions & 0 deletions criu/include/seize.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ extern void pstree_switch_state(struct pstree_item *root_item, int st);
extern const char *get_real_freezer_state(void);
extern bool alarm_timeouted(void);

extern char *task_comm_info(pid_t pid, char *comm, size_t size);
extern char *__task_comm_info(pid_t pid);

#endif
46 changes: 43 additions & 3 deletions criu/seize.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,46 @@
#include "xmalloc.h"
#include "util.h"

char *task_comm_info(pid_t pid, char *comm, size_t size)
{
int ret = 0;
Snorch marked this conversation as resolved.
Show resolved Hide resolved

if (!pr_quelled(LOG_INFO)) {
int saved_errno = errno;
char path[32];
int fd;

snprintf(path, sizeof(path), "/proc/%d/comm", pid);
fd = open(path, O_RDONLY);
if (fd >= 0) {
ssize_t n = read(fd, comm, size);
if (n > 0)
comm[n - 1] = '\0';
Snorch marked this conversation as resolved.
Show resolved Hide resolved
else
ret = -1;
close(fd);
} else {
ret = -1;
Snorch marked this conversation as resolved.
Show resolved Hide resolved
}
errno = saved_errno;
}

if (ret || (pr_quelled(LOG_INFO) && comm[0]))
comm[0] = '\0';

return comm;
}

/*
* NOTE: Don't run simultaneously, it uses local static buffer!
*/
char *__task_comm_info(pid_t pid)
{
static char comm[32];

return task_comm_info(pid, comm, sizeof(comm));
}

#define NR_ATTEMPTS 5

static const char frozen[] = "FROZEN";
Expand Down Expand Up @@ -249,13 +289,13 @@ static int seize_cgroup_tree(char *root_path, enum freezer_state state)
if (ret == 0)
continue;
if (errno != ESRCH) {
pr_perror("Unexpected error");
pr_perror("Unexpected error for pid %d (comm %s)", pid, __task_comm_info(pid));
fclose(f);
return -1;
}

if (!compel_interrupt_task(pid)) {
pr_debug("SEIZE %d: success\n", pid);
pr_debug("SEIZE %d (comm %s): success\n", pid, __task_comm_info(pid));
processes_to_wait++;
} else if (state == FROZEN) {
char buf[] = "/proc/XXXXXXXXXX/exe";
Expand All @@ -272,7 +312,7 @@ static int seize_cgroup_tree(char *root_path, enum freezer_state state)
* before it compete exit procedure. The caller simply
* should wait a bit and try freezing again.
*/
pr_err("zombie found while seizing\n");
pr_err("zombie %d (comm %s) found while seizing\n", pid, __task_comm_info(pid));
fclose(f);
return -EAGAIN;
}
Expand Down