From 6a2bdc4ee2dc49b5d89d09a1f255a7a0e2f18acf Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@intel.com>
Date: Tue, 28 Oct 2014 17:23:09 -0700
Subject: [PATCH 1/3] Always lock the DBus dispatcher before
dbus_connection_send*
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We lock it before dbus_connection_send_with_reply (the async version) in
QDBusConnectionPrivate::sendWithReplyAsync. We weren't locking it before
send_with_reply_and_block and we apparently should. The locking around
the dbus_connection_send function might not be necessary, but let's do
it to be safe.
The lock now needs to be recursive because we may be inside
QDBusConnectionPrivate::doDispatch.
Task-number: QTBUG-42189
Change-Id: I7b6b350909359817ea8b3f9c693bced042c9779a
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
---
src/dbus/qdbusintegrator.cpp | 19 +++++++++++++++----
src/dbus/qdbusthreaddebug_p.h | 3 +++
2 files changed, 18 insertions(+), 4 deletions(-)
|
|
|
1017 | 1017 | |
1018 | 1018 | QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p) |
1019 | 1019 | : QObject(p), ref(1), capabilities(0), mode(InvalidMode), connection(0), server(0), busService(0), |
1020 | | watchAndTimeoutLock(QMutex::Recursive), |
| 1020 | watchAndTimeoutLock(QMutex::Recursive), dispatchLock(QMutex::Recursive), |
1021 | 1021 | rootNode(QString(QLatin1Char('/'))), |
1022 | 1022 | anonymousAuthenticationAllowed(false) |
1023 | 1023 | { |
… |
… |
|
1266 | 1266 | //qDBusDebug() << "Emitting signal" << message; |
1267 | 1267 | //qDBusDebug() << "for paths:"; |
1268 | 1268 | q_dbus_message_set_no_reply(msg, true); // the reply would not be delivered to anything |
1269 | | huntAndEmit(connection, msg, obj, rootNode, isScriptable, isAdaptor); |
| 1269 | { |
| 1270 | QDBusDispatchLocker locker(HuntAndEmitAction, this); |
| 1271 | huntAndEmit(connection, msg, obj, rootNode, isScriptable, isAdaptor); |
| 1272 | } |
1270 | 1273 | q_dbus_message_unref(msg); |
1271 | 1274 | } |
1272 | 1275 | |
… |
… |
|
1923 | 1926 | |
1924 | 1927 | qDBusDebug() << this << "sending message (no reply):" << message; |
1925 | 1928 | checkThread(); |
1926 | | bool isOk = q_dbus_connection_send(connection, msg, 0); |
| 1929 | bool isOk; |
| 1930 | { |
| 1931 | QDBusDispatchLocker locker(SendMessageAction, this); |
| 1932 | isOk = q_dbus_connection_send(connection, msg, 0); |
| 1933 | } |
1927 | 1934 | int serial = 0; |
1928 | 1935 | if (isOk) |
1929 | 1936 | serial = q_dbus_message_get_serial(msg); |
… |
… |
|
1955 | 1962 | |
1956 | 1963 | qDBusDebug() << this << "sending message (blocking):" << message; |
1957 | 1964 | QDBusErrorInternal error; |
1958 | | DBusMessage *reply = q_dbus_connection_send_with_reply_and_block(connection, msg, timeout, error); |
| 1965 | DBusMessage *reply; |
| 1966 | { |
| 1967 | QDBusDispatchLocker locker(SendWithReplyAndBlockAction, this); |
| 1968 | reply = q_dbus_connection_send_with_reply_and_block(connection, msg, timeout, error); |
| 1969 | } |
1959 | 1970 | |
1960 | 1971 | q_dbus_message_unref(msg); |
1961 | 1972 | |