[CRIU] [PATCH] zdtm: use pthread_create to create a thread

Andrew Vagin avagin at openvz.org
Wed Sep 9 09:10:41 PDT 2015


If you call clone directly you are responsible for setting up the TLS area yourself.

$ abrt-cli ls  | grep different_creds | wc -l
39
$ gdb -c /var/spool/abrt/ccpp-2015-07-24-10\:21\:14-8014/coredump  different_creds
 Core was generated by `./different_creds --pidfile=different_creds.pid --outfile=different_creds.out'.
 Program terminated with signal SIGILL, Illegal instruction.
 #0  0x00007f86e2d8c7d9 in _dl_x86_64_restore_sse () from /lib64/ld-linux-x86-64.so.2
 Missing separate debuginfos, use: dnf debuginfo-install glibc-2.21-7.fc22.x86_64 libattr-2.4.47-9.fc22.x86_64 libcap-2.24-7.fc22.x86_64
 (gdb) bt
 #0  0x00007f86e2d8c7d9 in _dl_x86_64_restore_sse () from /lib64/ld-linux-x86-64.so.2
 #1  0x00007f86e2d84add in _dl_fixup () from /lib64/ld-linux-x86-64.so.2
 #2  0x00007f86e2d8bbc0 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
 #3  0x0000000000402da3 in sys_futex (val3=0, uaddr2=0x0, timeout=0x0, val=0, op=0, uaddr=0x6063f0 <sig_received>) at lock.h:29
 #4  futex_wait_while (f=0x6063f0 <sig_received>, v=0) at lock.h:121
 #5  test_waitsig () at test.c:367
 #6  0x0000000000401c4b in main (argc=<optimized out>, argv=0x7ffce16432f8) at different_creds.c:82

Reported-by: Mr Jenkins
Cc: Tycho Andersen <tycho.andersen at canonical.com>
Signed-off-by: Andrew Vagin <avagin at openvz.org>
---
 test/zdtm/live/static/Makefile          |  1 +
 test/zdtm/live/static/different_creds.c | 26 ++++++++++++--------------
 2 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 67be675..e66d3ca 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -317,6 +317,7 @@ inotify_system_nodel:	override CFLAGS += -DNODEL
 pthread00:		override LDLIBS += -pthread
 pthread01:		override LDLIBS += -pthread
 pthread02:		override LDLIBS += -pthread
+different_creds:	override LDLIBS += -pthread
 sigpending:		override LDLIBS += -pthread
 sigaltstack:		override LDLIBS += -pthread
 shm:			override CFLAGS += -DNEW_IPC_NS
diff --git a/test/zdtm/live/static/different_creds.c b/test/zdtm/live/static/different_creds.c
index 545dcb3..c9d23c9 100644
--- a/test/zdtm/live/static/different_creds.c
+++ b/test/zdtm/live/static/different_creds.c
@@ -6,13 +6,18 @@
 #include <sched.h>
 #include <sys/capability.h>
 #include <linux/limits.h>
+#include <pthread.h>
+#include <syscall.h>
 
 #include "zdtmtst.h"
 
 const char *test_doc	= "Check that threads with different creds aren't checkpointed";
 const char *test_author	= "Tycho Andersen <tycho.andersen at canonical.com>";
 
-int drop_caps_and_wait(void *arg)
+#define exit_group(code)	\
+	syscall(__NR_exit_group, code)
+
+void *drop_caps_and_wait(void *arg)
 {
 	cap_t caps;
 	int *pipe = arg;
@@ -20,7 +25,7 @@ int drop_caps_and_wait(void *arg)
         caps = cap_get_proc();
         if (!caps) {
                 err("cap_get_proc");
-                return 1;
+                return NULL;
         }
 
         if (cap_clear_flag(caps, CAP_EFFECTIVE) < 0) {
@@ -39,18 +44,14 @@ int drop_caps_and_wait(void *arg)
 		sleep(1000);
 die:
         cap_free(caps);
-        return 1;
+        return NULL;
 }
 
 int main(int argc, char ** argv)
 {
-	pid_t pid;
 	int ret, pipefd[2];
-	long clone_flags = CLONE_VM | CLONE_FILES | CLONE_SIGHAND |
-			   CLONE_THREAD | CLONE_SYSVSEM;
+	pthread_t thr;
 
-        size_t stack_size = sysconf(_SC_PAGESIZE);
-        void *stack = alloca(stack_size);
 	char buf;
 
 	test_init(argc, argv);
@@ -60,12 +61,10 @@ int main(int argc, char ** argv)
 		return -1;
 	}
 
-	pid = clone(drop_caps_and_wait, stack + stack_size, clone_flags, pipefd);
-	if (pid < 0) {
-		err("fork");
+	if (pthread_create(&thr, NULL, drop_caps_and_wait, pipefd)) {
+		err("Unable to create thread");
 		return -1;
 	}
-
 	close(pipefd[1]);
 
 	/*
@@ -83,6 +82,5 @@ int main(int argc, char ** argv)
 
 	fail("shouldn't dump successfully");
 
-	kill(pid, SIGKILL);
-	return ret;
+	exit_group(ret);
 }
-- 
2.4.3



More information about the CRIU mailing list