[CRIU] [PATCH 10/11] dump: Show task comm early

Pavel Emelyanov xemul at virtuozzo.com
Thu Aug 4 07:09:47 PDT 2016


On 08/02/2016 06:34 PM, Cyrill Gorcunov wrote:
> 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.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  criu/cr-dump.c | 41 ++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 38 insertions(+), 3 deletions(-)
> 
> diff --git a/criu/cr-dump.c b/criu/cr-dump.c
> index 06ff2d7cf8d3..be47f1874d34 100644
> --- a/criu/cr-dump.c
> +++ b/criu/cr-dump.c
> @@ -1113,6 +1113,41 @@ err:
>  	return ret;
>  }
>  
> +/*
> + * NOTE: Don't run simultaneously, it uses local static buffer!
> + * The only purpose of the helper is to print out task command
> + * for debug purpose when error happens early before task
> + * statistics gathered.
> + */
> +static char *task_comm_info(pid_t pid)
> +{
> +	static char comm[PROC_TASK_COMM_LEN];
> +	int ret = 0;
> +
> +	if (!pr_quelled(LOG_INFO)) {
> +		char path[64];
> +		int fd;
> +
> +		snprintf(path, sizeof(path), "/proc/%d/comm", pid);
> +		fd = open(path, O_RDONLY);

open_proc()

> +		if (fd >= 0) {
> +			ssize_t n = read(fd, comm, sizeof(comm));
> +			if (n > 0)
> +				comm[n-1] = '\0';
> +			else
> +				ret = -1;
> +			close(fd);
> +		} else {
> +			pr_perror("Can't open %s\n", path);
> +			ret = -1;
> +		}
> +	}
> +
> +	if (ret && comm[0])
> +		comm[0] = '\0';
> +	return comm;
> +}
> +
>  static int pre_dump_one_task(struct pstree_item *item)
>  {
>  	pid_t pid = item->pid.real;
> @@ -1125,7 +1160,7 @@ static int pre_dump_one_task(struct pstree_item *item)
>  	vmas.nr = 0;
>  
>  	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");
>  
>  	if (item->pid.state == TASK_STOPPED) {
> @@ -1201,7 +1236,7 @@ static int dump_one_task(struct pstree_item *item)
>  	vmas.nr = 0;
>  
>  	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)
> @@ -1677,7 +1712,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");
>  
>  	root_item = alloc_pstree_item();
> 



More information about the CRIU mailing list