From owner-svn-src-all@FreeBSD.ORG Tue Jun 16 05:10:21 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D33CC106567B; Tue, 16 Jun 2009 05:10:21 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BFA9A8FC24; Tue, 16 Jun 2009 05:10:21 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n5G5ALmq012958; Tue, 16 Jun 2009 05:10:21 GMT (envelope-from dchagin@svn.freebsd.org) Received: (from dchagin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n5G5ALl0012954; Tue, 16 Jun 2009 05:10:21 GMT (envelope-from dchagin@svn.freebsd.org) Message-Id: <200906160510.n5G5ALl0012954@svn.freebsd.org> From: Dmitry Chagin Date: Tue, 16 Jun 2009 05:10:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r194284 - in stable/7/sys: . amd64/linux32 compat/linux contrib/pf dev/ath/ath_hal i386/linux X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jun 2009 05:10:22 -0000 Author: dchagin Date: Tue Jun 16 05:10:21 2009 New Revision: 194284 URL: http://svn.freebsd.org/changeset/base/194284 Log: MFC r192206: Somewhere between 2.6.23 and 2.6.27, Linux added SOCK_CLOEXEC and SOCK_NONBLOCK flags, that allow to save fcntl() calls. Implement a variation of the socket() syscall which takes a flags in addition to the type argument. Approved by: kib (mentor) Modified: stable/7/sys/ (props changed) stable/7/sys/amd64/linux32/linux.h stable/7/sys/compat/linux/linux_socket.c stable/7/sys/compat/linux/linux_socket.h stable/7/sys/contrib/pf/ (props changed) stable/7/sys/dev/ath/ath_hal/ (props changed) stable/7/sys/i386/linux/linux.h Modified: stable/7/sys/amd64/linux32/linux.h ============================================================================== --- stable/7/sys/amd64/linux32/linux.h Tue Jun 16 05:08:48 2009 (r194283) +++ stable/7/sys/amd64/linux32/linux.h Tue Jun 16 05:10:21 2009 (r194284) @@ -563,6 +563,7 @@ int linux_ioctl_unregister_handler(struc #define LINUX_O_DIRECTORY 00200000 /* Must be a directory */ #define LINUX_O_NOFOLLOW 00400000 /* Do not follow links */ #define LINUX_O_NOATIME 01000000 +#define LINUX_O_CLOEXEC 02000000 #define LINUX_F_DUPFD 0 #define LINUX_F_GETFD 1 Modified: stable/7/sys/compat/linux/linux_socket.c ============================================================================== --- stable/7/sys/compat/linux/linux_socket.c Tue Jun 16 05:08:48 2009 (r194283) +++ stable/7/sys/compat/linux/linux_socket.c Tue Jun 16 05:10:21 2009 (r194284) @@ -550,10 +550,13 @@ linux_socket(struct thread *td, struct l int type; int protocol; } */ bsd_args; - int retval_socket; + int retval_socket, socket_flags; bsd_args.protocol = args->protocol; - bsd_args.type = args->type; + socket_flags = args->type & ~LINUX_SOCK_TYPE_MASK; + if (socket_flags & ~(LINUX_SOCK_CLOEXEC | LINUX_SOCK_NONBLOCK)) + return (EINVAL); + bsd_args.type = args->type & LINUX_SOCK_TYPE_MASK; if (bsd_args.type < 0 || bsd_args.type > LINUX_SOCK_MAX) return (EINVAL); bsd_args.domain = linux_to_bsd_domain(args->domain); @@ -564,6 +567,23 @@ linux_socket(struct thread *td, struct l if (retval_socket) return (retval_socket); + if (socket_flags & LINUX_SOCK_NONBLOCK) { + retval_socket = kern_fcntl(td, td->td_retval[0], + F_SETFL, O_NONBLOCK); + if (retval_socket) { + (void)kern_close(td, td->td_retval[0]); + goto out; + } + } + if (socket_flags & LINUX_SOCK_CLOEXEC) { + retval_socket = kern_fcntl(td, td->td_retval[0], + F_SETFD, FD_CLOEXEC); + if (retval_socket) { + (void)kern_close(td, td->td_retval[0]); + goto out; + } + } + if (bsd_args.type == SOCK_RAW && (bsd_args.protocol == IPPROTO_RAW || bsd_args.protocol == 0) && bsd_args.domain == PF_INET) { @@ -599,6 +619,7 @@ linux_socket(struct thread *td, struct l } #endif +out: return (retval_socket); } Modified: stable/7/sys/compat/linux/linux_socket.h ============================================================================== --- stable/7/sys/compat/linux/linux_socket.h Tue Jun 16 05:08:48 2009 (r194283) +++ stable/7/sys/compat/linux/linux_socket.h Tue Jun 16 05:10:21 2009 (r194284) @@ -69,6 +69,13 @@ #define LINUX_SOCK_MAX LINUX_SOCK_SEQPACKET +#define LINUX_SOCK_TYPE_MASK 0xf + +/* Flags for socket, socketpair, accept4 */ + +#define LINUX_SOCK_CLOEXEC LINUX_O_CLOEXEC +#define LINUX_SOCK_NONBLOCK LINUX_O_NONBLOCK + struct l_ucred { uint32_t pid; uint32_t uid; Modified: stable/7/sys/i386/linux/linux.h ============================================================================== --- stable/7/sys/i386/linux/linux.h Tue Jun 16 05:08:48 2009 (r194283) +++ stable/7/sys/i386/linux/linux.h Tue Jun 16 05:10:21 2009 (r194284) @@ -534,6 +534,7 @@ int linux_ioctl_unregister_handler(struc #define LINUX_O_DIRECTORY 00200000 /* Must be a directory */ #define LINUX_O_NOFOLLOW 00400000 /* Do not follow links */ #define LINUX_O_NOATIME 01000000 +#define LINUX_O_CLOEXEC 02000000 #define LINUX_F_DUPFD 0 #define LINUX_F_GETFD 1