[PATCH] please review. file descriptor passing for libc_r.
Alfred Perlstein
bright at mu.org
Sat Nov 22 18:36:49 PST 2003
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 at mu.org cell: 408-480-4684
More information about the freebsd-current
mailing list