Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame^] | 1 | From e747d0456adc080a1d31fb653bda9dc491795c80 Mon Sep 17 00:00:00 2001 |
| 2 | From: Jan Stancek <jstancek@redhat.com> |
| 3 | Date: Sun, 16 Jun 2019 11:14:16 +0200 |
| 4 | Subject: [PATCH] syscalls/tgkill03: wait for defunct tid to get detached |
| 5 | |
| 6 | Case where defunct tid is used has been observed to sporadically fail: |
| 7 | tgkill03.c:96: FAIL: Defunct tid should have failed with ESRCH: SUCCESS |
| 8 | |
| 9 | glibc __pthread_timedjoin_ex() waits for CLONE_CHILD_CLEARTID to clear tid, |
| 10 | and then resumes. Kernel clears it (glibc pd->tid) at: |
| 11 | do_exit |
| 12 | exit_mm |
| 13 | mm_release |
| 14 | put_user(0, tsk->clear_child_tid); |
| 15 | |
| 16 | but kernel tid is still valid, presumably until: |
| 17 | release_task |
| 18 | __exit_signal |
| 19 | __unhash_process |
| 20 | detach_pid |
| 21 | |
| 22 | To avoid race wait until /proc/<pid>/task/<tid> disappears. |
| 23 | |
| 24 | Signed-off-by: Jan Stancek <jstancek@redhat.com> |
| 25 | Reviewed-by: Li Wang <liwang@redhat.com> |
| 26 | Acked-by: Sumit Garg <sumit.garg@linaro.org> |
| 27 | |
| 28 | Upstream-Status: Backport |
| 29 | [https://github.com/linux-test-project/ltp/commit/e747d0456adc080a1d31fb653bda9dc491795c80] |
| 30 | |
| 31 | Signed-off-by: He Zhe <zhe.he@windriver.com> |
| 32 | --- |
| 33 | testcases/kernel/syscalls/tgkill/tgkill03.c | 6 +++++- |
| 34 | 1 file changed, 5 insertions(+), 1 deletion(-) |
| 35 | |
| 36 | diff --git a/testcases/kernel/syscalls/tgkill/tgkill03.c b/testcases/kernel/syscalls/tgkill/tgkill03.c |
| 37 | index f5bbdc5..593a217 100644 |
| 38 | --- a/testcases/kernel/syscalls/tgkill/tgkill03.c |
| 39 | +++ b/testcases/kernel/syscalls/tgkill/tgkill03.c |
| 40 | @@ -7,6 +7,7 @@ |
| 41 | |
| 42 | #include <pthread.h> |
| 43 | #include <pwd.h> |
| 44 | +#include <stdio.h> |
| 45 | #include <sys/types.h> |
| 46 | |
| 47 | #include "tst_safe_pthread.h" |
| 48 | @@ -42,6 +43,7 @@ static void setup(void) |
| 49 | { |
| 50 | sigset_t sigusr1; |
| 51 | pthread_t defunct_thread; |
| 52 | + char defunct_tid_path[PATH_MAX]; |
| 53 | |
| 54 | sigemptyset(&sigusr1); |
| 55 | sigaddset(&sigusr1, SIGUSR1); |
| 56 | @@ -55,8 +57,9 @@ static void setup(void) |
| 57 | TST_CHECKPOINT_WAIT(0); |
| 58 | |
| 59 | SAFE_PTHREAD_CREATE(&defunct_thread, NULL, defunct_thread_func, NULL); |
| 60 | - |
| 61 | SAFE_PTHREAD_JOIN(defunct_thread, NULL); |
| 62 | + sprintf(defunct_tid_path, "/proc/%d/task/%d", getpid(), defunct_tid); |
| 63 | + TST_RETRY_FN_EXP_BACKOFF(access(defunct_tid_path, R_OK), -1, 15); |
| 64 | } |
| 65 | |
| 66 | static void cleanup(void) |
| 67 | @@ -108,4 +111,5 @@ static struct tst_test test = { |
| 68 | .setup = setup, |
| 69 | .cleanup = cleanup, |
| 70 | .test = run, |
| 71 | + .timeout = 20, |
| 72 | }; |
| 73 | -- |
| 74 | 2.7.4 |
| 75 | |