From e997d34b0ccea9bc82fd890d603347082c0fc17c Mon Sep 17 00:00:00 2001 From: Kirill Tkhai Date: Tue, 16 May 2017 22:45:55 +0300 Subject: [PATCH] criu: Add raw fork() implementation Glibc has BUG with process creation: https://sourceware.org/bugzilla/show_bug.cgi?id=21386 It doesn't behave well when parent and child are from different pid namespaces and have the same pid. Use raw syscall without glibc's asserts as workaround. Also, use raw syscall for getpid() in tests too, as these two function go in the pair (glibc's getpid() relies on glibc's fork()). Signed-off-by: Kirill Tkhai Signed-off-by: Andrei Vagin --- criu/util.c | 9 +++++++++ test/zdtm/lib/test.c | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/criu/util.c b/criu/util.c index 59643f88b..6fa0ab05f 100644 --- a/criu/util.c +++ b/criu/util.c @@ -1459,3 +1459,12 @@ int getpid() { return syscall(__NR_getpid); } + +/* + * In glibc 2.24, fork() may fail when parent and child are + * from different pid namespaces and have the same pid. + */ +pid_t fork() +{ + return (pid_t)syscall(__NR_clone, SIGCHLD, 0, NULL, 0, NULL); +} diff --git a/test/zdtm/lib/test.c b/test/zdtm/lib/test.c index 562fa56c6..b332cba0d 100644 --- a/test/zdtm/lib/test.c +++ b/test/zdtm/lib/test.c @@ -296,3 +296,13 @@ void test_waitsig(void) { futex_wait_while(&sig_received, 0); } + +pid_t fork() +{ + return (pid_t)syscall(__NR_clone, SIGCHLD, 0, NULL, 0, NULL); +} + +int getpid() +{ + return syscall(__NR_getpid); +}