[CRIU] [PATCH 2/2] criu: Add raw fork() implementation

Kirill Tkhai ktkhai at virtuozzo.com
Tue May 16 12:45:55 PDT 2017


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 <ktkhai at virtuozzo.com>
---
 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 dad9386a7..90473c09e 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -1424,3 +1424,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 a01eac377..52ee86219 100644
--- a/test/zdtm/lib/test.c
+++ b/test/zdtm/lib/test.c
@@ -285,3 +285,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);
+}



More information about the CRIU mailing list