Ticket #46496: Always-lock-the-DBus-dispatcher-before-dbus_connecti.patch

File Always-lock-the-DBus-dispatcher-before-dbus_connecti.patch, 3.3 KB (added by RJVB (René Bertin), 10 years ago)

from Ubuntu

  • qtbase/src/dbus/qdbusintegrator.cpp

    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(-)
    
     
    10171017
    10181018QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p)
    10191019    : 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),
    10211021      rootNode(QString(QLatin1Char('/'))),
    10221022      anonymousAuthenticationAllowed(false)
    10231023{
     
    12661266    //qDBusDebug() << "Emitting signal" << message;
    12671267    //qDBusDebug() << "for paths:";
    12681268    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    }
    12701273    q_dbus_message_unref(msg);
    12711274}
    12721275
     
    19231926
    19241927    qDBusDebug() << this << "sending message (no reply):" << message;
    19251928    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    }
    19271934    int serial = 0;
    19281935    if (isOk)
    19291936        serial = q_dbus_message_get_serial(msg);
     
    19551962
    19561963        qDBusDebug() << this << "sending message (blocking):" << message;
    19571964        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        }
    19591970
    19601971        q_dbus_message_unref(msg);
    19611972
  • qtbase/src/dbus/qdbusthreaddebug_p.h

     
    9494    MessageResultReceivedAction = 26,
    9595    ActivateSignalAction = 27,
    9696    PendingCallBlockAction = 28,
     97    SendMessageAction = 29,
     98    SendWithReplyAndBlockAction = 30,
     99    HuntAndEmitAction = 31,
    97100
    98101    AddTimeoutAction = 50,
    99102    RealAddTimeoutAction = 51,