static void wpa_supplicant_fd_workaround(void)
{
#ifdef __linux__
int s, i;
/* When started from pcmcia-cs scripts, wpa_supplicant might start with
* fd 0, 1, and 2 closed. This will cause some issues because many
* places in wpa_supplicant are still printing out to stdout. As a
* workaround, make sure that fd's 0, 1, and 2 are not used for other
* sockets. */
for (i = 0; i < 3; i++) {
s = open("/dev/null", O_RDWR);
if (s > 2) {
close(s);
break;
}
}
#endif /* __linux__ */
}
代码如上。
写入/dev/null的东西会被系统丢掉
就像注释写的那样,对stdin/stdout/stderr进行保留。
代码中利用while先把文件描述符0,1,2(fd0,fd1,fd2)分配出去,
以后再分配的时候就不会将stdin/stdout/stderr打开,以达到保留目的。
本文介绍了解决Linux环境下wpa_supplicant启动时可能遇到的文件描述符冲突问题的方法,通过确保fd0, fd1, fd2不被用于其他socket,以保留对stdin/stdout/stderr的访问。

被折叠的 条评论
为什么被折叠?



