tst_clone: Fix child detection on sparc
PATCH 1/1 tst_clone: Fix child detection on sparc
On sparc the clone syscall does not return 0 in the child. It returns the parent pid, so the child thinks it is the parent.
Save the pid before the clone and compare it after.
--- lib/tst_clone.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
lib/tst_clone.c +10 -1
@@ -20,6 +20,9 @@ pid_t tst_clone(const struct tst_clone_args *tst_args) };int flags;pid_t pid =-1 ; +#ifdef __sparc__ +pid_t parent_pid =getpid (); +#endif tst_flush ();
@@ -31,7 +34,7 @@ pid_t tst_clone(const struct tst_clone_args *tst_args)return -1 ;if (pid !=-1 ) -return pid; + goto out; flags = args.exit_signal | args.flags;
@@ -44,5 +47,11 @@ pid_t tst_clone(const struct tst_clone_args *tst_args)if (pid ==-1 )return -2 ; +out: +#ifdef __sparc__ +if (getpid () != parent_pid) + pid =0 ; +#endif +return pid; }
Signature · 5 lines
2.53.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Anders,
lib/tst_clone.c pid_t tst_clone(const struct tst_clone_args *tst_args) · line 25
Quoted 5 lines · Anders Roxell
tst_clone: Fix child detection on sparclib/tst_clone.c +3
-0+#ifdef __sparc__ +pid_t parent_pid =getpid (); +#endif
Use tst_getpid() instead of getpid(). glibc versions prior to 2.25 cache getpid(), which returns a stale PID if tst_clone() is called from a child process created by a direct clone syscall.
lib/tst_clone.c pid_t tst_clone(const struct tst_clone_args *tst_args) · line 54
Quoted 5 lines
lib/tst_clone.c +5
-0+out: +#ifdef __sparc__ +if (getpid () != parent_pid) + pid =0 ; +#endif
Calling getpid() in the child returns the cached parent PID on glibc < 2.25 because the raw clone syscall bypasses glibc, causing child detection to fail. Use if (pid == parent_pid) pid = 0; instead, or use tst_getpid().
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp