Date: Thu, 13 Jun 2002 23:22:42 -0300 From: Mario Sergio Fujikawa Ferreira <lioux@FreeBSD.org> To: FreeBSD-arch@FreeBSD.org Cc: msmith@FreeBSD.org Subject: Adding SO_NOSIGPIPE to -STABLE/-CURRENT Message-ID: <20020614022304.94570.qmail@exxodus.fedaykin.here>
next in thread | raw e-mail | index | archive | help
--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 <msmith@FreeBSD.org> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020614022304.94570.qmail>