From owner-freebsd-current@FreeBSD.ORG Sat Nov 22 18:36:49 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B68FE16A4CE; Sat, 22 Nov 2003 18:36:49 -0800 (PST) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3B15E43FDF; Sat, 22 Nov 2003 18:36:49 -0800 (PST) (envelope-from bright@elvis.mu.org) Received: by elvis.mu.org (Postfix, from userid 1192) id 2F9A32ED44E; Sat, 22 Nov 2003 18:36:49 -0800 (PST) Date: Sat, 22 Nov 2003 18:36:49 -0800 From: Alfred Perlstein To: re@freebsd.org Message-ID: <20031123023649.GG35957@elvis.mu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i cc: current@freebsd.org Subject: [PATCH] please review. file descriptor passing for libc_r. X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Nov 2003 02:36:49 -0000 This should make things work properly for apps that are linked against libc_r and use filedescriptor passing. Can someone review and approve it please? Index: uthread_recvmsg.c =================================================================== RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_recvmsg.c,v retrieving revision 1.11 diff -u -r1.11 uthread_recvmsg.c --- uthread_recvmsg.c 19 Dec 2002 11:39:20 -0000 1.11 +++ uthread_recvmsg.c 23 Nov 2003 02:34:28 -0000 @@ -44,6 +44,9 @@ _recvmsg(int fd, struct msghdr *msg, int flags) { struct pthread *curthread = _get_curthread(); + struct cmsghdr *cmsgp; + int count, i, j; + int *fds; int ret; if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { @@ -70,6 +73,27 @@ } } _FD_UNLOCK(fd, FD_READ); + /* If file descriptors were passed then initialize them. */ + if (msg != NULL && (cmsgp = msg->msg_control) != NULL && + cmsgp->cmsg_level == SOL_SOCKET && + cmsgp->cmsg_type == SCM_RIGHTS) { + fds = (int *)CMSG_DATA(cmsgp); + count = (msg->msg_controllen - CMSG_LEN(0)) / sizeof(int); + for (i = 0; i < count; i++) { + /* + * XXX: If this fails we're screwing + * the user pretty badly by doing this + * but what other choice do we have? + */ + if (_thread_fd_table_init(fds[i]) != 0) { + for (j = 0; j < count; j++) { + __sys_close(fds[j]); + fds[j] = -1; + } + break; + } + } + } } return (ret); } -- - Alfred Perlstein - Research Engineering Development Inc. - email: bright@mu.org cell: 408-480-4684