aboutsummaryrefslogtreecommitdiff
path: root/src/adbd-client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/adbd-client.cpp')
-rw-r--r--src/adbd-client.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/adbd-client.cpp b/src/adbd-client.cpp
index 400c7c9..47914cb 100644
--- a/src/adbd-client.cpp
+++ b/src/adbd-client.cpp
@@ -23,6 +23,7 @@
#include <gio/gunixsocketaddress.h>
#include <algorithm>
+#include <atomic>
#include <cctype>
#include <cstring>
#include <chrono>
@@ -48,7 +49,9 @@ public:
g_cancellable_cancel(m_cancellable);
m_pkresponse_cv.notify_one();
m_sleep_cv.notify_one();
- m_worker_thread.join();
+ if (m_worker_thread.joinable()) {
+ m_worker_thread.join();
+ }
g_clear_object(&m_cancellable);
}
@@ -66,7 +69,7 @@ private:
GCancellable* cancellable = nullptr;
const std::string public_key;
- PKIdleData(Impl* self_, GCancellable* cancellable_, std::string public_key_):
+ PKIdleData(Impl* self_, GCancellable* cancellable_, const std::string& public_key_):
self(self_),
cancellable(G_CANCELLABLE(g_object_ref(cancellable_))),
public_key(public_key_) {}
@@ -104,8 +107,9 @@ private:
void on_public_key_response(PKResponse response)
{
+ g_debug("%s thread %p got response %d", G_STRLOC, g_thread_self(), int(response));
+
// set m_pkresponse and wake up the waiting worker thread
- std::unique_lock<std::mutex> lk(m_pkresponse_mutex);
m_pkresponse = response;
m_pkresponse_ready = true;
m_pkresponse_cv.notify_one();
@@ -121,11 +125,11 @@ private:
while (!g_cancellable_is_cancelled(m_cancellable))
{
- g_debug("%s creating a client socket to '%s'", G_STRLOC, socket_path.c_str());
+ g_debug("%s thread %p creating a client socket to '%s'", G_STRLOC, g_thread_self(), socket_path.c_str());
auto socket = create_client_socket(socket_path);
bool got_valid_req = false;
- g_debug("%s calling read_request", G_STRLOC);
+ g_debug("%s thread %p calling read_request", g_thread_self(), G_STRLOC);
std::string reqstr;
if (socket != nullptr)
reqstr = read_request(socket);
@@ -135,22 +139,25 @@ private:
if (reqstr.substr(0,2) == "PK") {
PKResponse response = PKResponse::DENY;
const auto public_key = reqstr.substr(2);
- g_debug("%s got pk [%s]", G_STRLOC, public_key.c_str());
+ g_debug("%s thread %p got pk [%s]", G_STRLOC, g_thread_self(), public_key.c_str());
if (!public_key.empty()) {
got_valid_req = true;
std::unique_lock<std::mutex> lk(m_pkresponse_mutex);
m_pkresponse_ready = false;
+ m_pkresponse = AdbdClient::PKResponse::DENY;
pass_public_key_to_main_thread(public_key);
m_pkresponse_cv.wait(lk, [this](){
return m_pkresponse_ready || g_cancellable_is_cancelled(m_cancellable);
});
response = m_pkresponse;
- g_debug("%s got response '%d', is-cancelled %d", G_STRLOC,
+ g_debug("%s thread %p got response '%d', is-cancelled %d", G_STRLOC,
+ g_thread_self(),
int(response),
int(g_cancellable_is_cancelled(m_cancellable)));
}
- if (!g_cancellable_is_cancelled(m_cancellable))
+ if (!g_cancellable_is_cancelled(m_cancellable)) {
send_pk_response(socket, response);
+ }
} else if (!reqstr.empty()) {
g_warning("Invalid ADB request: [%s]", reqstr.c_str());
}
@@ -270,7 +277,7 @@ private:
std::mutex m_pkresponse_mutex;
std::condition_variable m_pkresponse_cv;
- bool m_pkresponse_ready = false;
+ std::atomic<bool> m_pkresponse_ready {false};
PKResponse m_pkresponse = PKResponse::DENY;
};