[CRIU] [PATCH] pstree: Avoid multiple calls to getpid()

Andrei Vagin avagin at gmail.com
Thu Nov 8 20:43:27 MSK 2018


Applied, thanks!

I replaced current_pid to pid. I think it looks a bit better. Let me
know if you don't thing so.

On Sun, Oct 28, 2018 at 08:42:51PM +0000, Radostin Stoyanov wrote:
> Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
> ---
>  criu/pstree.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/criu/pstree.c b/criu/pstree.c
> index 928fe2d1..980d19fd 100644
> --- a/criu/pstree.c
> +++ b/criu/pstree.c
> @@ -333,10 +333,10 @@ err:
>  	return ret;
>  }
>  
> -static int prepare_pstree_for_shell_job(void)
> +static int prepare_pstree_for_shell_job(pid_t current_pid)
>  {
> -	pid_t current_sid = getsid(getpid());
> -	pid_t current_gid = getpgid(getpid());
> +	pid_t current_sid = getsid(current_pid);
> +	pid_t current_gid = getpgid(current_pid);
>  
>  	struct pstree_item *pi;
>  
> @@ -625,12 +625,12 @@ static int get_free_pid()
>  	return -1;
>  }
>  
> -static int prepare_pstree_ids(void)
> +static int prepare_pstree_ids(pid_t current_pid)
>  {
>  	struct pstree_item *item, *child, *helper, *tmp;
>  	LIST_HEAD(helpers);
>  
> -	pid_t current_pgid = getpgid(getpid());
> +	pid_t current_pgid = getpgid(current_pid);
>  
>  	/*
>  	 * Some task can be reparented to init. A helper task should be added
> @@ -910,7 +910,7 @@ static int prepare_pstree_kobj_ids(void)
>  int prepare_pstree(void)
>  {
>  	int ret;
> -	pid_t pid_max = 0, kpid_max = 0;
> +	pid_t pid_max = 0, kpid_max = 0, current_pid;
>  	int fd;
>  	char buf[21];
>  
> @@ -945,12 +945,14 @@ int prepare_pstree(void)
>  		}
>  	}
>  
> +	current_pid = getpid();
> +
>  	if (!ret)
>  		/*
>  		 * Shell job may inherit sid/pgid from the current
>  		 * shell, not from image. Set things up for this.
>  		 */
> -		ret = prepare_pstree_for_shell_job();
> +		ret = prepare_pstree_for_shell_job(current_pid);
>  	if (!ret)
>  		/*
>  		 * Walk the collected tree and prepare for restoring
> @@ -962,7 +964,7 @@ int prepare_pstree(void)
>  		 * Session/Group leaders might be dead. Need to fix
>  		 * pstree with properly injected helper tasks.
>  		 */
> -		ret = prepare_pstree_ids();
> +		ret = prepare_pstree_ids(current_pid);
>  
>  	return ret;
>  }
> -- 
> 2.17.2
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list