Home > Archive > Unix Programming > February 2007 > Purify error in signal handler
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Purify error in signal handler
|
|
| Achint Mehta 2007-02-25, 4:07 am |
| Hi,
I am running purify on my program (with gcc ver. 3.4.6)
I have installed a signal handler (for timer) using sigaction.
I am passing a pointer (data) into the sival_ptr which I intend to
access later in the signal handler.
timer_event.sigev_notify = SIGEV_SIGNAL;
timer_event.sigev_signo = SIGRTMIN;
timer_event.sigev_value.sival_ptr = data;
sigfillset (&timer_action.sa_mask);
timer_action.sa_flags = SA_SIGINFO ; /* realtime signal */
timer_action.sa_sigaction = handle_download_retry;
sigaction (SIGRTMIN, &timer_action, NULL);
....
timer_create(...)
...
timer_settime(...)
When I access this pointer in the signal handler purify gives me
Memory Segment error (which means that I am accessing memory from some
other segment)
I was accessing the pointer as
void handle_download_retry (int sigval, siginfo_t *extra, void *what)
{
. . .
p_msgData->data = (void *)(extra->si_value.sival_ptr); /* MSE :
Memory segment error */
}
However, even if I change the
p_msgData->data = (void *)(extra->si_value.sival_ptr);
to
p_msgData->data = (void *)(extra);
even then I get the error which means that purify doesn't like "extra"
being accessed.
I tried some combinations such as
p_msgData->data = 10;
and I did not get the purify error.
So it seems that the error is because of accessing "extra".
Also, p_msgData is a pointer to a global variable.
Although the program does not dump core (with or without purify) but
can somebody tell me whether the signal handler code is correct ?
Thanks in advance.
Regards,
Achint
| |
| Martin Jost 2007-02-27, 7:09 pm |
|
"Achint Mehta" <achintmehta@gmail.com> schrieb im Newsbeitrag
news:1172384962.564466.165590@k78g2000cwa.googlegroups.com...
> I am running purify on my program (with gcc ver. 3.4.6)
> I have installed a signal handler (for timer) using sigaction.
> I am passing a pointer (data) into the sival_ptr which I intend to
> access later in the signal handler.
>
> timer_event.sigev_notify = SIGEV_SIGNAL;
> timer_event.sigev_signo = SIGRTMIN;
> timer_event.sigev_value.sival_ptr = data;
Where did you get "data" from ?
Is it correctely initialized ?
> sigfillset (&timer_action.sa_mask);
> timer_action.sa_flags = SA_SIGINFO ; /* realtime signal */
> timer_action.sa_sigaction = handle_download_retry;
> sigaction (SIGRTMIN, &timer_action, NULL);
Ok, so I assume, the handler isn't called, until the initializiation above
is complete.
> timer_create(...)
> ...
> timer_settime(...)
>
> When I access this pointer in the signal handler purify gives me
> Memory Segment error (which means that I am accessing memory from some
> other segment)
You know that the C-library isn't reentrant (at least not every function).
Because your signal handler can get preempted and than another call to your
signal handler can happen, while you're still inside the first call, all
sort of (very) ugly things can happen, if you call C library functions in
your signal handler.
> I was accessing the pointer as
> void handle_download_retry (int sigval, siginfo_t *extra, void *what)
> {
> . . .
> p_msgData->data = (void *)(extra->si_value.sival_ptr); /* MSE :
> Memory segment error */
>
> }
>
Here "extra" is of type siginfo_t.
Above I see
timer_event.sigev_value.sival_ptr = data;
Do the types match ?
Here the access is by 'si_value.sival_ptr', above the acces is by
'sigev_value.sival_ptr' - huh ?
Sorry, no concrete answer, just a bunch of random questions coming to mind
looking at your code...
HTH (nevertheless)
Martin
|
|
|
|
|