[LTP] [PATCH v3] tst_clone: Fix child detection on sparc
Anders Roxell
anders.roxell@linaro.org
Wed Sep 30 22:14:30 CEST 2026
On sparc the clone syscall returns the caller's thread id in the child,
not 0. So the child thinks it is the parent.
Compare with tst_gettid() in the clone fallback. clone3 returns 0, but
sparc only has it since v7.0.
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
v2 -> v3: use tst_gettid(), the kernel returns the caller's thread id
to the child. And only get it in the clone fallback, as the AI review
suggested.
v1 -> v2: fixed the AI review comments, use tst_getpid() since glibc
before 2.25 caches getpid(), and only check after clone, so the goto
is gone.
lib/tst_clone.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/lib/tst_clone.c b/lib/tst_clone.c
index 296cd40ac0a0..a04c4042653b 100644
--- a/lib/tst_clone.c
+++ b/lib/tst_clone.c
@@ -35,6 +35,10 @@ pid_t tst_clone(const struct tst_clone_args *tst_args)
flags = args.exit_signal | args.flags;
+#ifdef __sparc__
+ pid_t tid = tst_gettid();
+#endif
+
#ifdef __s390x__
pid = syscall(__NR_clone, NULL, flags, args.pidfd, NULL, NULL);
#else
@@ -44,5 +48,10 @@ pid_t tst_clone(const struct tst_clone_args *tst_args)
if (pid == -1)
return -2;
+#ifdef __sparc__
+ if (pid == tid)
+ pid = 0;
+#endif
+
return pid;
}
--
2.53.0
More information about the ltp
mailing list