From 5e58391b5360fabc991488103168bdff0dac48dc Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Wed, 4 Sep 2024 14:30:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BD=E4=BA=A7=E7=B3=BB=E7=BB=9F=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=8C=89=E9=94=AE=E6=89=AB=E6=8F=8F=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=94=81=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scantool/main.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/scantool/main.cpp b/app/scantool/main.cpp index f5020744..48ac2200 100644 --- a/app/scantool/main.cpp +++ b/app/scantool/main.cpp @@ -53,19 +53,29 @@ int main(int argc, char *argv[]) } #else const char* lockFilePath = "/tmp/HGScanTool.lock"; - int fd = open(lockFilePath, O_RDONLY | O_CREAT, 666); - chmod(lockFilePath, 666); + int fd = open(lockFilePath, O_WRONLY | O_CREAT, S_IWUSR | S_IWGRP | S_IWOTH); + if (fd == -1) + printf("open failed."); + if (-1 == chmod(lockFilePath, S_IWUSR | S_IWGRP | S_IWOTH)) + { + printf("chmod file: %s failed.\n", lockFilePath); + } struct flock lock; - lock.l_type = F_RDLCK; + 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) { + printf("lock file %s failed.\n", lockFilePath); close(fd); return 0; } + else + { + printf("open file %s successfully.\n", lockFilePath); + } #endif QTranslator translator_qt;