andre@603: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik andre@603: * Software engineering by Intevation GmbH andre@603: * andre@603: * This file is Free Software under the GNU GPL (v>=2) andre@603: * and comes with ABSOLUTELY NO WARRANTY! andre@603: * See LICENSE.txt for details. andre@603: */ andre@603: #ifndef WIN32 andre@603: andre@603: #include "processhelp.h" wilde@782: #include "linuxlockfile.h" andre@1371: #include "util.h" wilde@782: wilde@782: #include wilde@782: #include wilde@782: wilde@782: #include wilde@782: #include wilde@782: #include andre@1371: #include wilde@782: andre@1255: int lockFileFD = -1; andre@603: andre@603: const QList ProcessHelp::getProcessesIdForName(const QString &processName) { andre@1162: // TODO (issue39) andre@603: Q_UNUSED(processName); andre@603: return QList(); andre@603: } andre@603: andre@603: bool ProcessHelp::otherProcessesExist(const QString &processName) { wilde@782: QDir dataDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); wilde@782: dataDir.mkpath("."); wilde@782: QString lockFilePath = dataDir.filePath(processName + ".pid"); wilde@782: lockFileFD = open_lockfile(lockFilePath.toLocal8Bit().data()); wilde@782: if (lockFileFD == -1) wilde@782: // Creating the lock file failed, so we assume another wilde@782: // instance is runnning. wilde@782: return true; andre@603: return false; andre@603: } andre@603: andre@603: void ProcessHelp::activateWindowForProcess(const QString &executableName) { andre@1162: // TODO (issue136) andre@603: Q_UNUSED(executableName); andre@603: return; andre@603: } andre@603: wilde@782: void ProcessHelp::cleanUp() { wilde@782: close_lockfile(lockFileFD); wilde@782: } wilde@782: andre@1371: QDateTime ProcessHelp::getSigDtFromInstSettings() { andre@1371: QString pathCandidate; andre@1371: QDateTime retval; andre@1371: if (is_system_install()) { andre@1371: pathCandidate = "/etc/" + qApp->applicationName() + "/" + andre@1371: qApp->applicationName() + "-inst.cfg"; andre@1371: } else { andre@1371: qDebug() << "Application name is : " << qApp->applicationName(); andre@1371: pathCandidate = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + andre@1371: + "/" + qApp->organizationName() + "/" + qApp->applicationName() + "-inst.cfg"; andre@1371: } andre@1371: QFileInfo fi(pathCandidate); andre@1371: if (!fi.isReadable()) { andre@1371: qDebug() << "Failed to find install config: " << pathCandidate; andre@1371: return retval; andre@1371: } andre@1371: QFile instcfg(pathCandidate); andre@1371: if (!instcfg.open(QIODevice::ReadOnly)) { andre@1371: qDebug() << "Failed to open install config"; andre@1371: return retval; andre@1371: } andre@1371: QByteArray data; andre@1371: int readLines = 0; andre@1371: while (readLines < 100) { andre@1371: readLines++; andre@1371: data = instcfg.readLine(); andre@1371: if (data.isEmpty()) { andre@1371: qDebug() << "Failed to read install config"; andre@1371: break; andre@1371: } andre@1371: QString line = QString::fromLocal8Bit(data); andre@1371: if (line.startsWith("SIG_DATE=")) { andre@1371: bool ok = false; andre@1371: QString sigDate = line.replace("SIG_DATE=",""); andre@1371: long sigSecs = sigDate.toLong(&ok); andre@1371: if (!ok) { andre@1371: qDebug() << "Failed to convert sig date to long"; andre@1371: } andre@1371: retval = QDateTime::fromTime_t(sigSecs); andre@1371: break; andre@1371: } andre@1371: } andre@1371: instcfg.close(); andre@1371: return retval; andre@1371: } andre@603: #endif /* Not WIN32 */