Skip to content

Commit

Permalink
util: block SIGCHLD to run a sub process
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Andrei Vagin <[email protected]>
Acked-by: Kirill Tkhai <[email protected]>
Signed-off-by: Andrei Vagin <[email protected]>
  • Loading branch information
avagin committed Apr 4, 2017
1 parent f2af34d commit a26033e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion criu/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand All @@ -1396,6 +1406,11 @@ int call_in_child_process(int (*fn)(void *), void *arg)
* 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;
Expand Down

0 comments on commit a26033e

Please sign in to comment.