From owner-freebsd-threads@FreeBSD.ORG Mon Jun 28 14:05:44 2010 Return-Path: Delivered-To: threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CCA301065672; Mon, 28 Jun 2010 14:05:44 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 1BA938FC17; Mon, 28 Jun 2010 14:05:43 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id o5SE5YGp045279 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 28 Jun 2010 17:05:34 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4) with ESMTP id o5SE5YIL073172; Mon, 28 Jun 2010 17:05:34 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4/Submit) id o5SE5YwD073171; Mon, 28 Jun 2010 17:05:34 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 28 Jun 2010 17:05:34 +0300 From: Kostik Belousov To: John Baldwin Message-ID: <20100628140534.GZ13238@deviant.kiev.zoral.com.ua> References: <201006280833.54224.jhb@freebsd.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="jHgdI7OefoZoiA5t" Content-Disposition: inline In-Reply-To: <201006280833.54224.jhb@freebsd.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-2.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_50, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: threads@freebsd.org Subject: Re: SIGPIPE and threads 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: Mon, 28 Jun 2010 14:05:44 -0000 --jHgdI7OefoZoiA5t Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 28, 2010 at 08:33:54AM -0400, John Baldwin wrote: > Currently when a thread performs a write(2) on a disconnected socket or a= FIFO=20 > with no readers the SIGPIPE signal is posted to the entire process via=20 > psignal(). This means that the signal can be delivered to any thread in = the=20 > process. However, it seems more intuitive to me that SIGPIPE should be s= ent=20 > to the "offending" thread similar to signals sent in response to traps vi= a=20 > trapsignal(). POSIX seems to require this in that the description of the= =20 > EPIPE error return value for write(2) and fflush(3) in the Open Group's o= nline=20 > manpages both say that SIGPIPE should be sent to the current thread in=20 > addition to returning EPIPE: >=20 > http://www.opengroup.org/onlinepubs/000095399/functions/write.html >=20 > http://www.opengroup.org/onlinepubs/000095399/functions/fflush.html >=20 > I have an untested (only compiled) patch below: I think the patch is right, but, as you note, having a dedicated function that wraps automatic ksi initialization and tdsignal() call would be even better. >=20 > Index: kern/uipc_syscalls.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 > --- kern/uipc_syscalls.c (revision 209571) > +++ kern/uipc_syscalls.c (working copy) > @@ -738,6 +738,7 @@ > struct mbuf *control; > enum uio_seg segflg; > { > + struct ksiginfo ksi; > struct file *fp; > struct uio auio; > struct iovec *iov; > @@ -793,8 +794,11 @@ > /* Generation of SIGPIPE can be controlled per socket */ > if (error =3D=3D EPIPE && !(so->so_options & SO_NOSIGPIPE) && > !(flags & MSG_NOSIGNAL)) { > + ksiginfo_init(&ksi); > + ksi.ksi_signo =3D SIGPIPE; > + ksi.ksi_code =3D SI_KERNEL; > PROC_LOCK(td->td_proc); > - psignal(td->td_proc, SIGPIPE); > + tdsignal(td->td_proc, td, SIGPIPE, &ksi); > PROC_UNLOCK(td->td_proc); > } > } > @@ -2379,6 +2383,7 @@ > { > #if (defined(INET) || defined(INET6)) && defined(SCTP) > struct sctp_sndrcvinfo sinfo, *u_sinfo =3D NULL; > + struct ksiginfo ksi; > struct socket *so; > struct file *fp =3D NULL; > int use_rcvinfo =3D 1; > @@ -2443,8 +2448,11 @@ > /* Generation of SIGPIPE can be controlled per socket. */ > if (error =3D=3D EPIPE && !(so->so_options & SO_NOSIGPIPE) && > !(uap->flags & MSG_NOSIGNAL)) { > + ksiginfo_init(&ksi); > + ksi.ksi_signo =3D SIGPIPE; > + ksi.ksi_code =3D SI_KERNEL; > PROC_LOCK(td->td_proc); > - psignal(td->td_proc, SIGPIPE); > + tdsignal(td->td_proc, td, SIGPIPE, &ksi); > PROC_UNLOCK(td->td_proc); > } > } > @@ -2483,6 +2491,7 @@ > { > #if (defined(INET) || defined(INET6)) && defined(SCTP) > struct sctp_sndrcvinfo sinfo, *u_sinfo =3D NULL; > + struct ksiginfo ksi; > struct socket *so; > struct file *fp =3D NULL; > int use_rcvinfo =3D 1; > @@ -2561,8 +2570,11 @@ > /* Generation of SIGPIPE can be controlled per socket */ > if (error =3D=3D EPIPE && !(so->so_options & SO_NOSIGPIPE) && > !(uap->flags & MSG_NOSIGNAL)) { > + ksiginfo_init(&ksi); > + ksi.ksi_signo =3D SIGPIPE; > + ksi.ksi_code =3D SI_KERNEL; > PROC_LOCK(td->td_proc); > - psignal(td->td_proc, SIGPIPE); > + tdsignal(td->td_proc, td, SIGPIPE, &ksi); > PROC_UNLOCK(td->td_proc); > } > } > Index: kern/sys_socket.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 > --- kern/sys_socket.c (revision 209571) > +++ kern/sys_socket.c (working copy) > @@ -92,6 +92,7 @@ > int flags, struct thread *td) > { > struct socket *so =3D fp->f_data; > + struct ksiginfo ksi; > int error; > =20 > #ifdef MAC > @@ -101,8 +102,11 @@ > #endif > error =3D sosend(so, 0, uio, 0, 0, 0, uio->uio_td); > if (error =3D=3D EPIPE && (so->so_options & SO_NOSIGPIPE) =3D=3D 0) { > + ksiginfo_init(&ksi); > + ksi.ksi_signo =3D SIGPIPE; > + ksi.ksi_code =3D SI_KERNEL; > PROC_LOCK(uio->uio_td->td_proc); > - psignal(uio->uio_td->td_proc, SIGPIPE); > + tdsignal(uio->uio_td->td_proc, uio->uio_td, SIGPIPE, &ksi); > PROC_UNLOCK(uio->uio_td->td_proc); > } > return (error); > Index: kern/sys_generic.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 > --- kern/sys_generic.c (revision 209571) > +++ kern/sys_generic.c (working copy) > @@ -509,6 +509,7 @@ > off_t offset; > int flags; > { > + struct ksiginfo ksi; > ssize_t cnt; > int error; > #ifdef KTRACE > @@ -531,8 +532,11 @@ > error =3D 0; > /* Socket layer is responsible for issuing SIGPIPE. */ > if (fp->f_type !=3D DTYPE_SOCKET && error =3D=3D EPIPE) { > + ksiginfo_init(&ksi); > + ksi.ksi_signo =3D SIGPIPE; > + ksi.ksi_code =3D SI_KERNEL; > PROC_LOCK(td->td_proc); > - psignal(td->td_proc, SIGPIPE); > + tdsignal(td->td_proc, td, SIGPIPE, &ksi); > PROC_UNLOCK(td->td_proc); > } > } >=20 > --=20 > John Baldwin --jHgdI7OefoZoiA5t Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iEYEARECAAYFAkworC0ACgkQC3+MBN1Mb4huTACfX3Wdq2CxgCmwrqNmCbolHudz rdQAnjDBamwK3sbfOy+wcMH/tNo5Bpup =86qS -----END PGP SIGNATURE----- --jHgdI7OefoZoiA5t--