[Socket]Unix socket 运行权限问题

Unix socket 运行权限问题

hongxi.zhu 2023-11-13

问题:socket只能在当前源码目录运行,换个路径或者换个机子运行,如果是服务端,启动则会出现无法bind, 客户端则会出现无法connect

原因:unix socket是基于文件的fd方式访问,socket_path实际上是一个目录+文件(s文件),要确保这个文件有可读写权限

解决方法:在server端listen方法前修改socket_path的文件权限

c 复制代码
#include<sys/stat.h>

...
    chmod(socket_path, 0777); //make sure the socket path has a write permission

    ret = listen(server_fd, 5);
    if ( ret < 0) {
        perror("listen error");
        exit(1);
    }
...
相关推荐
糖~醋排骨2 小时前
DHCP服务的搭建
linux·服务器·网络
huohaiyu2 小时前
网络中的一些基本概念
运维·服务器·网络
dust_and_stars2 小时前
ubuntu24使用apt安装VS-code-server code-server
linux·服务器·windows
ling-453 小时前
Linux-day09 11
linux·运维·服务器
zbguolei3 小时前
Debian提示:“用户名” 不是 sudoers 文件
linux·服务器·debian
zhangdawei8384 小时前
英伟达GB200,GB300和普通服务器如dell R740xd有什么区别?
运维·服务器·人工智能
糖~醋排骨4 小时前
FW防火墙的配置
linux·服务器·网络
2301_780943844 小时前
linux 对文件打补丁(Patch)
linux·运维·服务器
Lam㊣5 小时前
服务器端口转发的方法
linux·服务器
ChangYan.5 小时前
Windows命令行(cmd)下快速查找文件路径(类似Linux下find命令)
linux·运维·服务器