From owner-freebsd-net@FreeBSD.ORG Thu Mar 1 17:24:40 2007 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 34F4F16A400; Thu, 1 Mar 2007 17:24:40 +0000 (UTC) (envelope-from bms@FreeBSD.org) Received: from out5.smtp.messagingengine.com (out5.smtp.messagingengine.com [66.111.4.29]) by mx1.freebsd.org (Postfix) with ESMTP id 0877E13C4A7; Thu, 1 Mar 2007 17:24:39 +0000 (UTC) (envelope-from bms@FreeBSD.org) Received: from out1.internal (unknown [10.202.2.149]) by out1.messagingengine.com (Postfix) with ESMTP id EF9521F4588; Thu, 1 Mar 2007 12:24:39 -0500 (EST) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by out1.internal (MEProxy); Thu, 01 Mar 2007 12:24:39 -0500 X-Sasl-enc: z9G1jKwwxF3bJGgdtBa1GdsOCMTEM1wC+em2lZVszuKj 1172769879 Received: from [192.168.123.18] (82-35-112-254.cable.ubr07.dals.blueyonder.co.uk [82.35.112.254]) by mail.messagingengine.com (Postfix) with ESMTP id D100324498; Thu, 1 Mar 2007 12:24:36 -0500 (EST) Message-ID: <45E70C52.2080500@FreeBSD.org> Date: Thu, 01 Mar 2007 17:24:34 +0000 From: "Bruce M. Simpson" User-Agent: Thunderbird 1.5.0.9 (X11/20070125) MIME-Version: 1.0 To: Anton Yuzhaninov References: <2110071423.20070301151729@citrin.ru> <20070301152942.GA27336@rambler-co.ru> <1047693239.20070301194653@citrin.ru> In-Reply-To: <1047693239.20070301194653@citrin.ru> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-net@freebsd.org Subject: Re: is setsockopt SO_NOSIGPIPE work? X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Mar 2007 17:24:40 -0000 Anton Yuzhaninov wrote: > RE> It works, but only if you use send() instead of write(). > RE> Alternatively, you can control the behavior on a per > RE> message basis, by passing the MSG_NOSIGNAL in the "flags" > RE> argument to the send() call (without having to set a > RE> socket option). > > Thanks, with send() it works fine. > I think it should be documented in setsockopt(2). > AFAIK this is not a POSIX sockopt. I can only trace it back to MacOS X as the origin. Most applications I know of set the handler for SIGPIPE to SIG_IGN in such situations. Call graph: write() -> dofilewrite() -> soo_write() -> pru_send() Looking at the code for the generic write() path it looks like we would never squelch this kind of SIGPIPE intentionally. In soo_write() we check the SO_NOSIGPIPE option to tell if we should call psignal(). However, as soon as we return from soo_write(), the EPIPE is mapped to psignal() by the generic code in dofilewrite() which generates the SIGPIPE you are seeing. I think this may be a bug but in the absence of precise written requirements I can't be sure. :-) BMS