Close #12950: multiprocessing "test_fd_transfer" fails under OpenIndiana

This commit is contained in:
Jesus Cea 2011-09-10 04:04:09 +02:00
parent 54b01498e3
commit bbd8bec389
1 changed files with 23 additions and 11 deletions

View File

@ -86,31 +86,37 @@ ProcessingCtrlHandler(DWORD dwCtrlType)
/* Functions for transferring file descriptors between processes. /* Functions for transferring file descriptors between processes.
Reimplements some of the functionality of the fdcred Reimplements some of the functionality of the fdcred
module at http://www.mca-ltd.com/resources/fdcred_1.tgz. */ module at http://www.mca-ltd.com/resources/fdcred_1.tgz. */
/* Based in http://resin.csoft.net/cgi-bin/man.cgi?section=3&topic=CMSG_DATA */
static PyObject * static PyObject *
multiprocessing_sendfd(PyObject *self, PyObject *args) multiprocessing_sendfd(PyObject *self, PyObject *args)
{ {
int conn, fd, res; int conn, fd, res;
char dummy_char;
char buf[CMSG_SPACE(sizeof(int))];
struct msghdr msg = {0};
struct iovec dummy_iov; struct iovec dummy_iov;
char dummy_char;
struct msghdr msg;
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
union {
struct cmsghdr hdr;
unsigned char buf[CMSG_SPACE(sizeof(int))];
} cmsgbuf;
if (!PyArg_ParseTuple(args, "ii", &conn, &fd)) if (!PyArg_ParseTuple(args, "ii", &conn, &fd))
return NULL; return NULL;
dummy_iov.iov_base = &dummy_char; dummy_iov.iov_base = &dummy_char;
dummy_iov.iov_len = 1; dummy_iov.iov_len = 1;
msg.msg_control = buf;
msg.msg_controllen = sizeof(buf); memset(&msg, 0, sizeof(msg));
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = sizeof(cmsgbuf.buf);
msg.msg_iov = &dummy_iov; msg.msg_iov = &dummy_iov;
msg.msg_iovlen = 1; msg.msg_iovlen = 1;
cmsg = CMSG_FIRSTHDR(&msg); cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
msg.msg_controllen = cmsg->cmsg_len;
* (int *) CMSG_DATA(cmsg) = fd; * (int *) CMSG_DATA(cmsg) = fd;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
@ -127,20 +133,26 @@ multiprocessing_recvfd(PyObject *self, PyObject *args)
{ {
int conn, fd, res; int conn, fd, res;
char dummy_char; char dummy_char;
char buf[CMSG_SPACE(sizeof(int))];
struct msghdr msg = {0};
struct iovec dummy_iov; struct iovec dummy_iov;
struct msghdr msg = {0};
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
union {
struct cmsghdr hdr;
unsigned char buf[CMSG_SPACE(sizeof(int))];
} cmsgbuf;
if (!PyArg_ParseTuple(args, "i", &conn)) if (!PyArg_ParseTuple(args, "i", &conn))
return NULL; return NULL;
dummy_iov.iov_base = &dummy_char; dummy_iov.iov_base = &dummy_char;
dummy_iov.iov_len = 1; dummy_iov.iov_len = 1;
msg.msg_control = buf;
msg.msg_controllen = sizeof(buf); memset(&msg, 0, sizeof(msg));
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = sizeof(cmsgbuf.buf);
msg.msg_iov = &dummy_iov; msg.msg_iov = &dummy_iov;
msg.msg_iovlen = 1; msg.msg_iovlen = 1;
cmsg = CMSG_FIRSTHDR(&msg); cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_type = SCM_RIGHTS;