From 03d28870826d2e49e92274f229a5fad9d3604096 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Fri, 23 Aug 2024 15:28:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=9B=BD=E4=BA=A7=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=8C=89=E9=94=AE=E6=89=AB=E6=8F=8F=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B=E8=83=BD=E5=90=8C=E6=97=B6=E6=89=93=E5=BC=80?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scantool/main.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/scantool/main.cpp b/app/scantool/main.cpp index 211af869..6b6449be 100644 --- a/app/scantool/main.cpp +++ b/app/scantool/main.cpp @@ -2,6 +2,14 @@ #include #include "base/HGDef.h" #include +#include + +#if !defined (HG_CMP_MSC) +#include +#include +#include +#endif + #include "log/log.h" HLOG g_hLog = nullptr; @@ -37,6 +45,25 @@ int main(int argc, char *argv[]) CloseHandle(hMutex); 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 QTranslator translator_qt; @@ -55,6 +82,10 @@ int main(int argc, char *argv[]) #ifdef HG_CMP_MSC CloseHandle(hMutex); +#else + lock.l_type = F_UNLCK; + fcntl(fd, F_SETLK, &lock); + lockFile.close(); #endif return ret; }