Problem with signal 0 being delivered to SIGUSR1 handler

Vitaly Magerya vmagerya at gmail.com
Thu Nov 21 12:39:09 UTC 2013


Hi, folks. I'm investigating a test case failure that devel/boehm-gc
has on recent FreeBSD releases. The problem is that a signal
handler registered for SIGUSR1 is sometimes called with signum=0,
which should not be possible under any conditions.

Here's a simple test case that demonstrates this behavior:

/* Compile with 'c99 -o example example.c -pthread'
 */
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

void signal_handler(int signum, siginfo_t *si, void *context) {
    if (signum != SIGUSR1) {
        printf("bad signal, signum=%d\n", signum);
        exit(1);
    }
}

void *thread_func(void *arg) {
    return arg;
}

int main(void) {
    struct sigaction sa = { 0 };
    sa.sa_flags = SA_SIGINFO;
    sa.sa_sigaction = signal_handler;
    if (sigfillset(&sa.sa_mask) != 0) abort();
    if (sigaction(SIGUSR1, &sa, NULL) != 0) abort();
    for (int i = 0; i < 10000; i++) {
        pthread_t t;
        pthread_create(&t, NULL, thread_func, NULL);
        pthread_kill(t, SIGUSR1);
    }
    return 0;
}

Under FreeBSD 9.2-RELEASE amd64 I pretty consistently get
"signum=0" from this program, but you may need to run it a few
times or increase the number of iterations to see the same.

Interestingly enough, I don't see this behavior under 9.0-RELEASE.

So, any ideas what the problem here is?


More information about the freebsd-hackers mailing list