Mercurial > trustbridge
annotate ui/processhelp_linux.cpp @ 1307:2bacaec6e101
(perf) Use cached values to deterimine elevation.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 13 Oct 2014 12:32:13 +0200 |
parents | 2a1aa9df8f11 |
children | 23df332b2a4c |
rev | line source |
---|---|
603
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 * |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=2) |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 * See LICENSE.txt for details. |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 */ |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 #ifndef WIN32 |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 #include "processhelp.h" |
782
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
11 #include "linuxlockfile.h" |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
12 |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
13 #include <fcntl.h> |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
14 #include <semaphore.h> |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
15 |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
16 #include <QDebug> |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
17 #include <QDir> |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
18 #include <QStandardPaths> |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
19 |
1255
2a1aa9df8f11
(issue133) Improve API documentation
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1162
diff
changeset
|
20 int lockFileFD = -1; |
603
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 const QList<int> ProcessHelp::getProcessesIdForName(const QString &processName) { |
1162
2a1206932f53
(issue107) Comment all TODO's and FIXME's with issues as documented in issue107
Andre Heinecke <andre.heinecke@intevation.de>
parents:
782
diff
changeset
|
23 // TODO (issue39) |
603
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 Q_UNUSED(processName); |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 return QList<int>(); |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 } |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 bool ProcessHelp::otherProcessesExist(const QString &processName) { |
782
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
29 QDir dataDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
30 dataDir.mkpath("."); |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
31 QString lockFilePath = dataDir.filePath(processName + ".pid"); |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
32 lockFileFD = open_lockfile(lockFilePath.toLocal8Bit().data()); |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
33 if (lockFileFD == -1) |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
34 // Creating the lock file failed, so we assume another |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
35 // instance is runnning. |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
36 return true; |
603
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 return false; |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
38 } |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 void ProcessHelp::activateWindowForProcess(const QString &executableName) { |
1162
2a1206932f53
(issue107) Comment all TODO's and FIXME's with issues as documented in issue107
Andre Heinecke <andre.heinecke@intevation.de>
parents:
782
diff
changeset
|
41 // TODO (issue136) |
603
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 Q_UNUSED(executableName); |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
43 return; |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 } |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 |
782
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
46 void ProcessHelp::cleanUp() { |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
47 close_lockfile(lockFileFD); |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
48 } |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
49 |
603
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
50 #endif /* Not WIN32 */ |