[CRIU] [PATCH] [v2] util: block SIGCHLD to run a sub process

Kirill Tkhai ktkhai at virtuozzo.com
Fri Mar 31 02:04:36 PDT 2017


On 30.03.2017 21:11, Andrei Vagin wrote:
> From: Andrei Vagin <avagin at virtuozzo.com>
> 
> CRIU sets a sigchld handler and calls waitpid from it,
> but when we call a sub-process, we want to wait it
> 
> v2: remove a debug code
> 
> Cc: Kirill Tkhai <ktkhai at virtuozzo.com>
> Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>

Acked-by: Kirill Tkhai <ktkhai at virtuozzo.com>

> ---
>  criu/util.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/criu/util.c b/criu/util.c
> index 558d498..dad9386 100644
> --- a/criu/util.c
> +++ b/criu/util.c
> @@ -1369,6 +1369,7 @@ int open_fd_of_real_pid(pid_t pid, int fd, int flags)
>  
>  int call_in_child_process(int (*fn)(void *), void *arg)
>  {
> +	sigset_t blockmask, oldmask;
>  	int size, status, ret = -1;
>  	char *stack;
>  	pid_t pid;
> @@ -1379,10 +1380,19 @@ int call_in_child_process(int (*fn)(void *), void *arg)
>  		pr_perror("Can't allocate stack");
>  		return -1;
>  	}
> +
> +	sigemptyset(&blockmask);
> +	sigaddset(&blockmask, SIGCHLD);
> +
> +	if (sigprocmask(SIG_BLOCK, &blockmask, &oldmask) == -1) {
> +		pr_perror("Can not set mask of blocked signals");
> +		goto out_munmap;
> +	}
> +
>  	pid = clone(fn, stack + size, CLONE_VM | CLONE_FILES | SIGCHLD, arg);
>  	if (pid == -1) {
>  		pr_perror("Can't clone");
> -		goto out_munmap;
> +		goto out_unblock;
>  	}
>  	errno = 0;
>  	if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status) || WEXITSTATUS(status)) {
> @@ -1396,6 +1406,11 @@ out_close:
>  	 * with the same pid later, it will try to reuse this /proc/self.
>  	 */
>  	close_pid_proc();
> +out_unblock:
> +	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) == -1) {
> +		pr_perror("Can not unset mask of blocked signals");
> +		ret = -1;
> +	}
>  out_munmap:
>  	munmap(stack, size);
>  	return ret;
> 


More information about the CRIU mailing list