Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Jun 2009 21:52:39 +0000 (UTC)
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r194405 - in stable/7/sys: . compat/linux contrib/pf
Message-ID:  <200906172152.n5HLqddj089472@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dchagin
Date: Wed Jun 17 21:52:39 2009
New Revision: 194405
URL: http://svn.freebsd.org/changeset/base/194405

Log:
  MFC r192284:
  
  Implement MSG_CMSG_CLOEXEC flag for linux_recvmsg().
  
  Approved by:	kib (mentor)

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/compat/linux/linux_socket.c
  stable/7/sys/compat/linux/linux_socket.h
  stable/7/sys/contrib/pf/   (props changed)

Modified: stable/7/sys/compat/linux/linux_socket.c
==============================================================================
--- stable/7/sys/compat/linux/linux_socket.c	Wed Jun 17 21:49:41 2009	(r194404)
+++ stable/7/sys/compat/linux/linux_socket.c	Wed Jun 17 21:52:39 2009	(r194405)
@@ -1139,7 +1139,7 @@ linux_recvmsg(struct thread *td, struct 
 	struct mbuf **controlp;
 	caddr_t outbuf;
 	void *data;
-	int error;
+	int error, i, fd, fds, *fdp;
 
 	error = copyin(PTRIN(args->msg), &linux_msg, sizeof(linux_msg));
 	if (error)
@@ -1208,15 +1208,30 @@ linux_recvmsg(struct thread *td, struct 
 			data = CMSG_DATA(cm);
 			datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
 
-			if (outlen + LINUX_CMSG_LEN(datalen) >
-			    linux_msg.msg_controllen) {
-				if (outlen == 0) {
-					error = EMSGSIZE;
-					goto bad;
-				} else {
-					linux_msg.msg_flags |= LINUX_MSG_CTRUNC;
-					goto out;
+			switch (linux_cmsg->cmsg_type)
+			{
+			case LINUX_SCM_RIGHTS:
+				if (outlen + LINUX_CMSG_LEN(datalen) >
+				    linux_msg.msg_controllen) {
+					if (outlen == 0) {
+						error = EMSGSIZE;
+						goto bad;
+					} else {
+						linux_msg.msg_flags |=
+						    LINUX_MSG_CTRUNC;
+						goto out;
+					}
+				}
+				if (args->flags & LINUX_MSG_CMSG_CLOEXEC) {
+					fds = datalen / sizeof(int);
+					fdp = data;
+					for (i = 0; i < fds; i++) {
+						fd = *fdp++;
+						(void)kern_fcntl(td, fd,
+						    F_SETFD, FD_CLOEXEC);
+					}
 				}
+				break;
 			}
 
 			linux_cmsg->cmsg_len = LINUX_CMSG_LEN(datalen);

Modified: stable/7/sys/compat/linux/linux_socket.h
==============================================================================
--- stable/7/sys/compat/linux/linux_socket.h	Wed Jun 17 21:49:41 2009	(r194404)
+++ stable/7/sys/compat/linux/linux_socket.h	Wed Jun 17 21:52:39 2009	(r194405)
@@ -48,6 +48,7 @@
 #define LINUX_MSG_RST		0x1000
 #define LINUX_MSG_ERRQUEUE	0x2000
 #define LINUX_MSG_NOSIGNAL	0x4000
+#define LINUX_MSG_CMSG_CLOEXEC	0x40000000
 
 /* Socket-level control message types */
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906172152.n5HLqddj089472>