Hola,
I'm not sure if the subject line is worded correctly, but chasing
another problem I noticed that a thread (e.g., main thread) after call
to pthread_join() isn't interrupted to handle signals.
Same .c file on another OS works as expected.
Is my expectation or .c file incorrect, or is this a bug in OpenBSD?
I expect after compiling following .c file, and running the resulting
executable, to be able to ^C and have it nicely quit.
--patrick
$ cat foo.c
#include <sys/types.h>
#include <err.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int quit;
/* prototypes */
void sigh(int);
void *thr1(void*);
void
sigh(int sig)
{
quit = 1;
printf("Caught signal:%d\n", sig);
}
void*
thr1(void *arg)
{
sigset_t mask;
sigfillset(&mask);
if (0 != pthread_sigmask(SIG_SETMASK, &mask, NULL))
err(1, "pthread_sigmask()");
while (!quit) {
fprintf(stderr, ".");
sleep(1);
}
pthread_exit(NULL);
}
int
main(int argc, char *argv[])
{
void *prc;
pthread_t a;
struct sigaction sa;
bzero(&sa, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_handler = sigh;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
if (0 != pthread_create(&a, NULL, &thr1, NULL))
err(1, "pthread_create()");
#ifdef HACKAROUND // XXX
// Compiling this bit in allows signal handler to
// be invoked upon receiving desired signals.
while (!quit)
sleep(1);
#endif
if (0 != pthread_join(a, &prc))
err(1, "pthread_join()");
free(prc);
exit(0);
}
$ cc -g -O0 -pthread foo.c -o foo
$ ./foo
..^C.^C^C..^\Quit (core dumped)
$ cc -g -O0 -pthread foo.c -o foo -DHACKAROUND
$ ./foo
...^CCaught signal:2
$ sysctl kern.version
kern.version=OpenBSD 4.8-beta (GENERIC) #84: Tue Aug 3 10:03:35 MDT 2010
[email protected]:/usr/src/sys/arch/macppc/compile/GENERIC