annotate ui/processhelp_linux.cpp @ 1243:cf5784d2c3a8

(issue54) Safeguard to prohibit starting the application as root
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 24 Sep 2014 19:22:47 +0200
parents 2a1206932f53
children 2a1aa9df8f11
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) {
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
26 // TODO (issue39)
603
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 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
33 dataDir.mkpath(".");
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
34 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
35 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
36 if (lockFileFD == -1)
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
37 // 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
38 // instance is runnning.
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
39 return true;
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
40 return false;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
41 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
42
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 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
44 // TODO (issue136)
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
45 Q_UNUSED(executableName);
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46 return;
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47 }
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48
782
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
49 void ProcessHelp::cleanUp() {
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
50 close_lockfile(lockFileFD);
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
51 }
20ca94680003 Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents: 603
diff changeset
52
603
cfef809b890d Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 #endif /* Not WIN32 */

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