signal handling issue.

Alex Davis
2004-05-19T06:04:49Z

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