From owner-freebsd-threads@FreeBSD.ORG Fri Jun 9 12:45:17 2006 Return-Path: X-Original-To: threads@freebsd.org Delivered-To: freebsd-threads@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D201116A419; Fri, 9 Jun 2006 12:45:17 +0000 (UTC) (envelope-from maxim@macomnet.ru) Received: from mp2.macomnet.net (mp2.macomnet.net [195.128.64.6]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5BF9043D73; Fri, 9 Jun 2006 12:45:17 +0000 (GMT) (envelope-from maxim@macomnet.ru) Received: from localhost (localhost [127.0.0.1]) by mp2.macomnet.net (8.13.4/8.13.3) with ESMTP id k59Cj6Ro049173; Fri, 9 Jun 2006 16:45:07 +0400 (MSD) (envelope-from maxim@macomnet.ru) Date: Fri, 9 Jun 2006 16:45:06 +0400 (MSD) From: Maxim Konovalov To: Daniel Eischen In-Reply-To: Message-ID: <20060609164120.X11643@mp2.macomnet.net> References: <200606071906.25776.mi+mx@aldan.algebra.com> <200606071916.38538.mi+mx@aldan.algebra.com> <20060608081626.X6097@mp2.macomnet.net> <200606081218.17131.mi+mx@aldan.algebra.com> <20060608213618.O17062@mp2.macomnet.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=KOI8-R Content-Transfer-Encoding: 8BIT Cc: threads@freebsd.org, Mikhail Teterin Subject: Re: SIGINFO and pthreads X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Jun 2006 12:45:18 -0000 Daniel, On Thu, 8 Jun 2006, 18:52-0400, Daniel Eischen wrote: > On Thu, 8 Jun 2006, Maxim Konovalov wrote: > > > On Thu, 8 Jun 2006, 12:18-0400, Mikhail Teterin wrote: > > > > > ÞÅÔ×ÅÒ 08 ÞÅÒ×ÅÎØ 2006 00:17, Maxim Konovalov ÎÁÐÉÓÁ×: > > > > Inline it if it's small. šMailman strips most attachments. > > > > > > Damn... Yes, it is small -- this is just a demo program. Compile it first > > > as > > > > > > cc -o t t.c > > > > > > Then -- run and try various keyboard signals like Ctrl-C, Ctrl-Z, > > > Ctrl-T (SIGINFO), or Ctrl-\. (It will not quit on its own, you'll > > > have to kill it from another prompt.) > > > > > > They will all work. Then -- recompile as > > > > > > cc -o t -pthread t.c > > > > > > And run... This time around it will ignore the Ctrl-T, while > > > continuing to respond to others. > > > > > > > libpthread uses SIGINFO for dumping thread information to a file but > > > > looking over the code it seems it does allow to use SIGINFO to the > > > > app. > > > > > > I'd like to be able to disable the debugging feature or, at least, > > > force it to call my signal-handler AS EXPECTED AND DOCUMENTED, after > > > it is done with its own dumping. > > > > A funny thing your test program does work if you run it as > > > > LIBPTHREAD_DEBUG=yes ./t > > > > Try this patch: > > [ ... ] > > > For the first glance and quick test this check is not needed as we > > dump threads in already installed for SIGINFO _thr_sig_handler(). Of > > course we need our libpthreads experts review. > > Yes, that is a correct patch (remove the commented out section). > Please go ahead and commit! There is still a problem if user decided to SIG_IGN or SIG_DFL SIGINFO. In this case threads dump stops working. I don't know how important this fuctionality is so here is a more aggressive patch: Index: thread/thr_private.h =================================================================== RCS file: /home/ncvs/src/lib/libpthread/thread/thr_private.h,v retrieving revision 1.126 diff -u -p -r1.126 thr_private.h --- thread/thr_private.h 29 Mar 2006 05:38:19 -0000 1.126 +++ thread/thr_private.h 9 Jun 2006 12:17:51 -0000 @@ -1317,4 +1317,11 @@ int __sys_poll(struct pollfd *, unsigne int __sys_msync(void *, size_t, int); #endif +static __inline int +_thr_dump_enabled(void) +{ + + return ((_thr_debug_flags & DBG_INFO_DUMP) != 0); +} + #endif /* !_THR_PRIVATE_H */ Index: thread/thr_sig.c =================================================================== RCS file: /home/ncvs/src/lib/libpthread/thread/thr_sig.c,v retrieving revision 1.84 diff -u -p -r1.84 thr_sig.c --- thread/thr_sig.c 6 Mar 2006 05:02:28 -0000 1.84 +++ thread/thr_sig.c 9 Jun 2006 12:18:15 -0000 @@ -98,12 +98,6 @@ 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. * Index: thread/thr_sigaction.c =================================================================== RCS file: /home/ncvs/src/lib/libpthread/thread/thr_sigaction.c,v retrieving revision 1.23 diff -u -p -r1.23 thr_sigaction.c --- thread/thr_sigaction.c 13 Mar 2006 00:59:51 -0000 1.23 +++ thread/thr_sigaction.c 9 Jun 2006 12:40:31 -0000 @@ -75,7 +75,7 @@ _sigaction(int sig, const struct sigacti * Check if the kernel needs to be advised of a change * in signal action: */ - if (act != NULL && sig != SIGINFO) { + if (act != NULL) { newact.sa_flags |= SA_SIGINFO; @@ -91,6 +91,16 @@ _sigaction(int sig, const struct sigacti */ newact.sa_handler = (void (*) ())_thr_sig_handler; } + /* + * Install libpthread signal handler wrapper + * for SIGINFO signal if threads dump enabled + * even if a user set the signal handler to + * SIG_DFL or SIG_IGN. + */ + if (sig == SIGINFO && _thr_dump_enabled()) { + newact.sa_handler = + (void (*) ())_thr_sig_handler; + } /* Change the signal action in the kernel: */ if (__sys_sigaction(sig, &newact, NULL) != 0) { _thread_sigact[sig - 1] = oldact; %%% -- Maxim Konovalov