[ltt-dev] UST use case: Tracing QEMU/KVM
Stefan Hajnoczi
stefanha at linux.vnet.ibm.com
Mon May 24 04:41:51 EDT 2010
/*
* This example demonstrates the UST listener thread receiving signals and
* returning from poll().
*
* $ gcc -o poll_eintr poll_eintr.c -lust -lpthread
* $ ./poll_eintr
* main thread id=0x7f9c31a766a0
* ^CSIGINT handled in thread id=0x7f9c30ed7910
* libust[2615/2616]: Error: poll: Interrupted system call (in multipoll_poll() at ../libustcomm/multipoll.c:84)
* libust[2615/2616]: Error: error in multipoll_poll (in listener_main() at tracectl.c:1015)
*
* This happens because all other threads have SIGINT blocked, whereas libust
* does not block signals in the client thread. Therefore the signal is
* handled in the client thread, poll() is interrupted, and an error is
* printed.
*
* I think the correct behavior is to block signals in the client thread so it
* will not interfere with signal handling of the main program.
*/
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
static void sigint_handler(int signo)
{
fprintf(stderr, "SIGINT handled in thread id=0x%lx\n", pthread_self());
}
int main(int argc, char **argv)
{
sigset_t newmask;
fprintf(stderr, "main thread id=0x%lx\n", pthread_self());
/* Block SIGINT in this thread */
sigemptyset(&newmask);
sigaddset(&newmask, SIGINT);
pthread_sigmask(SIG_SETMASK, &newmask, NULL);
/* Set up a handler for SIGINT */
signal(SIGINT, sigint_handler);
/* Now wait for signals, the UST listener thread will receive it */
for (;;) {
pause();
fprintf(stderr, "pause returned in main thread\n");
}
return 0;
}
More information about the lttng-dev
mailing list