Date: Sat, 16 May 2009 18:48:42 +0000 (UTC) From: Dmitry Chagin <dchagin@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r192206 - in head/sys: amd64/linux32 compat/linux i386/linux Message-ID: <200905161848.n4GImgKJ066854@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dchagin Date: Sat May 16 18:48:41 2009 New Revision: 192206 URL: http://svn.freebsd.org/changeset/base/192206 Log: 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) MFC after: 1 month Modified: head/sys/amd64/linux32/linux.h head/sys/compat/linux/linux_socket.c head/sys/compat/linux/linux_socket.h head/sys/i386/linux/linux.h Modified: head/sys/amd64/linux32/linux.h ============================================================================== --- head/sys/amd64/linux32/linux.h Sat May 16 18:46:51 2009 (r192205) +++ head/sys/amd64/linux32/linux.h Sat May 16 18:48:41 2009 (r192206) @@ -571,6 +571,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: head/sys/compat/linux/linux_socket.c ============================================================================== --- head/sys/compat/linux/linux_socket.c Sat May 16 18:46:51 2009 (r192205) +++ head/sys/compat/linux/linux_socket.c Sat May 16 18:48:41 2009 (r192206) @@ -593,10 +593,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); @@ -607,6 +610,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) { @@ -642,6 +662,7 @@ linux_socket(struct thread *td, struct l } #endif +out: return (retval_socket); } Modified: head/sys/compat/linux/linux_socket.h ============================================================================== --- head/sys/compat/linux/linux_socket.h Sat May 16 18:46:51 2009 (r192205) +++ head/sys/compat/linux/linux_socket.h Sat May 16 18:48:41 2009 (r192206) @@ -100,6 +100,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: head/sys/i386/linux/linux.h ============================================================================== --- head/sys/i386/linux/linux.h Sat May 16 18:46:51 2009 (r192205) +++ head/sys/i386/linux/linux.h Sat May 16 18:48:41 2009 (r192206) @@ -547,6 +547,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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905161848.n4GImgKJ066854>