what is recvmsg equivalent in python?
Asked Answered
M

2

1

I am implementing a python script to do fuse mount programatically. I have written an equivalent in C, by making use of socketpair and recvmsg api's. But in python recvmsg is not implemented, so I am stuck. Can anyone of you tell me a python equivalent of this? Any help would be appreciated.

Let me tell why do I need recvmsg, I require to send the fd of the fuse mount from the child to the parent.

Merari answered 11/6, 2011 at 8:40 Comment(3)
It has not yet landed in Python, see bugs.python.org/issue6560Clarethaclaretta
No. As far as I am aware there is no way to implement recvmsg using what is currently available in Python. What data are you sending with recvmsg? Would it be possible to use a standard socket instead?Clarethaclaretta
I ran into this too. I took a stab at it but didn't get very far.Thunderstorm
C
1

What you could look at is using pyx or a C module for Python that implements the required functionality in C and then you can manipulate and or use it from your Python script. This would allow you to send over the file descriptor and have the Python script act upon it.

Other things you can do is write a small C wrapper, that handles the recvmsg and not until it gets that fd and has opened it does it do a fork. All file descriptors that are open will stay open when you fork, and then exec or even just plain old exec meaning you don't have to worry about Python receiving it.

Clarethaclaretta answered 21/6, 2011 at 8:39 Comment(0)
S
1

As part of Python3 socket.recvmsg is now available in the socket module which, according to the docs, should allow you to do what you want (albeit rather late!):

On some systems, sendmsg() and recvmsg() can be used to pass file descriptors between processes over an AF_UNIX socket. When this facility is used (it is often restricted to SOCK_STREAM sockets), recvmsg() will return, in its ancillary data, items of the form (socket.SOL_SOCKET, socket.SCM_RIGHTS, fds), where fds is a bytes object representing the new file descriptors as a binary array of the native C int type. If recvmsg() raises an exception after the system call returns, it will first attempt to close any file descriptors received via this mechanism.

Sachet answered 8/11, 2017 at 16:30 Comment(1)

© 2022 - 2024 — McMap. All rights reserved.