aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHolger Schröder <holger.schroeder.ext@basyskom.de>2011-01-19 17:36:05 +0100
committerHolger Schröder <holger.schroeder.ext@basyskom.de>2011-01-19 18:03:09 +0100
commitfb56abb143616105032ac7f33d0bcfdff8e8dd24 (patch)
treecb67fbdd9d29f154a9e5454fcc7181a6238f8ca4 /src
parentcf059a523c0934c50db128dc2ce800e6e93e0046 (diff)
Fixes: NB#209179 - QDBusConnection created before MApplication instantiation leads to threading issues
RevBy: Armin Berres Details: According to the qt bugtracker, the behaviour of QDBusConnection::sessionBus() and QDBusConnection::systemBus() is undefined, when they are used before the QApplication construnctor was executed. Because of this we defer the creation of the sessionBus until it is accessed the first time. And we do write an error message when the sessionBus is accessed before the qApp instance exists.
Diffstat (limited to 'src')
-rw-r--r--src/corelib/core/mapplicationservice_p.cpp42
-rw-r--r--src/corelib/core/mapplicationservice_p.h4
2 files changed, 41 insertions, 5 deletions
diff --git a/src/corelib/core/mapplicationservice_p.cpp b/src/corelib/core/mapplicationservice_p.cpp
index de64a3fb..8b9eb2bc 100644
--- a/src/corelib/core/mapplicationservice_p.cpp
+++ b/src/corelib/core/mapplicationservice_p.cpp
@@ -31,7 +31,7 @@ MApplicationServicePrivate::MApplicationServicePrivate(const QString &newService
registered(false),
instanceCounter(0),
q_ptr(NULL),
- dBusConnection(QDBusConnection::sessionBus()),
+ pDBusConnection(NULL),
mApp(MApplication::instance())
{
}
@@ -40,6 +40,37 @@ MApplicationServicePrivate::~MApplicationServicePrivate()
{
}
+static QString getexepath()
+{
+ char result[ 255 ];
+ memset( result, 0, 255 );
+ readlink( "/proc/self/exe", result, 254 );
+ return QString( result );
+}
+
+void MApplicationServicePrivate::ensureDBusConnection()
+{
+ // here we create the dbusconnection only when needed
+ // the behaviour of a QDBusConnection::sessionBus()
+ // or QDBusConnection::systemBus() is undefined, when it
+ // is instantiated before the QApplication constructor
+ // is finished.
+ if ( ! pDBusConnection )
+ {
+ if ( ! QCoreApplication::instance() )
+ {
+ qCritical() << "error: MApplicationServicePrivate::ensureDBusConnection"
+ " without QCoreApplication::instance. pid: "
+ << getpid() << "appname:" << getexepath();
+ }
+
+ static QDBusConnection myDBusConnection = QDBusConnection::sessionBus();
+
+ // now initialize the connection
+ pDBusConnection = &myDBusConnection;
+ }
+}
+
void MApplicationServicePrivate::launchNewProcess(const QString &binaryName, const QStringList &arguments)
{
QProcess *myProcess = new QProcess();
@@ -53,17 +84,20 @@ void MApplicationServicePrivate::launchNewProcess(const QString &binaryName, con
bool MApplicationServicePrivate::registerService(const QString &serviceName)
{
- return dBusConnection.registerService(serviceName);
+ ensureDBusConnection();
+ return pDBusConnection->registerService(serviceName);
}
void MApplicationServicePrivate::registerObject(const QString &path, QObject *object)
{
- dBusConnection.registerObject(path, object);
+ ensureDBusConnection();
+ pDBusConnection->registerObject(path, object);
}
void MApplicationServicePrivate::unregisterObject(const QString &path)
{
- dBusConnection.unregisterObject(path);
+ ensureDBusConnection();
+ pDBusConnection->unregisterObject(path);
}
QString MApplicationServicePrivate::appName()
diff --git a/src/corelib/core/mapplicationservice_p.h b/src/corelib/core/mapplicationservice_p.h
index 8f622e1b..34190320 100644
--- a/src/corelib/core/mapplicationservice_p.h
+++ b/src/corelib/core/mapplicationservice_p.h
@@ -59,8 +59,10 @@ protected:
bool isPrestarted();
bool activeWindowSet();
+ void ensureDBusConnection();
+
private:
- QDBusConnection dBusConnection;
+ QDBusConnection *pDBusConnection;
MApplication *mApp;
};