[PATCH] please review. file descriptor passing for libc_r.

From: Alfred Perlstein <bright_at_mu.org>
Date: Sat, 22 Nov 2003 18:36:49 -0800
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
_at__at_ -44,6 +44,9 _at__at_
 _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) {
_at__at_ -70,6 +73,27 _at__at_
 			}
 		}
 		_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
Received on Sat Nov 22 2003 - 17:36:49 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:30 UTC