Properly fail with ESRCH when pthread_killing an exited thread.
Previously, we were callign tgkill(pid, 0, signal) instead, which would
fail with EINVAL instead.
Test: bionic-unit-tests
Change-Id: I25b127dcf347e0223274502b0516a950b6c2093e
diff --git a/libc/bionic/pthread_kill.cpp b/libc/bionic/pthread_kill.cpp
index 3761a75..1531574 100644
--- a/libc/bionic/pthread_kill.cpp
+++ b/libc/bionic/pthread_kill.cpp
@@ -36,7 +36,9 @@
ErrnoRestorer errno_restorer;
pid_t tid = pthread_gettid_np(t);
- if (tid == -1) return ESRCH;
+
+ // tid gets reset to 0 on thread exit by CLONE_CHILD_CLEARTID.
+ if (tid == 0 || tid == -1) return ESRCH;
return (tgkill(getpid(), tid, sig) == -1) ? errno : 0;
}