Re: Signals and threads



Hi all..

I figured out the problem.
It was on the pthread library.
In pthread lib sigaction function is overloaded with __sigaction
function.
this is the function which is getting called when u link with pthread
lib
If we examine this function

int __sigaction(int sig, const struct sigaction * act,
struct sigaction * oact)
{
struct sigaction newact;
struct sigaction *newactp;

#ifdef DEBUG_PT
printf(__FUNCTION__": pthreads wrapper!\n");
#endif
if (sig == __pthread_sig_restart ||
sig == __pthread_sig_cancel ||
(sig == __pthread_sig_debug && __pthread_sig_debug > 0))
return EINVAL;
if (act)
{
newact = *act;
if (act->sa_handler != SIG_IGN && act->sa_handler != SIG_DFL
&& sig > 0 && sig < NSIG)
{
if (act->sa_flags & SA_SIGINFO)
newact.sa_handler = (__sighandler_t) pthread_sighandler_rt;
else



next line is the culprit which reassigns a new handler other than user provided handler<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<,
newact.sa_handler = (__sighandler_t) pthread_sighandler;
}
newactp = &newact;
}
else
newactp = NULL;
if (__libc_sigaction(sig, newactp, oact) == -1)
return -1;
#ifdef DEBUG_PT
printf(__FUNCTION__": signahdler installed, __sigaction successful\n");
#endif
if (sig > 0 && sig < NSIG)
{
if (oact != NULL)
oact->sa_handler = (__sighandler_t) sighandler[sig].old;
if (act)
/* For the assignment is does not matter whether it's a normal
or real-time signal. */
sighandler[sig].old = (arch_sighandler_t) act->sa_handler;
}
return 0;
}



If we examine further it is clear that pthead lib maintains a gblobal
array namely sighandler[sig].old

which is used to store the signalhandlers for all the therads. Also
there is only one handler per signal for all the process(i mean
therads). thats why the last registered signal handler is getting
called. Once again i thank everyone who had helped me to found a
solution for my problem.
reg
thomas

.