国产系统调整按键扫描工具文件锁权限

This commit is contained in:
yangjiaxuan 2024-09-04 14:30:27 +08:00
parent 9295432771
commit 5e58391b53
1 changed files with 13 additions and 3 deletions

View File

@ -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;