systembus-usage.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. commit 88c6e9334c8440721189ef7d020fa94d47f30f8b
  2. Author: Harald Sitter <sitter@kde.org>
  3. Date: Fri Aug 1 16:34:03 2014 +0200
  4. do not use global static systembus instance
  5. global static destruction order cannot be controlled and we need our bus
  6. to disconnect from the consolekit signals, so use our own bus instance
  7. to connect to systembus signals
  8. REVIEW: 119545
  9. diff --git a/core/polkitqt1-authority.cpp b/core/polkitqt1-authority.cpp
  10. index dd014cf..f25354d 100644
  11. --- a/core/polkitqt1-authority.cpp
  12. +++ core/polkitqt1-authority.cpp
  13. @@ -83,7 +83,10 @@ public:
  14. // Polkit will return NULL on failures, hence we use it instead of 0
  15. Private(Authority *qq) : q(qq)
  16. , pkAuthority(NULL)
  17. - , m_hasError(false) {}
  18. + , m_hasError(false)
  19. + , m_systemBus(0)
  20. + {
  21. + }
  22. ~Private();
  23. @@ -103,6 +106,13 @@ public:
  24. bool m_hasError;
  25. Authority::ErrorCode m_lastError;
  26. QString m_errorDetails;
  27. + // Local system bus. QDBusConnection::systemBus() may only be savely used
  28. + // inside a QCoreApplication scope as for example destruction of connected
  29. + // objects need to happen before the bus disappears. Since this class however
  30. + // is a global static and systemBus() internally is a global static we
  31. + // cannot assure destruction order. Instead we create a local copy of the
  32. + // global systemBus instance so we can make life time to our needs.
  33. + // This prevents crashes when cleaning up the global statics.
  34. QDBusConnection *m_systemBus;
  35. GCancellable *m_checkAuthorizationCancellable,
  36. *m_enumerateActionsCancellable,
  37. @@ -127,6 +137,7 @@ public:
  38. Authority::Private::~Private()
  39. {
  40. + delete m_systemBus;
  41. g_object_unref(m_checkAuthorizationCancellable);
  42. g_object_unref(m_enumerateActionsCancellable);
  43. g_object_unref(m_registerAuthenticationAgentCancellable);
  44. @@ -170,6 +181,9 @@ void Authority::Private::init()
  45. g_type_init();
  46. + m_systemBus = new QDBusConnection(QDBusConnection::connectToBus(QDBusConnection::SystemBus,
  47. + QString("polkit_qt_system_bus")));
  48. +
  49. m_checkAuthorizationCancellable = g_cancellable_new();
  50. m_enumerateActionsCancellable = g_cancellable_new();
  51. m_registerAuthenticationAgentCancellable = g_cancellable_new();
  52. @@ -219,7 +233,7 @@ void Authority::Private::init()
  53. // then we need to extract all seats from ConsoleKit
  54. QDBusMessage msg = QDBusMessage::createMethodCall(consoleKitService, consoleKitManagerPath, consoleKitManagerInterface, "GetSeats");
  55. - msg = QDBusConnection::systemBus().call(msg);
  56. + msg = m_systemBus->call(msg);
  57. if (!msg.arguments().isEmpty()) {
  58. // this method returns a list with present seats
  59. QList<QString> seats;
  60. @@ -256,8 +270,7 @@ void Authority::Private::seatSignalsConnect(const QString &seat)
  61. void Authority::Private::dbusSignalAdd(const QString &service, const QString &path, const QString &interface, const QString &name)
  62. {
  63. // FIXME: This code seems to be nonfunctional - it needs to be fixed somewhere (is it Qt BUG?)
  64. - QDBusConnection::systemBus().connect(service, path, interface, name,
  65. - q, SLOT(dbusFilter(QDBusMessage)));
  66. + m_systemBus->connect(service, path, interface, name, q, SLOT(dbusFilter(QDBusMessage)));
  67. }
  68. void Authority::Private::dbusFilter(const QDBusMessage &message)