comparison 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
comparison
equal deleted inserted replaced
773:2c69298b4188 782:20ca94680003
6 * See LICENSE.txt for details. 6 * See LICENSE.txt for details.
7 */ 7 */
8 #ifndef WIN32 8 #ifndef WIN32
9 9
10 #include "processhelp.h" 10 #include "processhelp.h"
11 #include "linuxlockfile.h"
12
13 #include <fcntl.h>
14 #include <semaphore.h>
15
16 #include <QDebug>
17 #include <QDir>
18 #include <QStandardPaths>
19
20 namespace ProcessHelp
21 {
22 int lockFileFD = -1;
23 }
11 24
12 const QList<int> ProcessHelp::getProcessesIdForName(const QString &processName) { 25 const QList<int> ProcessHelp::getProcessesIdForName(const QString &processName) {
13 // TODO 26 // TODO
14 Q_UNUSED(processName); 27 Q_UNUSED(processName);
15 return QList<int>(); 28 return QList<int>();
16 } 29 }
17 30
18 bool ProcessHelp::otherProcessesExist(const QString &processName) { 31 bool ProcessHelp::otherProcessesExist(const QString &processName) {
19 // TODO 32 // FIXME: We are using lock file semantics on GNU Linux so the
20 Q_UNUSED(processName); 33 // name of this method is rather misleading.
34
35 QDir dataDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
36 dataDir.mkpath(".");
37 QString lockFilePath = dataDir.filePath(processName + ".pid");
38 lockFileFD = open_lockfile(lockFilePath.toLocal8Bit().data());
39 if (lockFileFD == -1)
40 // Creating the lock file failed, so we assume another
41 // instance is runnning.
42 return true;
21 return false; 43 return false;
22 } 44 }
23 45
24 void ProcessHelp::activateWindowForProcess(const QString &executableName) { 46 void ProcessHelp::activateWindowForProcess(const QString &executableName) {
25 // TODO 47 // TODO
26 Q_UNUSED(executableName); 48 Q_UNUSED(executableName);
27 return; 49 return;
28 } 50 }
29 51
52 void ProcessHelp::cleanUp() {
53 close_lockfile(lockFileFD);
54 }
55
30 #endif /* Not WIN32 */ 56 #endif /* Not WIN32 */

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