[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdesupport/soprano/backends/virtuoso
From: Sebastian Trueg <sebastian () trueg ! de>
Date: 2010-02-11 11:02:37
Message-ID: 1265886157.377729.27185.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1088673 by trueg:
Introduced new parameter "forcedstart" which will shut down any running instance of \
Virtuoso accessing the storage dir.
M +2 -0 CMakeLists.txt
M +4 -1 Virtuoso.dox
M +40 -7 virtuosocontroller.cpp
M +1 -0 virtuosocontroller.h
--- trunk/kdesupport/soprano/backends/virtuoso/CMakeLists.txt #1088672:1088673
@@ -8,6 +8,7 @@
${soprano_core_BINARY_DIR}
${QT_INCLUDES}
${soprano_SOURCE_DIR}
+ ${soprano_SOURCE_DIR}/server
${virtuoso_BINARY_DIR}
${IODBC_INCLUDE_DIR}
)
@@ -24,6 +25,7 @@
odbcconnectionpool.cpp
odbcqueryresult.cpp
${soprano_core_SOURCE_DIR}/sopranodirs.cpp
+ ${soprano_SOURCE_DIR}/server/lockfile.cpp
)
qt4_automoc(${SRC})
--- trunk/kdesupport/soprano/backends/virtuoso/Virtuoso.dox #1088672:1088673
@@ -30,8 +30,11 @@
* - \c CheckpointInterval - The interval in minutes at which Virtuoso will \
automatically make a database checkpoint. Defaults to 60.
* - \c MinAutoCheckpointSize - The minimum size of the Virtuoso transaction log. An \
automatic checkpoint will not be made if there is
* less than MinAutoCheckpointSize bytes in the current \
transaction log. Defaults to 4000000. + * - \c forcedstart - A boolean property which \
when set will result in the backend killing any Virtuoso instance accessing the + * \
data in the storage dir before starting its own instance. This option is ignored when \
connecting to an already + * running Virtuoso server.
*
- * The two settings above are user settings and have to be provided using \
Soprano::BackendOptionUser: + * The settings above are user settings and have to be \
provided using Soprano::BackendOptionUser:
*
* \code
* Soprano::BackendSettings settings;
--- trunk/kdesupport/soprano/backends/virtuoso/virtuosocontroller.cpp \
#1088672:1088673 @@ -21,6 +21,7 @@
#include "virtuosocontroller.h"
#include "sopranodirs.h"
+#include "lockfile.h"
#include <QtCore/QTemporaryFile>
#include <QtCore/QProcess>
@@ -33,6 +34,11 @@
#include <QtCore/QMutex>
#include <QtCore/QMutexLocker>
+#ifndef Q_OS_WIN
+#include <sys/types.h>
+#include <signal.h>
+#endif
+
Q_DECLARE_METATYPE( QProcess::ExitStatus )
namespace {
@@ -103,13 +109,25 @@
return false;
}
- // remove old lock files to be sure
- QString lockFilePath
- = valueInSettings( settings, BackendOptionStorageDir ).toString()
- + QLatin1String( "/soprano-virtuoso.lck" );
- if ( QFile::exists( lockFilePath ) )
- QFile::remove( lockFilePath );
+ const QString storageDir = valueInSettings( settings, \
BackendOptionStorageDir ).toString();
+ // check if another instance of Virtuoso is running
+ int pid = pidOfRunningVirtuosoInstance( storageDir );
+ if ( pid > 0 && valueInSettings( settings, "forcedstart", false ).toBool() ) \
{ +#ifndef Q_OS_WIN
+ qDebug( "Shutting down Virtuoso instance (%d) which is in our way.", pid \
); + kill( pid, SIGTERM );
+#endif
+ pid = 0;
+ }
+
+ // remove old lock files in case Virtuoso crashed
+ if ( !pid ) {
+ QString lockFilePath = storageDir + QLatin1String( \
"/soprano-virtuoso.lck" ); + if ( QFile::exists( lockFilePath ) )
+ QFile::remove( lockFilePath );
+ }
+
QStringList args;
args << "+foreground"
<< "+configfile" << QDir::toNativeSeparators(m_configFilePath)
@@ -292,7 +310,7 @@
cfs.setValue( "DisableTcpSocket", "1" );
#endif
- // FIXME: what is this?
+ // TODO: make this configurable to allow the server to read/write from and to a \
set of folders // cfs.setValue( "DirsAllowed", "." );
// FIXME: what is this?
@@ -347,4 +365,19 @@
return QString();
}
+
+// static
+int Soprano::VirtuosoController::pidOfRunningVirtuosoInstance( const QString& \
storagePath ) +{
+ // try to aquire lock as Virtuoso itself does
+ LockFile lock( storagePath + QLatin1String( "/soprano-virtuoso.db" ) );
+ int pid = 0;
+ if ( !lock.aquireLock( &pid ) ) {
+ return pid;
+ }
+ else {
+ return 0;
+ }
+}
+
#include "virtuosocontroller.moc"
--- trunk/kdesupport/soprano/backends/virtuoso/virtuosocontroller.h #1088672:1088673
@@ -70,6 +70,7 @@
ExitStatus lastExitStatus() const { return m_lastExitStatus; }
static QString locateVirtuosoBinary();
+ static int pidOfRunningVirtuosoInstance( const QString& storagePath );
Q_SIGNALS:
void started();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic