From 1a1e2a8c63768fe023a768696c77c4dec823b18d Mon Sep 17 00:00:00 2001 From: compudj Date: Thu, 26 Jan 2006 22:32:41 +0000 Subject: [PATCH] signals ok git-svn-id: http://ltt.polymtl.ca/svn@1497 04897980-b3bd-0310-b5e0-8ef037075253 --- usertrace/lttng_usertrace.c | 59 +++++++++++++++++++++---------------- usertrace/lttng_usertrace.h | 3 ++ usertrace/test.c | 4 +++ 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/usertrace/lttng_usertrace.c b/usertrace/lttng_usertrace.c index 7f1039f4..51204181 100644 --- a/usertrace/lttng_usertrace.c +++ b/usertrace/lttng_usertrace.c @@ -71,8 +71,8 @@ void __lttng_sig_trace_handler(int signo) int ret; sigset_t set, oldset; - printf("LTTng Sig handler : pid : %lu\n", getpid()); - + printf("LTTng signal handler : thread id : %lu, pid %lu\n", pthread_self(), getpid()); +#if 0 /* Disable signals */ ret = sigfillset(&set); if(ret) { @@ -85,7 +85,7 @@ void __lttng_sig_trace_handler(int signo) printf("Error in sigprocmask\n"); exit(1); } - +#endif //0 /* Get all the new traces */ #if 0 do { @@ -99,40 +99,22 @@ void __lttng_sig_trace_handler(int signo) } while(addr); #endif //0 + +#if 0 /* Enable signals */ ret = sigprocmask(SIG_SETMASK, &oldset, NULL); if(ret) { printf("Error in sigprocmask\n"); exit(1); } - +#endif //0 } -void __lttng_init_trace_info(void) -{ - memset(<tng_trace_info, 0, MAX_TRACES*sizeof(struct lttng_trace_info)); -} - -void __attribute__((constructor)) __lttng_user_init(void) +static void thread_init(void) { - static struct sigaction act; int err; - printf("LTTng user init\n"); - - /* Init trace info */ - __lttng_init_trace_info(); - - /* Activate the signal */ - act.sa_handler = __lttng_sig_trace_handler; - err = sigemptyset(&(act.sa_mask)); - if(err) perror("Error with sigemptyset"); - err = sigaddset(&(act.sa_mask), SIGRTMIN+3); - if(err) perror("Error with sigaddset"); - err = sigaction(SIGRTMIN+3, &act, NULL); - if(err) perror("Error with sigaction"); - /* TEST */ err = ltt_switch((unsigned long)NULL); if(err) { @@ -153,7 +135,34 @@ void __attribute__((constructor)) __lttng_user_init(void) printf("Error in ltt_switch system call\n"); exit(1); } +} + +void __attribute__((constructor)) __lttng_user_init(void) +{ + static struct sigaction act; + int err; + + printf("LTTng user init\n"); + + /* Activate the signal */ + act.sa_handler = __lttng_sig_trace_handler; + err = sigemptyset(&(act.sa_mask)); + if(err) perror("Error with sigemptyset"); + err = sigaddset(&(act.sa_mask), SIGRTMIN+3); + if(err) perror("Error with sigaddset"); + err = sigaction(SIGRTMIN+3, &act, NULL); + if(err) perror("Error with sigaction"); + thread_init(); +} +void lttng_thread_init(void) +{ + thread_init(); } + + + + + diff --git a/usertrace/lttng_usertrace.h b/usertrace/lttng_usertrace.h index b4aa8f3b..944e8a0f 100644 --- a/usertrace/lttng_usertrace.h +++ b/usertrace/lttng_usertrace.h @@ -26,6 +26,9 @@ void __lttng_sig_trace_handler(int signo); +/* Call this at the beginning of a new thread, except for the main() */ +void lttng_thread_init(void); + static inline _syscall1(int, ltt_switch, unsigned long, addr) static inline _syscall3(int, ltt_update, unsigned long, addr, int *, active, int *, filter) diff --git a/usertrace/test.c b/usertrace/test.c index 9c772973..a0509a27 100644 --- a/usertrace/test.c +++ b/usertrace/test.c @@ -10,6 +10,7 @@ void *thr1(void *arg) { + lttng_thread_init(); printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid()); while(1) {} @@ -20,6 +21,8 @@ void *thr1(void *arg) void *thr2(void *arg) { + lttng_thread_init(); + while(1) { printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid()); sleep(2); @@ -34,6 +37,7 @@ int main() pthread_t tid1, tid2; void *tret; + printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid()); err = pthread_create(&tid1, NULL, thr1, NULL); if(err!=0) exit(1); -- 2.34.1