From f5bfc641c38ca0dbd37c8993bc74f81c7e0c9b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Tue, 6 May 2014 15:27:07 +0200 Subject: [PATCH 4/7] Fix PostgreSQL startup when akonadiserverrc contains empty values When there are empty configuration options in akonadiserverrc (like Host), we would still pick them up and use them as valid values, which is wrong, because then we work with empty socket path etc. Instead we always replace non-existent and empty config values with the default ones, so that Akonadi with PostgreSQL is always able to start. --- server/src/storage/dbconfigpostgresql.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/server/src/storage/dbconfigpostgresql.cpp b/server/src/storage/dbconfigpostgresql.cpp index 10460d4..66e4605 100644 --- a/server/src/storage/dbconfigpostgresql.cpp +++ b/server/src/storage/dbconfigpostgresql.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -90,13 +91,29 @@ bool DbConfigPostgresql::init( QSettings &settings ) // read settings for current driver settings.beginGroup( driverName() ); mDatabaseName = settings.value( QLatin1String( "Name" ), defaultDatabaseName() ).toString(); + if ( mDatabaseName.isEmpty() ) { + mDatabaseName = defaultDatabaseName(); + } mHostName = settings.value( QLatin1String( "Host" ), defaultHostName ).toString(); + if ( mHostName.isEmpty() ) { + mHostName = defaultHostName; + } + // User, password and Options can be empty and still valid, so don't override them mUserName = settings.value( QLatin1String( "User" ) ).toString(); mPassword = settings.value( QLatin1String( "Password" ) ).toString(); mConnectionOptions = settings.value( QLatin1String( "Options" ), defaultOptions ).toString(); mServerPath = settings.value( QLatin1String( "ServerPath" ), defaultServerPath ).toString(); + if ( mInternalServer && mServerPath.isEmpty() ) { + mServerPath = defaultServerPath; + } mInitDbPath = settings.value( QLatin1String( "InitDbPath" ), defaultInitDbPath ).toString(); + if ( mInternalServer && mInitDbPath.isEmpty() ) { + mInitDbPath = defaultInitDbPath; + } mPgData = settings.value( QLatin1String( "PgData" ), defaultPgData ).toString(); + if ( mPgData.isEmpty() ) { + mPgData = defaultPgData; + } settings.endGroup(); // store back the default values @@ -104,12 +121,8 @@ bool DbConfigPostgresql::init( QSettings &settings ) settings.setValue( QLatin1String( "Name" ), mDatabaseName ); settings.setValue( QLatin1String( "Host" ), mHostName ); settings.setValue( QLatin1String( "Options" ), mConnectionOptions ); - if ( !mServerPath.isEmpty() ) { - settings.setValue( QLatin1String( "ServerPath" ), mServerPath ); - } - if ( !mInitDbPath.isEmpty() ) { - settings.setValue( QLatin1String( "InitDbPath" ), mInitDbPath ); - } + settings.setValue( QLatin1String( "ServerPath" ), mServerPath ); + settings.setValue( QLatin1String( "InitDbPath" ), mInitDbPath ); settings.setValue( QLatin1String( "StartServer" ), mInternalServer ); settings.endGroup(); settings.sync(); @@ -203,7 +216,7 @@ void DbConfigPostgresql::startInternalServer() break; } - if ( pgCtl.waitForFinished( 500 ) ) { + if ( pgCtl.waitForFinished( 500 ) && pgCtl.exitCode() ) { akError() << "Database process exited unexpectedly during initial connection!"; akError() << "executable:" << mServerPath; akError() << "arguments:" << arguments; -- 1.9.3