Skip to content

Commit

Permalink
dump: Show task comm early
Browse files Browse the repository at this point in the history
When error happens on file dumping stage the only information about the
task we dumping is its PID. For debug purpose show task's @comm early.

It proves useful when trying to understand which of dumped applications
is "guilty" in brokern dump when pid is not there anymore.

Signed-off-by: Cyrill Gorcunov <[email protected]>
Signed-off-by: Pavel Tikhomirov <[email protected]>
  • Loading branch information
Cyrill Gorcunov authored and Snorch committed Feb 24, 2023
1 parent 6b95196 commit 36e4bd5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
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;

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';
else
ret = -1;
close(fd);
} else {
ret = -1;
}
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

0 comments on commit 36e4bd5

Please sign in to comment.