view ui/processhelp_linux.cpp @ 1384:318e8c5c4f85

Do not depend on RELEASE_BUILD for debug output this is handled by g_debug and no longer neccessary als a Macro
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 15 Jan 2015 15:57:26 +0100
parents 96f640c88d10
children
line wrap: on
line source
/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU GPL (v>=2)
 * and comes with ABSOLUTELY NO WARRANTY!
 * See LICENSE.txt for details.
 */
#ifndef WIN32

#include "processhelp.h"
#include "linuxlockfile.h"
#include "util.h"

#include <fcntl.h>
#include <semaphore.h>

#include <QDebug>
#include <QDir>
#include <QStandardPaths>
#include <QApplication>

int lockFileFD = -1;

const QList<int> ProcessHelp::getProcessesIdForName(const QString &processName) {
    // TODO (issue39)
    Q_UNUSED(processName);
    return QList<int>();
}

bool ProcessHelp::otherProcessesExist(const QString &processName) {
    QDir dataDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
    dataDir.mkpath(".");
    QString lockFilePath = dataDir.filePath(processName + ".pid");
    lockFileFD = open_lockfile(lockFilePath.toLocal8Bit().data());
    if (lockFileFD == -1)
        // Creating the lock file failed, so we assume another
        // instance is runnning.
        return true;
    return false;
}

void ProcessHelp::activateWindowForProcess(const QString &executableName) {
    // TODO (issue136)
    Q_UNUSED(executableName);
    return;
}

void ProcessHelp::cleanUp() {
    close_lockfile(lockFileFD);
}

QDateTime ProcessHelp::getSigDtFromInstSettings() {
    QString pathCandidate;
    QDateTime retval;
    if (is_system_install()) {
        pathCandidate = "/etc/" + qApp->applicationName() + "/" +
          qApp->applicationName() + "-inst.cfg";
    } else {
        qDebug() << "Application name is : " << qApp->applicationName();
        pathCandidate = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) +
          + "/" + qApp->organizationName() + "/" +  qApp->applicationName() + "-inst.cfg";
    }
    QFileInfo fi(pathCandidate);
    if (!fi.isReadable()) {
        qDebug() << "Failed to find install config: " << pathCandidate;
        return retval;
    }
    QFile instcfg(pathCandidate);
    if (!instcfg.open(QIODevice::ReadOnly)) {
        qDebug() << "Failed to open install config";
        return retval;
    }
    QByteArray data;
    int readLines = 0;
    while (readLines < 100) {
        readLines++;
        data = instcfg.readLine();
        if (data.isEmpty()) {
            qDebug() << "Failed to read install config";
            break;
        }
        QString line = QString::fromLocal8Bit(data);
        if (line.startsWith("SIG_DATE=")) {
            bool ok = false;
            QString sigDate = line.replace("SIG_DATE=","");
            long sigSecs = sigDate.toLong(&ok);
            if (!ok) {
                qDebug() << "Failed to convert sig date to long";
            }
            retval = QDateTime::fromTime_t(sigSecs);
            break;
        }
    }
    instcfg.close();
    return retval;
}
#endif /* Not WIN32 */

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