summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@theqtcompany.com>2015-02-17 17:39:14 +0100
committerGatis Paeglis <gatis.paeglis@theqtcompany.com>2015-02-19 12:36:43 +0200
commit7b14c47d6adbc6ab3cdfc9d10bef25029215a85f (patch)
tree2653e422f897bac708bad96a2f0d9fa3a796735a
parentb23bcb38a90bb5820b34139576c04fed9f6d6309 (diff)
Prevent reading wifi events from closed connection
Stop wifi event thread before closing down a connection to wpa-supplicant to avoid race-condition where we can end up reading events from closed socket and blocking the new connection from attaching to the socket. Change-Id: Ie1efabf35791e0dac3f57fa8038b0e414cbff1f5 Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
-rw-r--r--src/wifi/qwificontroller.cpp10
-rw-r--r--src/wifi/qwificontroller_p.h2
-rw-r--r--src/wifi/qwifimanager.cpp4
3 files changed, 7 insertions, 9 deletions
diff --git a/src/wifi/qwificontroller.cpp b/src/wifi/qwificontroller.cpp
index 216c70c..7b8be80 100644
--- a/src/wifi/qwificontroller.cpp
+++ b/src/wifi/qwificontroller.cpp
@@ -278,7 +278,6 @@ void QWifiController::initializeBackend()
}
#endif
if (!initFailed && resetSupplicantSocket()) {
- startWifiEventThread();
qCDebug(B2QT_WIFI) << "wifi backend started successfully";
emit backendStateChanged(QWifiManager::Running);
} else {
@@ -286,11 +285,10 @@ void QWifiController::initializeBackend()
}
}
-bool QWifiController::resetSupplicantSocket() const
+bool QWifiController::resetSupplicantSocket()
{
qCDebug(B2QT_WIFI) << "reset supplicant socket";
- // close down the previous connection to supplicant if
- // one exists before re-connecting.
+ exitWifiEventThread();
if (q_wifi_stop_supplicant() < 0)
qCWarning(B2QT_WIFI) << "failed to stop supplicant!";
q_wifi_close_supplicant_connection(m_interface);
@@ -310,6 +308,7 @@ bool QWifiController::resetSupplicantSocket() const
qCWarning(B2QT_WIFI) << "failed to connect to a supplicant!";
return false;
}
+ startWifiEventThread();
return true;
}
@@ -345,7 +344,8 @@ void QWifiController::exitWifiEventThread()
if (m_eventThread->isRunning()) {
m_exitEventThread = true;
m_managerPrivate->call(QStringLiteral("SCAN"));
- m_eventThread->wait();
+ if (!m_eventThread->wait(8000))
+ qCWarning(B2QT_WIFI, "timed out waiting for wifi event thread to exit!");
}
}
diff --git a/src/wifi/qwificontroller_p.h b/src/wifi/qwificontroller_p.h
index 63ad2ef..185cff9 100644
--- a/src/wifi/qwificontroller_p.h
+++ b/src/wifi/qwificontroller_p.h
@@ -97,7 +97,7 @@ public:
void startWifiEventThread();
void acquireIPAddress();
void stopDhcp() const;
- bool resetSupplicantSocket() const;
+ bool resetSupplicantSocket();
signals:
void backendStateChanged(QWifiManager::BackendState backendState);
diff --git a/src/wifi/qwifimanager.cpp b/src/wifi/qwifimanager.cpp
index 14d839e..7585cf2 100644
--- a/src/wifi/qwifimanager.cpp
+++ b/src/wifi/qwifimanager.cpp
@@ -123,10 +123,8 @@ void QWifiManagerPrivate::updateWifiState()
if (ps.readAll().contains("wpa_supplicant"))
supplicantRunning = true;
#endif
- if (supplicantRunning && m_wifiController->resetSupplicantSocket()) {
- m_wifiController->startWifiEventThread();
+ if (supplicantRunning && m_wifiController->resetSupplicantSocket())
m_backendState = QWifiManager::Running;
- }
}
QString QWifiManagerPrivate::call(const QString &command)