In Linux, is there any example of using AF_LOCAL (unix domain sockets) to communicate between processes (IPC) without using a file? (on a read only filesystem)
在Linux中,有没有使用AF_LOCAL (unix域套接字)在进程之间通信而不使用文件的例子?(在只读文件系统上)
I must use a Unix Domain socket, but I don't have file create/write access on the system.
我必须使用Unix域套接字,但是我在系统上没有文件创建/写入访问权限。
Thank you in advance.
提前谢谢你。
1 个解决方案
#1
3
You can create a unix domain socket with an "abstract socket address". Simply make the first character of the sun_path
string in the sockaddr_un
you pass to bind
be '\0'
. After this initial NUL, write a string to the remainder of sun_path
and pad it out to UNIX_PATH_MAX
with NULs (or anything else).
您可以使用“抽象套接字地址”创建unix域套接字。只需在传递给bind '\0'的sockaddr_un中创建sun_path字符串的第一个字符。在这个初始NUL之后,将一个字符串写入sun_path的其余部分,并用null(或其他任何东西)将其写到UNIX_PATH_MAX中。
Sockets created this way will not have any filesystem entry, but instead will be placed into an invisible system-wide socket namespace. The socket name is not a null-terminated string; it's a UNIX_PATH_MAX length string starting with a NUL, and any other NULs have no special significance. So it's vitally important to pad out that name, or you'll put extra uninitialized memory garbage into that name, with unexpected results. By convention, this is generally done with NUL pads, but it's up to you.
这样创建的套接字将不会有任何文件系统条目,而是将被放置到一个不可见的系统范围内的套接字名称空间中。套接字名称不是空端字符串;它是一个以NUL开头的UNIX_PATH_MAX长度字符串,任何其他的null都没有特殊的意义。因此,将这个名称补上是非常重要的,否则您将在该名称中添加额外的未初始化内存垃圾,并产生意想不到的结果。按照惯例,这通常是用NUL pad完成的,但这取决于您。
For more information, consult unix(7), and specifically the part on abstract socket addresses. A fully worked example can also be found here.
有关更多信息,请参阅unix(7),特别是有关抽象套接字地址的部分。这里还可以找到一个完整的示例。
#1
3
You can create a unix domain socket with an "abstract socket address". Simply make the first character of the sun_path
string in the sockaddr_un
you pass to bind
be '\0'
. After this initial NUL, write a string to the remainder of sun_path
and pad it out to UNIX_PATH_MAX
with NULs (or anything else).
您可以使用“抽象套接字地址”创建unix域套接字。只需在传递给bind '\0'的sockaddr_un中创建sun_path字符串的第一个字符。在这个初始NUL之后,将一个字符串写入sun_path的其余部分,并用null(或其他任何东西)将其写到UNIX_PATH_MAX中。
Sockets created this way will not have any filesystem entry, but instead will be placed into an invisible system-wide socket namespace. The socket name is not a null-terminated string; it's a UNIX_PATH_MAX length string starting with a NUL, and any other NULs have no special significance. So it's vitally important to pad out that name, or you'll put extra uninitialized memory garbage into that name, with unexpected results. By convention, this is generally done with NUL pads, but it's up to you.
这样创建的套接字将不会有任何文件系统条目,而是将被放置到一个不可见的系统范围内的套接字名称空间中。套接字名称不是空端字符串;它是一个以NUL开头的UNIX_PATH_MAX长度字符串,任何其他的null都没有特殊的意义。因此,将这个名称补上是非常重要的,否则您将在该名称中添加额外的未初始化内存垃圾,并产生意想不到的结果。按照惯例,这通常是用NUL pad完成的,但这取决于您。
For more information, consult unix(7), and specifically the part on abstract socket addresses. A fully worked example can also be found here.
有关更多信息,请参阅unix(7),特别是有关抽象套接字地址的部分。这里还可以找到一个完整的示例。