Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src As discussed in tech-kern, provide the means to prevent deli...



details:   https://anonhg.NetBSD.org/src/rev/35f4c24df3f8
branches:  trunk
changeset: 773011:35f4c24df3f8
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jan 25 00:28:35 2012 +0000

description:
As discussed in tech-kern, provide the means to prevent delivery of SIGPIPE
on EPIPE for all file descriptor types:

- provide O_NOSIGPIPE for open,kqueue1,pipe2,dup3,fcntl(F_{G,S}ETFL) [NetBSD]
- provide SOCK_NOSIGPIPE for socket,socketpair [NetBSD]
- provide SO_NOSIGPIPE for {g,s}seckopt [NetBSD/FreeBSD/MacOSX]
- provide F_{G,S}ETNOSIGPIPE for fcntl [MacOSX]

diffstat:

 lib/libc/sys/dup.2        |   9 +++++++--
 lib/libc/sys/fcntl.2      |  45 +++++++++++++++++++++------------------------
 lib/libc/sys/getsockopt.2 |   8 ++++++--
 lib/libc/sys/kqueue.2     |   9 +++++++--
 lib/libc/sys/open.2       |  15 +++++++++++++--
 lib/libc/sys/pipe.2       |   9 +++++++--
 lib/libc/sys/socket.2     |   7 ++++++-
 sys/kern/kern_descrip.c   |  31 ++++++++++++++++++-------------
 sys/kern/kern_event.c     |   6 +++---
 sys/kern/sys_descrip.c    |  16 ++++++++++++++--
 sys/kern/sys_generic.c    |   8 ++++----
 sys/kern/sys_pipe.c       |   6 +++---
 sys/kern/uipc_socket.c    |   9 ++++++---
 sys/kern/uipc_syscalls.c  |  34 ++++++++++++++++++++++++----------
 sys/sys/fcntl.h           |  12 +++++++++---
 sys/sys/filedesc.h        |   3 ++-
 sys/sys/socket.h          |   4 +++-
 17 files changed, 153 insertions(+), 78 deletions(-)

diffs (truncated from 714 to 300 lines):

diff -r 4aa4e6bf7c04 -r 35f4c24df3f8 lib/libc/sys/dup.2
--- a/lib/libc/sys/dup.2        Tue Jan 24 22:40:20 2012 +0000
+++ b/lib/libc/sys/dup.2        Wed Jan 25 00:28:35 2012 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: dup.2,v 1.27 2011/07/22 11:02:39 wiz Exp $
+.\"    $NetBSD: dup.2,v 1.28 2012/01/25 00:28:35 christos Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)dup.2      8.1 (Berkeley) 6/4/93
 .\"
-.Dd July 16, 2011
+.Dd January 23, 2012
 .Dt DUP 2
 .Os
 .Sh NAME
@@ -118,6 +118,11 @@
 property.
 .It Dv O_NONBLOCK
 Sets non-blocking I/O.
+.It Dv O_NOSIGPIPE
+Return
+.Er EPIPE
+instead of raising
+.Dv SIGPIPE .
 .El
 .Sh RETURN VALUES
 The value \-1 is returned if an error occurs in either call.
diff -r 4aa4e6bf7c04 -r 35f4c24df3f8 lib/libc/sys/fcntl.2
--- a/lib/libc/sys/fcntl.2      Tue Jan 24 22:40:20 2012 +0000
+++ b/lib/libc/sys/fcntl.2      Wed Jan 25 00:28:35 2012 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: fcntl.2,v 1.39 2011/06/27 08:21:08 wiz Exp $
+.\"    $NetBSD: fcntl.2,v 1.40 2012/01/25 00:28:35 christos Exp $
 .\"
 .\" Copyright (c) 1983, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)fcntl.2    8.2 (Berkeley) 1/12/94
 .\"
-.Dd June 25, 2011
+.Dd January 23, 2012
 .Dt FCNTL 2
 .Os
 .Sh NAME
@@ -146,35 +146,32 @@
 .Ar fd .
 .It Dv F_MAXFD
 Return the maximum file descriptor number currently open by the process.
+.It Dv F_GETNOSIGPIPE
+Return if the
+.Dv O_NOSIGPIPE
+flag is set in the file descriptor.
+.It Dv F_SETNOSIGPIPE
+Set or clear the
+.Dv O_NOSIGPIPE
+in the file descriptor.
 .El
 .Pp
-The flags for the
+The set of valid flags for the
 .Dv F_GETFL
 and
 .Dv F_SETFL
 flags are as follows:
-.Bl -tag -width O_NONBLOCKX
-.It Dv O_NONBLOCK
-Non-blocking I/O; if no data is available to a
-.Xr read 2
-call, or if a
-.Xr write 2
-operation would block,
-the read or write call returns \-1 with the error
-.Er EAGAIN .
-.It Dv O_APPEND
-Force each write to append at the end of file;
-corresponds to the
-.Dv O_APPEND
-flag of
+.Dv O_APPEND ,
+.Dv O_ASYNC ,
+.Dv O_FSYNC ,
+.Dv O_NONBLOCK ,
+.Dv O_DSYNC ,
+.Dv O_RSYNC ,
+.Dv O_ALT_IO ,
+.Dv O_DIRECT ,
+.Dv O_NOSIGPIPE .
+These flags are described in
 .Xr open 2 .
-.It Dv O_ASYNC
-Enable the
-.Dv SIGIO
-signal to be sent to the process group
-when I/O is possible, e.g.,
-upon availability of data to be read.
-.El
 .Pp
 Several commands are available for doing advisory file locking;
 they all operate on the following structure:
diff -r 4aa4e6bf7c04 -r 35f4c24df3f8 lib/libc/sys/getsockopt.2
--- a/lib/libc/sys/getsockopt.2 Tue Jan 24 22:40:20 2012 +0000
+++ b/lib/libc/sys/getsockopt.2 Wed Jan 25 00:28:35 2012 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: getsockopt.2,v 1.34 2009/06/29 08:38:07 wiz Exp $
+.\"    $NetBSD: getsockopt.2,v 1.35 2012/01/25 00:28:35 christos Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)getsockopt.2       8.4 (Berkeley) 5/2/95
 .\"
-.Dd June 28, 2009
+.Dd January 23, 2012
 .Dt GETSOCKOPT 2
 .Os
 .Sh NAME
@@ -167,6 +167,10 @@
 .It Dv SO_RCVTIMEO Ta "set timeout value for input"
 .It Dv SO_TIMESTAMP Ta "enables reception of a timestamp with datagrams"
 .It Dv SO_ACCEPTFILTER Ta "set accept filter on listening socket"
+.It Dv SO_NOSIGPIPE Ta
+controls generation of
+.Dv SIGPIPE
+for the socket
 .It Dv SO_TYPE Ta "get the type of the socket (get only)"
 .It Dv SO_ERROR Ta "get and clear error on the socket (get only)"
 .El
diff -r 4aa4e6bf7c04 -r 35f4c24df3f8 lib/libc/sys/kqueue.2
--- a/lib/libc/sys/kqueue.2     Tue Jan 24 22:40:20 2012 +0000
+++ b/lib/libc/sys/kqueue.2     Wed Jan 25 00:28:35 2012 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: kqueue.2,v 1.31 2011/06/26 16:42:41 christos Exp $
+.\"    $NetBSD: kqueue.2,v 1.32 2012/01/25 00:28:35 christos Exp $
 .\"
 .\" Copyright (c) 2000 Jonathan Lemon
 .\" All rights reserved.
@@ -32,7 +32,7 @@
 .\"
 .\" $FreeBSD: src/lib/libc/sys/kqueue.2,v 1.22 2001/06/27 19:55:57 dd Exp $
 .\"
-.Dd June 24, 2011
+.Dd January 23, 2012
 .Dt KQUEUE 2
 .Os
 .Sh NAME
@@ -92,6 +92,11 @@
 Set the close on exec property.
 .It Dv O_NONBLOCK
 Sets non-blocking I/O.
+.It Dv O_NOSIGPIPE
+Return
+.Er EPIPE
+instead of raising
+.Dv SIGPIPE .
 .El
 The queue is not inherited by a child created with
 .Xr fork 2 .
diff -r 4aa4e6bf7c04 -r 35f4c24df3f8 lib/libc/sys/open.2
--- a/lib/libc/sys/open.2       Tue Jan 24 22:40:20 2012 +0000
+++ b/lib/libc/sys/open.2       Wed Jan 25 00:28:35 2012 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: open.2,v 1.50 2011/04/20 19:57:58 christos Exp $
+.\"    $NetBSD: open.2,v 1.51 2012/01/25 00:28:35 christos Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)open.2     8.2 (Berkeley) 11/16/93
 .\"
-.Dd April 20, 2011
+.Dd January 23, 2012
 .Dt OPEN 2
 .Os
 .Sh NAME
@@ -99,6 +99,11 @@
 on
 .Xr exec 3
 flag.
+.It Dv O_NOSIGPIPE
+Return
+.Er EPIPE
+instead of raising
+.Dv SIGPIPE .
 .It Dv O_DSYNC
 If set, write operations will be performed according to synchronized
 I/O data integrity completion:
@@ -153,6 +158,12 @@
 element of the request must meet the above alignment constraints.
 .It Dv O_DIRECTORY
 Fail if the file is not a directory.
+.It Dv O_ASYNC
+Enable the
+.Dv SIGIO
+signal to be sent to the process group
+when I/O is possible, e.g.,
+upon availability of data to be read.
 .El
 .Pp
 Opening a file with
diff -r 4aa4e6bf7c04 -r 35f4c24df3f8 lib/libc/sys/pipe.2
--- a/lib/libc/sys/pipe.2       Tue Jan 24 22:40:20 2012 +0000
+++ b/lib/libc/sys/pipe.2       Wed Jan 25 00:28:35 2012 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: pipe.2,v 1.27 2011/07/22 11:02:39 wiz Exp $
+.\"    $NetBSD: pipe.2,v 1.28 2012/01/25 00:28:35 christos Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)pipe.2     8.1 (Berkeley) 6/4/93
 .\"
-.Dd July 15, 2011
+.Dd January 23, 2012
 .Dt PIPE 2
 .Os
 .Sh NAME
@@ -97,6 +97,11 @@
 property.
 .It Dv O_NONBLOCK
 Sets non-blocking I/O.
+.It Dv O_NOSIGPIPE
+Return
+.Er EPIPE
+instead of raising
+.Dv SIGPIPE .
 .El
 .Sh RETURN VALUES
 On successful creation of the pipe, zero is returned.
diff -r 4aa4e6bf7c04 -r 35f4c24df3f8 lib/libc/sys/socket.2
--- a/lib/libc/sys/socket.2     Tue Jan 24 22:40:20 2012 +0000
+++ b/lib/libc/sys/socket.2     Wed Jan 25 00:28:35 2012 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: socket.2,v 1.37 2011/06/26 16:42:41 christos Exp $
+.\"    $NetBSD: socket.2,v 1.38 2012/01/25 00:28:35 christos Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -86,6 +86,11 @@
 Set the close on exec property.
 .It Dv SOCK_NONBLOCK
 Sets non-blocking I/O.
+.It Dv SOCK_NOSIGPIPE
+Return
+.Er EPIPE
+instead of raising
+.Dv SIGPIPE .
 .El
 .Pp
 A
diff -r 4aa4e6bf7c04 -r 35f4c24df3f8 sys/kern/kern_descrip.c
--- a/sys/kern/kern_descrip.c   Tue Jan 24 22:40:20 2012 +0000
+++ b/sys/kern/kern_descrip.c   Wed Jan 25 00:28:35 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_descrip.c,v 1.217 2011/09/25 13:40:37 chs Exp $   */
+/*     $NetBSD: kern_descrip.c,v 1.218 2012/01/25 00:28:35 christos Exp $      */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.217 2011/09/25 13:40:37 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.218 2012/01/25 00:28:35 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -500,20 +500,25 @@
  * to a socket.
  */
 int
+fd_getsock1(unsigned fd, struct socket **sop, file_t **fp)
+{
+       *fp = fd_getfile(fd);
+       if (__predict_false(*fp == NULL)) {
+               return EBADF;
+       }
+       if (__predict_false((*fp)->f_type != DTYPE_SOCKET)) {
+               fd_putfile(fd);
+               return ENOTSOCK;
+       }
+       *sop = (*fp)->f_data;
+       return 0;
+}
+
+int
 fd_getsock(unsigned fd, struct socket **sop)
 {
        file_t *fp;
-
-       fp = fd_getfile(fd);
-       if (__predict_false(fp == NULL)) {
-               return EBADF;



Home | Main Index | Thread Index | Old Index