在哪里放置 Unix 域 (AF_UNIX) 套接字?端点(文件)?
是否有约定将表示 Unix 域套接字端点的“文件”放置在何处?
我倾向于将它们放在 /tmp/some-application-specific-subdir-name/
中,但我想知道是否有更常见的地方。
背景是, POSIX 并不清楚 访问此类“文件”的最大路径长度:
sun_path 的大小故意未定义。这是因为不同的实现使用不同的大小。例如,4.3 BSD 使用的大小为 108,4.4 BSD 使用的大小为 104。由于大多数实现源自 BSD 版本,因此大小通常在 92 到 108 的范围内。
应用程序不应假定 sun_path 的特定长度或假定它可以容纳 {_POSIX_PATH_MAX} 字节 (256)。
因此,这种对路径长度的“限制”应该保留在应用程序的文件/路径名配置之外。
Is there a convention where to place the 'files' representing the end points to Unix Domain Sockets?
I tend to put them to /tmp/some-application-specific-subdir-name/
, but I wonder if there is a more common place.
The background is, that POSIX is not clear about the maximum path length to access such 'files':
The size of sun_path has intentionally been left undefined. This is because different implementations use different sizes. For example, 4.3 BSD uses a size of 108, and 4.4 BSD uses a size of 104. Since most implementations originate from BSD versions, the size is typically in the range 92 to 108.
Applications should not assume a particular length for sun_path or assume that it can hold {_POSIX_PATH_MAX} bytes (256).
So this "restriction" on the path's length should be kept out of the application's file/path name configurations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
FHS 说:FHS 说: linuxfoundation.org/FHS_3.0/fhs/ch03s15.html" rel="noreferrer">
/run
(以前是
/var/run
。)The FHS says:
/run
(It used to be
/var/run
.)在 Ubuntu 上,
netstat
命令在多个不同位置显示 UNIX 域套接字。正如 JB 所建议的,有些,但是少数,在/var/run
中;其中大部分位于@/tmp/...
中(我相信@
指定抽象名称,这是 Linux 特定的),还有一些位于各种应用程序的特定位置。所以在实践中,最常见的位置似乎是在/tmp
中,至少在 Ubuntu 上是这样,这是一个相当常见的平台。请注意,/tmp
位置在这里特别有意义,因为 UDS 必须由每个bind
创建,并在之后删除(当套接字关闭时,或者当应用程序关闭时)退出,或者当应用程序下次启动时以及在下次调用bind
之前)。On Ubuntu, the
netstat
command shows UNIX Domain Sockets in multiple different places. Some, however a few, in/var/run
, as JB suggested; most of them in@/tmp/…
(I believe the@
designate abstract names, which is Linux specific), and some others in various application's specific places. So in practice, the most common location seems to be in/tmp
, at least on Ubuntu, which is a rather common platform. Note the/tmp
location particularly makes sense here, as UDS has to be created by eachbind
and to be deleted afterwards (either when the socket is closed, or when the application exit, or when the application starts the next time and before its next invocation tobind
).在 Android 中,您可以将其放置在
/dev/socket/
中In Android you can place it in
/dev/socket/