From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tvrtko Ursulin Subject: [PATCH 2/2] drmtest: Avoid wrong PID/TID after clone races Date: Tue, 3 Dec 2013 16:44:55 +0000 Message-ID: <1386089095-9966-3-git-send-email-tvrtko.ursulin@linux.intel.com> References: <1386089095-9966-1-git-send-email-tvrtko.ursulin@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 1A052FB498 for ; Tue, 3 Dec 2013 08:45:25 -0800 (PST) In-Reply-To: <1386089095-9966-1-git-send-email-tvrtko.ursulin@linux.intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org To: Intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org From: Tvrtko Ursulin Various C library implementations have various races with regards to caching getpid() or TID inside pthread_kill() implementations. For example see clone(2) glibc man page and pthread_kill Bionic C library source. Work around that by making sure correct PID/TGID and TID values are retrieved from the kernel when re-raising the signal. It can be delivered immediately after the clone system call while C library cached copies have not yet been updated. Signed-off-by: Tvrtko Ursulin --- lib/drmtest.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/drmtest.c b/lib/drmtest.c index dcacd3b..139eb82 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -43,6 +43,8 @@ #include #include #include +#include +#include #include "drmtest.h" #include "i915_drm.h" @@ -1473,6 +1475,8 @@ static void igt_atexit_handler(void) static void fatal_sig_handler(int sig) { + pid_t pid, tid; + restore_all_sig_handler(); /* @@ -1481,7 +1485,11 @@ static void fatal_sig_handler(int sig) */ call_exit_handlers(sig); - raise(sig); + /* Workaround cached PID and TID races on glibc and Bionic libc. */ + pid = syscall(SYS_getpid); + tid = syscall(SYS_gettid); + + syscall(SYS_tgkill, pid, tid, sig); } /* -- 1.8.4.3