diff ui/processhelp_linux.cpp @ 782:20ca94680003

Implemented detection of running instance on linux using a lock file.
author Sascha Wilde <wilde@intevation.de>
date Mon, 14 Jul 2014 12:46:47 +0200
parents cfef809b890d
children 2a1206932f53
line wrap: on
line diff
--- a/ui/processhelp_linux.cpp	Thu Jul 10 19:16:21 2014 +0200
+++ b/ui/processhelp_linux.cpp	Mon Jul 14 12:46:47 2014 +0200
@@ -8,6 +8,19 @@
 #ifndef WIN32
 
 #include "processhelp.h"
+#include "linuxlockfile.h"
+
+#include <fcntl.h>
+#include <semaphore.h>
+
+#include <QDebug>
+#include <QDir>
+#include <QStandardPaths>
+
+namespace ProcessHelp
+{
+    int lockFileFD = -1;
+}
 
 const QList<int> ProcessHelp::getProcessesIdForName(const QString &processName) {
     // TODO
@@ -16,8 +29,17 @@
 }
 
 bool ProcessHelp::otherProcessesExist(const QString &processName) {
-    // TODO
-    Q_UNUSED(processName);
+    // FIXME: We are using lock file semantics on GNU Linux so the
+    // name of this method is rather misleading.
+
+    QDir dataDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
+    dataDir.mkpath(".");
+    QString lockFilePath = dataDir.filePath(processName + ".pid");
+    lockFileFD = open_lockfile(lockFilePath.toLocal8Bit().data());
+    if (lockFileFD == -1)
+        // Creating the lock file failed, so we assume another
+        // instance is runnning.
+        return true;
     return false;
 }
 
@@ -27,4 +49,8 @@
     return;
 }
 
+void ProcessHelp::cleanUp() {
+    close_lockfile(lockFileFD);
+}
+
 #endif /* Not WIN32 */

http://wald.intevation.org/projects/trustbridge/