Clean up the closed stdin/stdout/stderr workaround to close sockets
Close the workaround sockets when wpa_supplicant exists to avoid hitting resource leak warnings. Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
3489cfb09c
commit
392824ef10
1 changed files with 20 additions and 8 deletions
|
@ -101,20 +101,31 @@ static void license(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void wpa_supplicant_fd_workaround(void)
|
static void wpa_supplicant_fd_workaround(int start)
|
||||||
{
|
{
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
int s, i;
|
static int fd[3] = { -1, -1, -1 };
|
||||||
|
int i;
|
||||||
/* When started from pcmcia-cs scripts, wpa_supplicant might start with
|
/* When started from pcmcia-cs scripts, wpa_supplicant might start with
|
||||||
* fd 0, 1, and 2 closed. This will cause some issues because many
|
* 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
|
* 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
|
* workaround, make sure that fd's 0, 1, and 2 are not used for other
|
||||||
* sockets. */
|
* sockets. */
|
||||||
for (i = 0; i < 3; i++) {
|
if (start) {
|
||||||
s = open("/dev/null", O_RDWR);
|
for (i = 0; i < 3; i++) {
|
||||||
if (s > 2) {
|
fd[i] = open("/dev/null", O_RDWR);
|
||||||
close(s);
|
if (fd[i] > 2) {
|
||||||
break;
|
close(fd[i]);
|
||||||
|
fd[i] = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
if (fd[i] >= 0) {
|
||||||
|
close(fd[i]);
|
||||||
|
fd[i] = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* __linux__ */
|
#endif /* __linux__ */
|
||||||
|
@ -140,7 +151,7 @@ int main(int argc, char *argv[])
|
||||||
return -1;
|
return -1;
|
||||||
iface_count = 1;
|
iface_count = 1;
|
||||||
|
|
||||||
wpa_supplicant_fd_workaround();
|
wpa_supplicant_fd_workaround(1);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
c = getopt(argc, argv,
|
c = getopt(argc, argv,
|
||||||
|
@ -288,6 +299,7 @@ int main(int argc, char *argv[])
|
||||||
wpa_supplicant_deinit(global);
|
wpa_supplicant_deinit(global);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
wpa_supplicant_fd_workaround(0);
|
||||||
os_free(ifaces);
|
os_free(ifaces);
|
||||||
os_free(params.pid_file);
|
os_free(params.pid_file);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue