解决国产系统按键扫描工具进程能同时打开多个的问题;
This commit is contained in:
parent
5de0658d61
commit
03d2887082
|
@ -2,6 +2,14 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include "base/HGDef.h"
|
#include "base/HGDef.h"
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
#if !defined (HG_CMP_MSC)
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "log/log.h"
|
#include "log/log.h"
|
||||||
HLOG g_hLog = nullptr;
|
HLOG g_hLog = nullptr;
|
||||||
|
|
||||||
|
@ -37,6 +45,25 @@ int main(int argc, char *argv[])
|
||||||
CloseHandle(hMutex);
|
CloseHandle(hMutex);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
const QString lockFilePath = "/tmp/HGScanTool.lock";
|
||||||
|
QFile lockFile(lockFilePath);
|
||||||
|
|
||||||
|
if (!lockFile.open(QIODevice::ReadWrite | QIODevice::Unbuffered))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int fd = lockFile.handle();
|
||||||
|
struct flock lock;
|
||||||
|
lock.l_type = F_WRLCK;
|
||||||
|
lock.l_whence = SEEK_SET;
|
||||||
|
lock.l_start = 0;
|
||||||
|
lock.l_len = 0;
|
||||||
|
if (fcntl(fd, F_SETLK, &lock) == -1)
|
||||||
|
{
|
||||||
|
lockFile.close();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QTranslator translator_qt;
|
QTranslator translator_qt;
|
||||||
|
@ -55,6 +82,10 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
#ifdef HG_CMP_MSC
|
#ifdef HG_CMP_MSC
|
||||||
CloseHandle(hMutex);
|
CloseHandle(hMutex);
|
||||||
|
#else
|
||||||
|
lock.l_type = F_UNLCK;
|
||||||
|
fcntl(fd, F_SETLK, &lock);
|
||||||
|
lockFile.close();
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue