aboutsummaryrefslogtreecommitdiffstats
path: root/wpa_supplicant/main.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2012-08-19 15:01:04 (GMT)
committerJouni Malinen <j@w1.fi>2012-08-19 15:01:04 (GMT)
commit392824ef1009e3efb081a22780dc337d55744235 (patch)
tree659fd45e1a7486b1661cdbe43bf07cabf167b28d /wpa_supplicant/main.c
parent3489cfb09cc21ce95f0d8b8abb31a6199b78030c (diff)
downloadhostap-392824ef1009e3efb081a22780dc337d55744235.zip
hostap-392824ef1009e3efb081a22780dc337d55744235.tar.gz
hostap-392824ef1009e3efb081a22780dc337d55744235.tar.bz2
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>
Diffstat (limited to 'wpa_supplicant/main.c')
-rw-r--r--wpa_supplicant/main.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/wpa_supplicant/main.c b/wpa_supplicant/main.c
index 3f11e9f..19f7ce6 100644
--- a/wpa_supplicant/main.c
+++ b/wpa_supplicant/main.c
@@ -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__
- int s, i;
+ static int fd[3] = { -1, -1, -1 };
+ int 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;
+ if (start) {
+ for (i = 0; i < 3; i++) {
+ fd[i] = open("/dev/null", O_RDWR);
+ if (fd[i] > 2) {
+ 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__ */
@@ -140,7 +151,7 @@ int main(int argc, char *argv[])
return -1;
iface_count = 1;
- wpa_supplicant_fd_workaround();
+ wpa_supplicant_fd_workaround(1);
for (;;) {
c = getopt(argc, argv,
@@ -288,6 +299,7 @@ int main(int argc, char *argv[])
wpa_supplicant_deinit(global);
out:
+ wpa_supplicant_fd_workaround(0);
os_free(ifaces);
os_free(params.pid_file);