From owner-freebsd-arch Thu Jun 13 19:24:42 2002 Delivered-To: freebsd-arch@freebsd.org Received: from heaven.gigo.com (heaven.gigo.com [64.57.102.22]) by hub.freebsd.org (Postfix) with ESMTP id 57A7E37B40D for ; Thu, 13 Jun 2002 19:24:34 -0700 (PDT) Received: from 200-193-224-003-bsace7003.dsl.telebrasilia.net.br (200-193-224-003-bsace7003.dsl.telebrasilia.net.br [200.193.224.3]) by heaven.gigo.com (Postfix) with ESMTP id 649F2B8F2 for ; Thu, 13 Jun 2002 19:24:32 -0700 (PDT) Received: (qmail 94571 invoked by uid 1001); 14 Jun 2002 02:23:04 -0000 Message-ID: <20020614022304.94570.qmail@exxodus.fedaykin.here> Date: Thu, 13 Jun 2002 23:22:42 -0300 From: Mario Sergio Fujikawa Ferreira To: FreeBSD-arch@FreeBSD.org Cc: msmith@FreeBSD.org Subject: Adding SO_NOSIGPIPE to -STABLE/-CURRENT Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="sdtB3X0nJg68CQEu" Content-Disposition: inline User-Agent: Mutt/1.2.5.1i X-Operating-System: FreeBSD 4.6-PRERELEASE X-Disclaimer: I hope you find what you are looking for... in life :) Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --sdtB3X0nJg68CQEu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, I would like you to review this proposal to add the socket option SO_NOSIGPIPE: "Do not issue SIGPIPE on EPIPE." Therefore, we can disable SIGPIPE on a per socket basis instead of completing ignoring it with either sigpromask(2) or signal(3) handling. I can already hear the bikeshed legions crying that this is not necessary since we can just use one of the aformentioned options. Furthermore, who might want to handle SIGPIPE? Is it of use? For those that might find it useful, here go a simple scenario not easily reproduceable without SO_NOSIGPIPE: multi-threaded client, some threads want to handle SIGPIPE, others not. Similar options can be found in: - Darwin - SOF_NOSIGPIPE - Linux - MSG_NOSIGNAL - Solaris - Don't recall - Possibly others Do not dimiss this without consideration. This adds functionality without detracting from our system base. This patch was written against -STABLE since it's the system I use but should be easily re-written against -CURRENT. Credits to whom they are due, original sample code was kindly provided by Mike Smith from Darwin's codebase. Obtained from: Darwin (msmith sent me darwin's code) Regards, ps: Please CC: me since it seems I've not been able to subscribe to -arch -- Mario S F Ferreira - DF - Brazil - "I guess this is a signature." Computer Science Undergraduate | FreeBSD Committer | CS Developer flames to beloved devnull@someotherworldbeloworabove.org feature, n: a documented bug | bug, n: an undocumented feature --sdtB3X0nJg68CQEu Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=patch-nosigpipe --- sys/sys/socket.h.orig Mon Feb 25 19:32:57 2002 +++ sys/sys/socket.h Tue Feb 26 00:12:02 2002 @@ -78,6 +78,7 @@ #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ #define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */ +#define SO_NOSIGPIPE 0x0800 /* no sigpipe on epipe */ #define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */ /* --- sys/kern/sys_generic.c.orig Mon Feb 25 19:22:18 2002 +++ sys/kern/sys_generic.c Mon Feb 25 19:22:55 2002 @@ -409,7 +409,8 @@ if (auio.uio_resid != cnt && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; - if (error == EPIPE) + /* The socket layer handles SIGPIPE */ + if (error == EPIPE && fp->f_type != DTYPE_SOCKET) psignal(p, SIGPIPE); } cnt -= auio.uio_resid; --- sys/kern/uipc_socket.c.orig Mon Feb 25 19:26:17 2002 +++ sys/kern/uipc_socket.c Tue Feb 26 10:30:59 2002 @@ -1157,6 +1157,7 @@ case SO_REUSEPORT: case SO_OOBINLINE: case SO_TIMESTAMP: + case SO_NOSIGPIPE: error = sooptcopyin(sopt, &optval, sizeof optval, sizeof optval); if (error) @@ -1339,6 +1340,7 @@ case SO_BROADCAST: case SO_OOBINLINE: case SO_TIMESTAMP: + case SO_NOSIGPIPE: optval = so->so_options & sopt->sopt_name; integer: error = sooptcopyout(sopt, &optval, sizeof optval); --- sys/kern/uipc_syscalls.c.orig Mon Feb 25 19:59:54 2002 +++ sys/kern/uipc_syscalls.c Mon Feb 25 20:01:48 2002 @@ -586,7 +586,8 @@ if (auio.uio_resid != len && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; - if (error == EPIPE) + /* Generation of SIGPIPE can be controlled per socket */ + if (error == EPIPE && !(so->so_options & SO_NOSIGPIPE)) psignal(p, SIGPIPE); } if (error == 0) --sdtB3X0nJg68CQEu-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message