annotate ui/processhelp_linux.cpp @ 868:ae571e7ecdc9

Make appendTextSignature public for better testability
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 05 Aug 2014 17:44:31 +0200
parents 20ca94680003
children 2a1206932f53
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
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
20 namespace ProcessHelp
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
21 {
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
22 int lockFileFD = -1;
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
23 }
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 const QList<int> ProcessHelp::getProcessesIdForName(const QString &processName) {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26 // TODO
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 Q_UNUSED(processName);
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 return QList<int>();
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31 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
32 // FIXME: We are using lock file semantics on GNU Linux so the
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
33 // name of this method is rather misleading.
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
34
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
35 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
36 dataDir.mkpath(".");
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
37 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
38 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
39 if (lockFileFD == -1)
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
40 // 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
41 // instance is runnning.
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
42 return true;
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 return false;
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
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46 void ProcessHelp::activateWindowForProcess(const QString &executableName) {
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47 // TODO
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48 Q_UNUSED(executableName);
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
49 return;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
50 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
51
782
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
52 void ProcessHelp::cleanUp() {
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
53 close_lockfile(lockFileFD);
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
54 }
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
55
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
56 #endif /* Not WIN32 */

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