[CRIU] Re: [PATCH 3/3] restore: Don't close pstree_fd several times

Pavel Emelyanov xemul at parallels.com
Mon Mar 5 10:31:58 EST 2012


On 03/04/2012 01:39 AM, Cyrill Gorcunov wrote:
> There is a scenario when pstree_fd may be tried
> to close several times -- if we start crtools
> with "detach" option. So instead of adding various
> if () constructions -- simply pass a pointer to
> file descriptor and use close_safe which is immune
> against closed file.

I'd better make restore_root_task close it always and patched the
caller to simply do return restore_root_task().

> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  cr-restore.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/cr-restore.c b/cr-restore.c
> index 46295c3..72f328a 100644
> --- a/cr-restore.c
> +++ b/cr-restore.c
> @@ -1388,19 +1388,19 @@ static int restore_task_with_children(void *_arg)
>  	return restore_one_task(me->pid);
>  }
>  
> -static int restore_root_task(int fd, struct cr_options *opts)
> +static int restore_root_task(int *fd, struct cr_options *opts)
>  {
>  	struct pstree_entry e;
>  	int ret, i;
>  	struct sigaction act, old_act;
>  
> -	ret = read(fd, &e, sizeof(e));
> +	ret = read(*fd, &e, sizeof(e));
>  	if (ret != sizeof(e)) {
>  		pr_perror("Can't read root pstree entry");
>  		return -1;
>  	}
>  
> -	close(fd);
> +	close_safe(fd);
>  
>  	ret = sigaction(SIGCHLD, NULL, &act);
>  	if (ret < 0) {
> @@ -1467,7 +1467,7 @@ static int restore_all_tasks(pid_t pid, struct cr_options *opts)
>  	if (prepare_shared(pstree_fd))
>  		goto out;
>  
> -	ret = restore_root_task(pstree_fd, opts);
> +	ret = restore_root_task(&pstree_fd, opts);
>  out:
>  	close_safe(&pstree_fd);
>  	return ret;



More information about the CRIU mailing list