From owner-freebsd-hackers@FreeBSD.ORG Fri Nov 22 18:39:53 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 117E0145; Fri, 22 Nov 2013 18:39:53 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 842552652; Fri, 22 Nov 2013 18:39:52 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.7/8.14.7) with ESMTP id rAMIdgQ8044050; Fri, 22 Nov 2013 20:39:42 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua rAMIdgQ8044050 Received: (from kostik@localhost) by tom.home (8.14.7/8.14.7/Submit) id rAMIdgnB044049; Fri, 22 Nov 2013 20:39:42 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 22 Nov 2013 20:39:42 +0200 From: Konstantin Belousov To: Jilles Tjoelker Subject: Re: Problem with signal 0 being delivered to SIGUSR1 handler Message-ID: <20131122183942.GB59496@kib.kiev.ua> References: <528DFEE6.6020504@gmail.com> <20131121211546.GQ59496@kib.kiev.ua> <20131122133553.GA28457@stack.nl> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="rmx1G5GNWS01lHd9" Content-Disposition: inline In-Reply-To: <20131122133553.GA28457@stack.nl> User-Agent: Mutt/1.5.22 (2013-10-16) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: freebsd-hackers@freebsd.org, threads@freebsd.org, Vitaly Magerya , davidxu@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Nov 2013 18:39:53 -0000 --rmx1G5GNWS01lHd9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Nov 22, 2013 at 02:35:53PM +0100, Jilles Tjoelker wrote: > This analysis suggests an easier approach: just move the check for > deferred_siginfo.si_signo =3D=3D 0 downward. If __fillcontextx2 or sysarch > need to be looked up by rtld, the resulting _thr_ast() will invoke the > signal handler and the original call to check_deferred_signal() will do > nothing. >=20 > This patch fixes the problem for me on stable/9 and head. >=20 > Index: lib/libthr/thread/thr_sig.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- lib/libthr/thread/thr_sig.c (revision 258178) > +++ lib/libthr/thread/thr_sig.c (working copy) > @@ -326,12 +326,12 @@ check_deferred_signal(struct pthread *curthread) > uc_len =3D __getcontextx_size(); > uc =3D alloca(uc_len); > getcontext(uc); > - if (curthread->deferred_siginfo.si_signo =3D=3D 0) > - return; > __fillcontextx2((char *)uc); > act =3D curthread->deferred_sigact; > uc->uc_sigmask =3D curthread->deferred_sigmask; > memcpy(&info, &curthread->deferred_siginfo, sizeof(siginfo_t)); > + if (curthread->deferred_siginfo.si_signo =3D=3D 0) > + return; > /* remove signal */ > curthread->deferred_siginfo.si_signo =3D 0; > handle_signal(&act, info.si_signo, &info, uc); >=20 I do not like this. It is similar to what I did initially when I debugged the problem, but the duplicated calls to getcontext(2) and sysarch(2) stayed out as a sore in ktrace. I also do not like the fact that, with the change, signal is delivered from an rtld context. If taking such road, the fix would be to add __fillcontext2() to _rtld_init(), but I described the reason for other fix in the initial response. --rmx1G5GNWS01lHd9 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iQIcBAEBAgAGBQJSj6TtAAoJEJDCuSvBvK1BOSkQAIgX0yy3jpTylGEV1X5BfvRt SkbpN+JlzSgUTMKGrnA0qt03SQE2JZp9rHS+b8qPEgDuXG/P76pz10rqcMF+3wv3 4Xs9yiv0r4kRv9Blw7d5tvsXi1HH9sF8hPmj2TbL2rJ1qOv4hacg5LLvocyZZ4oz yyL5WRB6XwQTW3Ax8BXSMuxLvHA4P2PAQ6CxG2283O1WQrOHELroLGTeS1nCvjaI irefCxx5lXWS3HYi6NxkV6MWIBYI7e57tLZNAKJnF5FDT8bWw/0hqR1/8Jpp/80Y vEs/56f1yNzJibzTS84NmZ5iW5KsKC4NR/Oq3AyRgZQ65C6Du2oOyHgjDW7o6a+i JznvcXVGA4TlF0m2e0zoXAhG0uHtxKZaHeDm8MBrR2ghZY2w1o2IHxIW944yzzY4 wkHT3i2WsMVkpPqyIMr2Zb4Z/tKf9bnthk3K3+JnTbSJDnvpzU2xIU3B1iosmXM2 GRKBCwzD36MzJ0MBZWbSWtpdJZDcS+qZVyJviq3TKsqd0Tfbr+08LtkXJ8w+3gDV de4RMbNc9cqN9hq+mvvTxdZKUd4nFYuwZXx0qyUxZequ16tYpUfAXlnaVco6vYAS 5fFc1ztq+lVhjkLnGeW+SE1q4Alju6cgAnf25XUo+7W3ZEtC+DxXnrtuptpzcJ3X XZLeWMJ+5fuwTle9w9SP =pWVY -----END PGP SIGNATURE----- --rmx1G5GNWS01lHd9--