gpt4 book ai didi

c - 如何更改 linux 套接字文件的权限?

转载 作者:太空狗 更新时间:2023-10-29 17:05:36 25 4
gpt4 key购买 nike

我有一个创建套接字的程序,然后我想更改套接字文件的权限:

ret_val = chmod(filename, 0777);

,但它不会改变,即使 ret_val 将为 0。如果我在常规文件上尝试相同的操作,它会起作用。

有什么想法吗?

P.S:我以 root 身份运行该程序,因此它具有所需的所有权限。

最佳答案

来自man 7 unix:

In the Linux implementation, sockets which are visible in the file system honor the permissions of the directory they are in. Their owner, group and their permissions can be changed. Creation of a new socket will fail if the process does not have write and search (execute) permission on the directory the socket is created in. Connecting to the socket object requires read/write permission. This behavior differs from many BSD-derived systems which ignore permissions for UNIX domain sockets. Portable programs should not rely on this feature for security.

所以如果你想控制一个套接字的权限,为了便携,你应该控制包含套接字的目录的权限。

关于c - 如何更改 linux 套接字文件的权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5977556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com