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"
wilde@782: 
wilde@782: #include <fcntl.h>
wilde@782: #include <semaphore.h>
wilde@782: 
wilde@782: #include <QDebug>
wilde@782: #include <QDir>
wilde@782: #include <QStandardPaths>
wilde@782: 
wilde@782: namespace ProcessHelp
wilde@782: {
wilde@782:     int lockFileFD = -1;
wilde@782: }
andre@603: 
andre@603: const QList<int> ProcessHelp::getProcessesIdForName(const QString &processName) {
andre@603:     // TODO
andre@603:     Q_UNUSED(processName);
andre@603:     return QList<int>();
andre@603: }
andre@603: 
andre@603: bool ProcessHelp::otherProcessesExist(const QString &processName) {
wilde@782:     // FIXME: We are using lock file semantics on GNU Linux so the
wilde@782:     // name of this method is rather misleading.
wilde@782: 
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@603:     // TODO
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@603: #endif /* Not WIN32 */