Skip to contentSkip to conversation

lib/tst_test: avoid cleanup by cloned test threads

PATCH New Steve Muckle 2 participants 2 messages Sep 20, 2017 – Sep 22, 2017 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/tst_test: avoid cleanup by cloned test threads

Some versions of glibc and bionic report the same PID for parent and child when clone() is called with CLONE_VM but not CLONE_THREAD. This can cause cleanup to be incorrectly run by the child.

Avoid this by using a direct syscall for getpid when running the cleanup.

---
 lib/tst_test.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
lib/tst_test.c +8 -1
index f72de82d4..0cc78589e 100644
@@ -29,6 +29,7 @@
 #include "tst_test.h"
 #include "tst_device.h"
 #include "lapi/futex.h"
+#include "lapi/syscalls.h"
 #include "tst_ansi_color.h"
 #include "tst_timer_test.h"
 
@@ -276,7 +277,13 @@ void tst_vbrk_(const char *file, const int lineno, int ttype,
 {
 	print_result(file, lineno, ttype, fmt, va);
 
-	if (getpid() == main_pid)
+	/*
+	 * The getpid implementation in some C library versions may cause cloned
+	 * test threads to show the same pid as their parent when CLONE_VM is
+	 * specified but CLONE_THREAD is not. Use direct syscall to avoid
+	 * cleanup running in the child.
+	 */
+	if (syscall(SYS_getpid) == main_pid)
 		do_test_cleanup();
 
 	if (getpid() == lib_pid)
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
#1 lore raw

PATCH 1/1 lib/tst_test: avoid cleanup by cloned test threads

----- Original Message -----

Quoted 7 lines

Some versions of glibc and bionic report the same PID for parent and child when clone() is called with CLONE_VM but not CLONE_THREAD. This can cause cleanup to be incorrectly run by the child.

Avoid this by using a direct syscall for getpid when running the cleanup.

Pushed.

Thanks,
Jan