1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/socket/socket.c: check SCM_RIGHTS macro addition to

the msg_control field to test existence of file descriptor passing
  by msg_control.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2004-05-20 06:04:39 +00:00
parent 09053e137f
commit 2ef79516bc
2 changed files with 27 additions and 9 deletions

View file

@ -1,3 +1,9 @@
Thu May 20 14:35:52 2004 Tanaka Akira <akr@m17n.org>
* ext/socket/socket.c: check SCM_RIGHTS macro addition to
the msg_control field to test existence of file descriptor passing
by msg_control.
Thu May 20 12:38:06 2004 Yukihiro Matsumoto <matz@ruby-lang.org> Thu May 20 12:38:06 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* numeric.c (flo_eq): alway check if operands are NaN. * numeric.c (flo_eq): alway check if operands are NaN.

View file

@ -1530,18 +1530,30 @@ unix_recvfrom(argc, argv, sock)
return s_recvfrom(sock, argc, argv, RECV_UNIX); return s_recvfrom(sock, argc, argv, RECV_UNIX);
} }
#if defined(HAVE_ST_MSG_CONTROL) && defined(SCM_RIGHTS)
#define FD_PASSING_BY_MSG_CONTROL 1
#else
#define FD_PASSING_BY_MSG_CONTROL 0
#endif
#if defined(HAVE_ST_MSG_ACCRIGHTS)
#define FD_PASSING_BY_MSG_ACCRIGHTS 1
#else
#define FD_PASSING_BY_MSG_ACCRIGHTS 0
#endif
static VALUE static VALUE
unix_send_io(sock, val) unix_send_io(sock, val)
VALUE sock, val; VALUE sock, val;
{ {
#if defined(HAVE_SENDMSG) && (defined(HAVE_ST_MSG_CONTROL) || defined(HAVE_ST_MSG_ACCRIGHTS)) #if defined(HAVE_SENDMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS)
int fd; int fd;
OpenFile *fptr; OpenFile *fptr;
struct msghdr msg; struct msghdr msg;
struct iovec vec[1]; struct iovec vec[1];
char buf[1]; char buf[1];
#if defined(HAVE_ST_MSG_CONTROL) #if FD_PASSING_BY_MSG_CONTROL
struct { struct {
struct cmsghdr hdr; struct cmsghdr hdr;
int fd; int fd;
@ -1572,7 +1584,7 @@ unix_send_io(sock, val)
msg.msg_iov = vec; msg.msg_iov = vec;
msg.msg_iovlen = 1; msg.msg_iovlen = 1;
#if defined(HAVE_ST_MSG_CONTROL) #if FD_PASSING_BY_MSG_CONTROL
msg.msg_control = (caddr_t)&cmsg; msg.msg_control = (caddr_t)&cmsg;
msg.msg_controllen = sizeof(struct cmsghdr) + sizeof(int); msg.msg_controllen = sizeof(struct cmsghdr) + sizeof(int);
msg.msg_flags = 0; msg.msg_flags = 0;
@ -1595,7 +1607,7 @@ unix_send_io(sock, val)
#endif #endif
} }
#if defined(HAVE_RECVMSG) && (defined(HAVE_ST_MSG_CONTROL) || defined(HAVE_ST_MSG_ACCRIGHTS)) #if defined(HAVE_RECVMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS)
static void static void
thread_read_select(fd) thread_read_select(fd)
int fd; int fd;
@ -1614,7 +1626,7 @@ unix_recv_io(argc, argv, sock)
VALUE *argv; VALUE *argv;
VALUE sock; VALUE sock;
{ {
#if defined(HAVE_RECVMSG) && (defined(HAVE_ST_MSG_CONTROL) || defined(HAVE_ST_MSG_ACCRIGHTS)) #if defined(HAVE_RECVMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS)
VALUE klass, mode; VALUE klass, mode;
OpenFile *fptr; OpenFile *fptr;
struct msghdr msg; struct msghdr msg;
@ -1622,7 +1634,7 @@ unix_recv_io(argc, argv, sock)
char buf[1]; char buf[1];
int fd; int fd;
#if defined(HAVE_ST_MSG_CONTROL) #if FD_PASSING_BY_MSG_CONTROL
struct { struct {
struct cmsghdr hdr; struct cmsghdr hdr;
int fd; int fd;
@ -1647,7 +1659,7 @@ unix_recv_io(argc, argv, sock)
msg.msg_iov = vec; msg.msg_iov = vec;
msg.msg_iovlen = 1; msg.msg_iovlen = 1;
#if defined(HAVE_ST_MSG_CONTROL) #if FD_PASSING_BY_MSG_CONTROL
msg.msg_control = (caddr_t)&cmsg; msg.msg_control = (caddr_t)&cmsg;
msg.msg_controllen = sizeof(struct cmsghdr) + sizeof(int); msg.msg_controllen = sizeof(struct cmsghdr) + sizeof(int);
msg.msg_flags = 0; msg.msg_flags = 0;
@ -1665,7 +1677,7 @@ unix_recv_io(argc, argv, sock)
rb_sys_fail("recvmsg(2)"); rb_sys_fail("recvmsg(2)");
if ( if (
#if defined(HAVE_ST_MSG_CONTROL) #if FD_PASSING_BY_MSG_CONTROL
msg.msg_controllen != sizeof(struct cmsghdr) + sizeof(int) || msg.msg_controllen != sizeof(struct cmsghdr) + sizeof(int) ||
cmsg.hdr.cmsg_len != sizeof(struct cmsghdr) + sizeof(int) || cmsg.hdr.cmsg_len != sizeof(struct cmsghdr) + sizeof(int) ||
cmsg.hdr.cmsg_level != SOL_SOCKET || cmsg.hdr.cmsg_level != SOL_SOCKET ||
@ -1677,7 +1689,7 @@ unix_recv_io(argc, argv, sock)
rb_raise(rb_eSocket, "File descriptor was not passed"); rb_raise(rb_eSocket, "File descriptor was not passed");
} }
#if defined(HAVE_ST_MSG_CONTROL) #if FD_PASSING_BY_MSG_CONTROL
fd = cmsg.fd; fd = cmsg.fd;
#endif #endif