[CRIU] [PATCH] util: block SIGCHLD to run a sub process
Andrei Vagin
avagin at openvz.org
Wed Mar 29 22:48:21 PDT 2017
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
Cc: Kirill Tkhai <ktkhai at virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
criu/util.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/criu/util.c b/criu/util.c
index 558d498..c014a5d 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,14 +1380,27 @@ 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)) {
- pr_err("Can't wait or bad status: errno=%d, status=%d", errno, status);
+ if (waitpid(pid, &status, 0) != pid) {
+ pr_perror("Unable to wait %d", pid);
+ goto out_close;
+ }
+ if ( !WIFEXITED(status) || WEXITSTATUS(status)) {
+ pr_err("Can't wait or bad status: errno=%d (%s), status=%d", errno, strerror(errno), status);
goto out_close;
}
ret = 0;
@@ -1396,8 +1410,14 @@ 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;
}
--
2.7.4
More information about the CRIU
mailing list