diff options
author | deischen <deischen@FreeBSD.org> | 2006-03-06 05:02:28 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 2006-03-06 05:02:28 +0000 |
commit | 6401ef60bd59c05126a12e332c4d5013372c9e34 (patch) | |
tree | 66e0ad6cb27877bf851261f4ff6ba3a77b571418 /lib/libpthread | |
parent | ea2809ea3b33504640ada4abf4cfc29d33e3cbb0 (diff) | |
download | FreeBSD-src-6401ef60bd59c05126a12e332c4d5013372c9e34.zip FreeBSD-src-6401ef60bd59c05126a12e332c4d5013372c9e34.tar.gz |
Only catch SIGINFO (for dumping thread states) when LIBPTHREAD_DEBUG
is defined in the environment.
Requested by: jmg & a few others
Diffstat (limited to 'lib/libpthread')
-rw-r--r-- | lib/libpthread/thread/thr_init.c | 2 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_private.h | 1 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_sig.c | 41 |
3 files changed, 28 insertions, 16 deletions
diff --git a/lib/libpthread/thread/thr_init.c b/lib/libpthread/thread/thr_init.c index 7945ed9..ac04336 100644 --- a/lib/libpthread/thread/thr_init.c +++ b/lib/libpthread/thread/thr_init.c @@ -518,6 +518,8 @@ init_private(void) else if (getenv("LIBPTHREAD_PROCESS_SCOPE") != NULL) _thread_scope_system = -1; #endif + if (getenv("LIBPTHREAD_DEBUG") != NULL) + _thr_debug_flags |= DBG_INFO_DUMP; /* * _thread_list_lock and _kse_count are initialized diff --git a/lib/libpthread/thread/thr_private.h b/lib/libpthread/thread/thr_private.h index e2055bc..9d8ee63 100644 --- a/lib/libpthread/thread/thr_private.h +++ b/lib/libpthread/thread/thr_private.h @@ -82,6 +82,7 @@ #define DBG_MUTEX 0x0001 #define DBG_SIG 0x0002 +#define DBG_INFO_DUMP 0x0004 #ifdef _PTHREADS_INVARIANTS #define THR_ASSERT(cond, msg) do { \ diff --git a/lib/libpthread/thread/thr_sig.c b/lib/libpthread/thread/thr_sig.c index ec6ebd5..f53b87f 100644 --- a/lib/libpthread/thread/thr_sig.c +++ b/lib/libpthread/thread/thr_sig.c @@ -98,6 +98,12 @@ static int sigproptbl[NSIG] = { #define DBG_MSG(x...) #endif +static __inline int +_thr_dump_enabled(void) +{ + return ((_thr_debug_flags & DBG_INFO_DUMP) != 0); +} + /* * Signal setup and delivery. * @@ -253,7 +259,7 @@ _thr_sig_dispatch(struct kse *curkse, int sig, siginfo_t *info) DBG_MSG(">>> _thr_sig_dispatch(%d)\n", sig); /* Check if the signal requires a dump of thread information: */ - if (sig == SIGINFO) { + if (_thr_dump_enabled() && (sig == SIGINFO)) { /* Dump thread information to file: */ _thread_dump_info(); } @@ -347,7 +353,7 @@ _thr_sig_handler(int sig, siginfo_t *info, ucontext_t *ucp) } /* Check if the signal requires a dump of thread information: */ - if (sig == SIGINFO) { + if (_thr_dump_enabled() && (sig == SIGINFO)) { /* Dump thread information to file: */ _thread_dump_info(); } @@ -521,7 +527,7 @@ handle_signal(struct pthread *curthread, struct sighandle_info *shi) _kse_critical_leave(&curthread->tcb->tcb_tmbx); /* Check if the signal requires a dump of thread information: */ - if (shi->sig == SIGINFO) { + if (_thr_dump_enabled() && (shi->sig == SIGINFO)) { /* Dump thread information to file: */ _thread_dump_info(); } @@ -1200,21 +1206,24 @@ _thr_signal_init(void) __sys_sigaction(i, &act, NULL); } } - /* - * Install the signal handler for SIGINFO. It isn't - * really needed, but it is nice to have for debugging - * purposes. - */ - _thread_sigact[SIGINFO - 1].sa_flags = SA_SIGINFO | SA_RESTART; - SIGEMPTYSET(act.sa_mask); - act.sa_flags = SA_SIGINFO | SA_RESTART; - act.sa_sigaction = (__siginfohandler_t *)&_thr_sig_handler; - if (__sys_sigaction(SIGINFO, &act, NULL) != 0) { - __sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL); + if (_thr_dump_enabled()) { /* - * Abort this process if signal initialisation fails: + * Install the signal handler for SIGINFO. It isn't + * really needed, but it is nice to have for debugging + * purposes. */ - PANIC("Cannot initialize signal handler"); + _thread_sigact[SIGINFO - 1].sa_flags = SA_SIGINFO | SA_RESTART; + SIGEMPTYSET(act.sa_mask); + act.sa_flags = SA_SIGINFO | SA_RESTART; + act.sa_sigaction = (__siginfohandler_t *)&_thr_sig_handler; + if (__sys_sigaction(SIGINFO, &act, NULL) != 0) { + __sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, + NULL); + /* + * Abort this process if signal initialisation fails: + */ + PANIC("Cannot initialize signal handler"); + } } __sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL); __sys_sigaltstack(NULL, &_thr_initial->sigstk); |