summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--monitor_fdpass.c30
2 files changed, 29 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 81259c8e..236b0075 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@
- (stevesk) HAVE_ACCRIGHTS_IN_MSGHDR configure support
- (stevesk) [monitor.c monitor_wrap.c] #ifdef HAVE_PW_CLASS_IN_PASSWD
- (stevesk) configure and cpp __FUNCTION__ gymnastics to handle nielsisms
+ - (stevesk) [monitor_fdpass.c] support for access rights style file
+ descriptor passing
20020321
- (bal) OpenBSD CVS Sync
@@ -7996,4 +7998,4 @@
- Wrote replacements for strlcpy and mkdtemp
- Released 1.0pre1
-$Id: ChangeLog,v 1.1969 2002/03/22 18:19:53 stevesk Exp $
+$Id: ChangeLog,v 1.1970 2002/03/22 19:32:53 stevesk Exp $
diff --git a/monitor_fdpass.c b/monitor_fdpass.c
index 7785535b..fd55a277 100644
--- a/monitor_fdpass.c
+++ b/monitor_fdpass.c
@@ -35,12 +35,18 @@ void
mm_send_fd(int socket, int fd)
{
struct msghdr msg;
- char tmp[CMSG_SPACE(sizeof(int))];
- struct cmsghdr *cmsg;
struct iovec vec;
char ch;
+#ifndef HAVE_ACCRIGHTS_IN_MSGHDR
+ char tmp[CMSG_SPACE(sizeof(int))];
+ struct cmsghdr *cmsg;
+#endif
memset(&msg, 0, sizeof(msg));
+#ifdef HAVE_ACCRIGHTS_IN_MSGHDR
+ msg.msg_accrights = (caddr_t)&fd;
+ msg.msg_accrightslen = sizeof(fd);
+#else
msg.msg_control = (caddr_t)tmp;
msg.msg_controllen = CMSG_LEN(sizeof(int));
cmsg = CMSG_FIRSTHDR(&msg);
@@ -48,6 +54,7 @@ mm_send_fd(int socket, int fd)
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
*(int *)CMSG_DATA(cmsg) = fd;
+#endif
vec.iov_base = &ch;
vec.iov_len = 1;
@@ -62,25 +69,40 @@ int
mm_receive_fd(int socket)
{
struct msghdr msg;
- char tmp[CMSG_SPACE(sizeof(int))];
- struct cmsghdr *cmsg;
struct iovec vec;
char ch;
+#ifndef HAVE_ACCRIGHTS_IN_MSGHDR
+ char tmp[CMSG_SPACE(sizeof(int))];
+ struct cmsghdr *cmsg;
+#else
+ int fd;
+#endif
memset(&msg, 0, sizeof(msg));
vec.iov_base = &ch;
vec.iov_len = 1;
msg.msg_iov = &vec;
msg.msg_iovlen = 1;
+#ifdef HAVE_ACCRIGHTS_IN_MSGHDR
+ msg.msg_accrights = (caddr_t)&fd;
+ msg.msg_accrightslen = sizeof(fd);
+#else
msg.msg_control = tmp;
msg.msg_controllen = sizeof(tmp);
+#endif
if (recvmsg(socket, &msg, 0) == -1)
fatal("%s: recvmsg", __FUNCTION__);
+#ifdef HAVE_ACCRIGHTS_IN_MSGHDR
+ if (msg.msg_accrightslen != sizeof(fd))
+ fatal("%s: no fd", __FUNCTION__);
+ return fd;
+#else
cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg->cmsg_type != SCM_RIGHTS)
fatal("%s: expected type %d got %d", __FUNCTION__,
SCM_RIGHTS, cmsg->cmsg_type);
return (*(int *)CMSG_DATA(cmsg));
+#endif
}