pthread_kill(0,0) Segmentation fault rather than ESRCH
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
glibc (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
The simple program:
#include <signal.h>
int
main (int arcg, char *argv[])
{
pthread_
return 0;
}
Gets "Segmentation fault". The man page says it should return ESRCH. Looking at the eglibc-2.19 source I found:
In ./nptl/
27
29 int
30 pthread_sigqueue (threadid, signo, value)
31 pthread_t threadid;
32 int signo;
33 const union sigval value;
34 {
35 #ifdef __NR_rt_
36 struct pthread *pd = (struct pthread *) threadid;
37
38 /* Make sure the descriptor is valid. */
39 if (DEBUGGING_P && INVALID_TD_P (pd))
40 /* Not a valid thread handle. */
41 return ESRCH;
42
and in ./nptl/
27 int
28 __pthread_kill (threadid, signo)
29 pthread_t threadid;
30 int signo;
31 {
32 struct pthread *pd = (struct pthread *) threadid;
33
34 /* Make sure the descriptor is valid. */
35 if (DEBUGGING_P && INVALID_TD_P (pd))
36 /* Not a valid thread handle. */
37 return ESRCH;
38
and in ./ports/
27 int
28 __pthread_kill (threadid, signo)
29 pthread_t threadid;
30 int signo;
31 {
32 struct pthread *pd = (struct pthread *) threadid;
33
34 /* Make sure the descriptor is valid. */
35 if (DEBUGGING_P && INVALID_TD_P (pd))
36 /* Not a valid thread handle. */
37 return ESRCH;
38
In all of these cases, the "DEBUGGING_P &&" causes the "INVALID_TD_P (pd)" test to not be generated, since DEBUGGING_P is #defined as 0. We need to do the test!
The Ubuntu man page for pthread_kill says:
If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a thread ID.
$ lsb_release -rd
Description: Ubuntu 14.04.3 LTS
Release: 14.04
$ apt-cache policy libc6
libc6:
Installed: 2.19-0ubuntu6.6
Candidate: 2.19-0ubuntu6.6
Version table:
*** 2.19-0ubuntu6.6 0
500 http://
500 http://
100 /var/lib/
2.19-0ubuntu6 0
500 http://