[Pkg-scicomp-devel] Bug#494031: Signal handlers not working?

Jurij Smakov jurij at wooyd.org
Tue Aug 26 20:50:54 UTC 2008


I dug a little bit into the code and it seems that the problem is 
caused by this macro defined in Utilities/hdf5/H5detect.c:

#if defined(H5_HAVE_LONGJMP) && defined(H5_HAVE_SIGNAL)
#define ALIGNMENT(TYPE,INFO) {                  \
    char    *volatile _buf=NULL;              \
    volatile TYPE  _val=1;                  \
    volatile TYPE  _val2;                  \
    volatile size_t  _ano=0;                  \
    void    (*_handler)(int) = signal(SIGBUS, sigbus_handler);    \
    void    (*_handler2)(int) = signal(SIGSEGV, sigsegv_handler);  \
    _buf = (char*)malloc(sizeof(TYPE)+align_g[NELMTS(align_g)-1]);          \
    if (setjmp(jbuf_g)) _ano++;                  \
    if (_ano<NELMTS(align_g)) {                  \
  *((TYPE*)(_buf+align_g[_ano])) = _val; /*possible SIGBUS or SEGSEGV*/  \
  _val2 = *((TYPE*)(_buf+align_g[_ano]));  /*possible SIGBUS or SEGSEGV*/  \

It tries to set the signal handlers for SIGBUS and SIGSEGV and then 
try various casts in an attempt to detect the alignment requirements. 
So, SIGBUS/SIGSEGV appears to be intentional, except that they are 
supposed to be caught by signal handlers, and not terminate the build. 
The signal(2) man page includes the following information:

       The only portable use of signal() is to set a signal's disposition to SIG_DFL or
       SIG_IGN.   The  semantics when using signal() to establish a signal handler vary
       across systems (and POSIX.1 explicitly permits this variation); do  not  use  it
       for this purpose.

Current theory is that setting signal handlers via signal() does not 
work in Debian for some reason. I'll try to rewrite this code using 
sigaction interface to see if it helps.

Jurij Smakov                                           jurij at wooyd.org
Key: http://www.wooyd.org/pgpkey/                      KeyID: C99E03CC

More information about the Pkg-scicomp-devel mailing list