Commit 8dbd0f31 authored by Volker Krause's avatar Volker Krause
Browse files

Fix various startup/shutdown issues:

- no more spurious error messages about a failed startup blaming your
  D-Bus setup
- disconnect from the database befor shutting down to make the MySQL
  shutdown a lot faster
- fix crash on shutdown due to socket deletion from the wrong thread

svn path=/trunk/KDE/kdepim/akonadi/; revision=756017
parent c8772c9a
......@@ -28,6 +28,10 @@
item part names, etc. and replace the usages accordingly.
*/
// D-Bus service names
#define AKONADI_DBUS_SERVER_SERVICE "org.kde.Akonadi"
#define AKONADI_DBUS_CONTROL_SERVICE "org.kde.Akonadi.Control"
// item part names
#define AKONADI_PART_BODY "RFC822"
......
......@@ -8,6 +8,7 @@ set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" )
########### next target ###############
set( akonadictl_SRCS
akonadistarter.cpp
main.cpp
)
......
/*
Copyright (c) 2008 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "akonadistarter.h"
#include <libakonadi/protocol.h>
#include <QCoreApplication>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDebug>
#include <QProcess>
#include <QTimer>
AkonadiStarter::AkonadiStarter(QObject * parent) :
QObject( parent ),
mRegistered( false )
{
connect( QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
SLOT( serviceOwnerChanged(QString,QString,QString)) );
}
bool AkonadiStarter::start()
{
qDebug( "Starting Akonadi Server..." );
const bool ok = QProcess::startDetached( "akonadi_control" );
if ( !ok ) {
qDebug( "Error: unable to execute binary akonadi_control" );
return false;
}
// safety timeout
QTimer::singleShot( 5000, QCoreApplication::instance(), SLOT(quit()) );
// wait for the server to register with D-Bus
QCoreApplication::instance()->exec();
if ( !mRegistered ) {
qDebug( "Error: akonadi_control was started but didn't register at D-Bus session bus." );
qDebug( "Make sure your system is setup correctly!" );
return false;
}
qDebug( " done." );
return true;
}
void AkonadiStarter::serviceOwnerChanged(const QString & name, const QString & oldOwner, const QString & newOwner)
{
Q_UNUSED( oldOwner );
if ( name != QLatin1String( AKONADI_DBUS_CONTROL_SERVICE ) || newOwner.isEmpty() )
return;
mRegistered = true;
QCoreApplication::instance()->quit();
}
#include "akonadistarter.moc"
/*
Copyright (c) 2008 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef AKONADISTARTER_H
#define AKONADISTARTER_H
#include <QtCore/QObject>
class AkonadiStarter : public QObject
{
Q_OBJECT
public:
explicit AkonadiStarter( QObject *parent = 0 );
bool start();
private slots:
void serviceOwnerChanged( const QString &name, const QString &oldOwner, const QString &newOwner );
private:
bool mRegistered;
};
#endif
......@@ -19,13 +19,15 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QProcess>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusConnectionInterface>
#include <libakonadi/protocol.h>
#include "controlmanagerinterface.h"
#include "akonadistarter.h"
static void printHelp( const QString &app )
{
......@@ -39,27 +41,18 @@ static void printHelp( const QString &app )
static bool startServer()
{
qDebug( "Starting Akonadi Server..." );
const bool ok = QProcess::startDetached( "akonadi_control" );
if ( !ok ) {
qDebug( "Error: unable to execute binary akonadi_control" );
return false;
}
const bool registered = QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.Akonadi.Control" );
if ( !registered ) {
qDebug( "Error: akonadi_control was started but didn't register at DBus session bus." );
qDebug( "Make sure your DBus system is setup correctly!" );
if ( QDBusConnection::sessionBus().interface()->isServiceRegistered( AKONADI_DBUS_CONTROL_SERVICE )
|| QDBusConnection::sessionBus().interface()->isServiceRegistered( AKONADI_DBUS_SERVER_SERVICE ) ) {
qDebug() << "Akonadi is already running.";
return false;
}
qDebug( " done." );
return true;
AkonadiStarter starter;
return starter.start();
}
static bool stopServer()
{
org::kde::Akonadi::ControlManager iface( "org.kde.Akonadi.Control", "/ControlManager", QDBusConnection::sessionBus(), 0 );
org::kde::Akonadi::ControlManager iface( AKONADI_DBUS_CONTROL_SERVICE, "/ControlManager", QDBusConnection::sessionBus(), 0 );
iface.shutdown();
return true;
......@@ -67,10 +60,10 @@ static bool stopServer()
static bool statusServer()
{
bool registered = QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.Akonadi.Control" );
bool registered = QDBusConnection::sessionBus().interface()->isServiceRegistered( AKONADI_DBUS_CONTROL_SERVICE );
qDebug( "Akonadi Control: %s", registered ? "running" : "stopped" );
registered = QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.Akonadi" );
registered = QDBusConnection::sessionBus().interface()->isServiceRegistered( AKONADI_DBUS_SERVER_SERVICE );
qDebug( "Akonadi Server: %s", registered ? "running" : "stopped" );
return true;
......
......@@ -33,6 +33,8 @@
#include <QtDBus/QDBusError>
#include <QtCore/QDebug>
using Akonadi::ProcessControl;
AgentManager::AgentManager( QObject *parent )
: QObject( parent )
{
......@@ -84,12 +86,14 @@ AgentManager::~AgentManager()
void AgentManager::cleanup()
{
foreach ( const AgentInstanceInfo info, mAgentInstances ) {
info.controller->setCrashPolicy( ProcessControl::StopOnCrash );
if ( info.agentInterface && info.agentInterface->isValid() )
info.agentInterface->quit();
}
mAgentInstances.clear();
mStorageController->setCrashPolicy( ProcessControl::StopOnCrash );
org::kde::Akonadi::Server *serverIface = new org::kde::Akonadi::Server( "org.kde.Akonadi", "/Server",
QDBusConnection::sessionBus(), this );
serverIface->quit();
......
......@@ -139,12 +139,14 @@ void AkonadiServer::quit()
mConnections[ i ]->wait();
}
}
// execute the deleteLater() calls for the threads so they free their db connections
// and the following db termination will work
QCoreApplication::instance()->processEvents();
QSettings settings( XdgBaseDirs::akonadiServerConfigFile(), QSettings::IniFormat );
if ( settings.value( QLatin1String("General/Driver") ).toString() == QLatin1String( "QMYSQL" )
&& settings.value( QLatin1String( "QMYSQL/StartServer" ), true ).toBool() )
if ( mDatabaseProcess )
stopDatabaseProcess();
QSettings settings( XdgBaseDirs::akonadiServerConfigFile(), QSettings::IniFormat );
const QString connectionSettingsFile = XdgBaseDirs::akonadiConnectionConfigFile( XdgBaseDirs::WriteOnly );
#ifndef Q_OS_WIN
......
......@@ -58,7 +58,6 @@ AkonadiConnection::~AkonadiConnection()
{
Tracer::self()->endConnection( m_identifier, QString() );
delete m_tcpSocket;
delete m_parser;
}
......@@ -89,6 +88,8 @@ void AkonadiConnection::run()
writeOut( "* OK Akonadi Almost IMAP Server");
exec();
delete m_tcpSocket;
m_tcpSocket = 0;
}
void AkonadiConnection::slotDisconnected()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment