]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wpa_cli: Fix detach race with forked monitor process
authorJouni Malinen <jouni.malinen@atheros.com>
Fri, 12 Mar 2010 15:34:56 +0000 (17:34 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 12 Mar 2010 15:34:56 +0000 (17:34 +0200)
Need to kill the monitor process before running detach command on
the monitor connection to avoid race where the monitor process may
end up getting the detach command result.

wpa_supplicant/wpa_cli.c

index 454852c1240d1cc58716f6df989ae6b361719289..924ad96a163523da73c702e81bd04e286a8b74a8 100644 (file)
@@ -255,6 +255,15 @@ static void wpa_cli_close_connection(void)
        if (ctrl_conn == NULL)
                return;
 
+#ifdef CONFIG_WPA_CLI_FORK
+       if (mon_pid) {
+               int status;
+               kill(mon_pid, SIGPIPE);
+               wait(&status);
+               mon_pid = 0;
+       }
+#endif /* CONFIG_WPA_CLI_FORK */
+
        if (wpa_cli_attached) {
                wpa_ctrl_detach(interactive ? mon_conn : ctrl_conn);
                wpa_cli_attached = 0;
@@ -265,14 +274,6 @@ static void wpa_cli_close_connection(void)
                wpa_ctrl_close(mon_conn);
                mon_conn = NULL;
        }
-#ifdef CONFIG_WPA_CLI_FORK
-       if (mon_pid) {
-               int status;
-               kill(mon_pid, SIGPIPE);
-               wait(&status);
-               mon_pid = 0;
-       }
-#endif /* CONFIG_WPA_CLI_FORK */
 }