* signal handling issue.
@ 2004-05-19 5:45 Alex Davis
2004-05-19 6:18 ` Ulrich Drepper
2004-05-19 11:39 ` Richard B. Johnson
0 siblings, 2 replies; 5+ messages in thread
From: Alex Davis @ 2004-05-19 5:45 UTC (permalink / raw)
To: linux-kernel
There appears to be a change between linux 2.4 and 2.6
in how signals are handled. As a test, I wrote the program
below:
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
static jmp_buf env;
static void handler(int s) {
printf("caught signal %d\n", s);
longjmp(env, 1);
}
int main() {
int * p = 0;
printf("write\n");
signal(SIGSEGV, handler);
if ( ! setjmp(env) )
{
*p = 0;
}
printf("read\n");
signal(SIGSEGV, handler);
if ( ! setjmp(env) )
{
int a = *p;
}
return 0;
}
When run on 2.4.26, the program prints:
write
caught signal 11
read
caught signal 11
Which (I think) is expected, but when run on 2.6.5,
the program prints:
write
caught signal 11
read
Segmentation fault
It's as if the second call to signal is being ignored.
Is this a bug or a feature?
-Alex
=====
I code, therefore I am
__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: signal handling issue.
2004-05-19 5:45 signal handling issue Alex Davis
@ 2004-05-19 6:18 ` Ulrich Drepper
2004-05-19 11:39 ` Richard B. Johnson
1 sibling, 0 replies; 5+ messages in thread
From: Ulrich Drepper @ 2004-05-19 6:18 UTC (permalink / raw)
To: Alex Davis; +Cc: linux-kernel
Fix your code:
> static void handler(int s) {
> printf("caught signal %d\n", s);
> longjmp(env, 1);
> }
Use siglonjmp() and sigsetjmp(). You are not allowed to use longjmp()
to jump from a signal handler.
[How many times have I explained this here now?]
--
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: signal handling issue.
2004-05-19 5:45 signal handling issue Alex Davis
2004-05-19 6:18 ` Ulrich Drepper
@ 2004-05-19 11:39 ` Richard B. Johnson
1 sibling, 0 replies; 5+ messages in thread
From: Richard B. Johnson @ 2004-05-19 11:39 UTC (permalink / raw)
To: Alex Davis; +Cc: linux-kernel
On Tue, 18 May 2004, Alex Davis wrote:
> There appears to be a change between linux 2.4 and 2.6
> in how signals are handled. As a test, I wrote the program
> below:
>
> #include <stdio.h>
> #include <signal.h>
> #include <setjmp.h>
>
> static jmp_buf env;
>
> static void handler(int s) {
> printf("caught signal %d\n", s);
> longjmp(env, 1);
> }
[SNIPPED...]
A a couple years ago they changed the rules. You can't longjmp
from a signal handler anymore. There's some other function
call with 'sig' in it, like siglongjmp or something like
that. Ahh... here it is:
/usr/include/setjmp.h:extern void siglongjmp __P ((sigjmp_buf __env, int __val))
Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5557.45 BogoMips).
Note 96.31% of all statistics are fiction.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: signal handling issue.
@ 2004-05-19 5:56 Alex Davis
0 siblings, 0 replies; 5+ messages in thread
From: Alex Davis @ 2004-05-19 5:56 UTC (permalink / raw)
To: linux-kernel
Some additional info: the 2.6.5 system has gcc 3.3.3,
the 2.4.26 system has gcc 3.3.1. Both systems have
glibc 2.3.2.
-Alex
=====
I code, therefore I am
__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: signal handling issue.
@ 2004-05-19 6:56 Alex Davis
0 siblings, 0 replies; 5+ messages in thread
From: Alex Davis @ 2004-05-19 6:56 UTC (permalink / raw)
To: linux-kernel
>Use siglonjmp() and sigsetjmp(). You are not allowed to use longjmp()
>to jump from a signal handler.
Is this documented anywhere??
=====
I code, therefore I am
__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-05-19 11:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-19 5:45 signal handling issue Alex Davis
2004-05-19 6:18 ` Ulrich Drepper
2004-05-19 11:39 ` Richard B. Johnson
-- strict thread matches above, loose matches on Subject: below --
2004-05-19 5:56 Alex Davis
2004-05-19 6:56 Alex Davis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox