python 中的recvmsg 相当于什么?

发布于 2024-11-14 17:58:09 字数 196 浏览 1 评论 0原文

我正在实现一个 python 脚本来以编程方式安装熔丝。我通过使用socketpair 和recvmsg api,用C 语言编写了等效的程序。但在 python 中,recvmsg 没有实现,所以我陷入了困境。你们谁能告诉我一个相当于这个的Python吗?任何帮助将不胜感激。

让我告诉我为什么需要recvmsg,我需要将fuse挂载的fd从子进程发送到父进程。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕梦 2024-11-21 17:58:09

您可以考虑使用 pyx 或 Python 的 C 模块来实现 C 中所需的功能,然后您可以从 Python 脚本中操作和/或使用它。这将允许您发送文件描述符并让 Python 脚本对其进行操作。

您可以做的其他事情是编写一个小的 C 包装器,它处理 recvmsg,直到它获取该 fd 并打开它后,它才会执行 fork。当您 fork 时,所有打开的文件描述符都将保持打开状态,然后执行,甚至只是普通的旧执行,这意味着您不必担心 Python 接收它。

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.

别在捏我脸啦 2024-11-21 17:58:09

作为 Python3 的一部分 socket.recvmsg 现已推出在 socket 模块中,根据文档,它应该允许你做你想做的事(尽管很晚了!):

在某些系统上,sendmsg()和recvmsg()可用于传递文件
通过 AF_UNIX 套接字的进程之间的描述符。当这个
使用设施(通常仅限于 SOCK_STREAM 套接字),
recvmsg() 将在其辅助数据中返回以下形式的项目
(socket.SOL_SOCKET,socket.SCM_RIGHTS,fds),其中fds是一个字节
将新文件描述符表示为二进制数组的对象
本机 C int 类型。如果recvmsg()在系统启动后引发异常
调用返回时,它将首先尝试关闭所有文件描述符
通过此机制接收。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文