Mercurial > trustbridge
annotate ui/processhelp_linux.cpp @ 1373:00fcb9c4d16b
(issue179) Handle SW verify failures and try to redownload the update
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 24 Nov 2014 16:46:08 +0100 |
parents | 96f640c88d10 |
children |
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" |
1371
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
12 #include "util.h" |
782
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
13 |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
14 #include <fcntl.h> |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
15 #include <semaphore.h> |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
16 |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
17 #include <QDebug> |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
18 #include <QDir> |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
19 #include <QStandardPaths> |
1371
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
20 #include <QApplication> |
782
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
21 |
1255
2a1aa9df8f11
(issue133) Improve API documentation
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1162
diff
changeset
|
22 int lockFileFD = -1; |
603
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 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
|
25 // TODO (issue39) |
603
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 Q_UNUSED(processName); |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 return QList<int>(); |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 } |
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 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
|
31 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
|
32 dataDir.mkpath("."); |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
33 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
|
34 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
|
35 if (lockFileFD == -1) |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
36 // 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
|
37 // instance is runnning. |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
38 return true; |
603
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 return false; |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 } |
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 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
|
43 // TODO (issue136) |
603
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 Q_UNUSED(executableName); |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 return; |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 } |
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
47 |
782
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
48 void ProcessHelp::cleanUp() { |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
49 close_lockfile(lockFileFD); |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
50 } |
20ca94680003
Implemented detection of running instance on linux using a lock file.
Sascha Wilde <wilde@intevation.de>
parents:
603
diff
changeset
|
51 |
1371
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
52 QDateTime ProcessHelp::getSigDtFromInstSettings() { |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
53 QString pathCandidate; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
54 QDateTime retval; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
55 if (is_system_install()) { |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
56 pathCandidate = "/etc/" + qApp->applicationName() + "/" + |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
57 qApp->applicationName() + "-inst.cfg"; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
58 } else { |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
59 qDebug() << "Application name is : " << qApp->applicationName(); |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
60 pathCandidate = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
61 + "/" + qApp->organizationName() + "/" + qApp->applicationName() + "-inst.cfg"; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
62 } |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
63 QFileInfo fi(pathCandidate); |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
64 if (!fi.isReadable()) { |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
65 qDebug() << "Failed to find install config: " << pathCandidate; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
66 return retval; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
67 } |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
68 QFile instcfg(pathCandidate); |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
69 if (!instcfg.open(QIODevice::ReadOnly)) { |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
70 qDebug() << "Failed to open install config"; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
71 return retval; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
72 } |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
73 QByteArray data; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
74 int readLines = 0; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
75 while (readLines < 100) { |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
76 readLines++; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
77 data = instcfg.readLine(); |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
78 if (data.isEmpty()) { |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
79 qDebug() << "Failed to read install config"; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
80 break; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
81 } |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
82 QString line = QString::fromLocal8Bit(data); |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
83 if (line.startsWith("SIG_DATE=")) { |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
84 bool ok = false; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
85 QString sigDate = line.replace("SIG_DATE=",""); |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
86 long sigSecs = sigDate.toLong(&ok); |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
87 if (!ok) { |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
88 qDebug() << "Failed to convert sig date to long"; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
89 } |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
90 retval = QDateTime::fromTime_t(sigSecs); |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
91 break; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
92 } |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
93 } |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
94 instcfg.close(); |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
95 return retval; |
23df332b2a4c
(issue179) Read install signature timestamp from config
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1255
diff
changeset
|
96 } |
603
cfef809b890d
Add Process Management functions and ther implementation for windows.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
97 #endif /* Not WIN32 */ |