summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Keller <rainer.keller@digia.com>2014-10-23 09:15:07 +0200
committerRainer Keller <rainer.keller@digia.com>2014-10-23 10:35:19 +0200
commit7a6da7878566dc18acb540bd29f7e11fa7e3ff66 (patch)
treeba4ab41f33774a22526de296375be6c11770eadc
parent3bb682ea29ffaf72ff73e6eb57abdc5c59524e8a (diff)
Check for lock file in non-writable directoriesv5.4.0-rc1
On some linux systems /var/lock is not writable by users which are not root and not in the uucp or dialout group. If the root user acquires a lock and you are trying to access the same port with a non-root user it will not check for the lock but creates a new lock file in /tmp instead. This change checks in readable directories for lock files. Change-Id: Ia308fd344d2fe9d3c699f7a428ff620ea101eff3 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r--src/serialport/qserialport_unix.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 99792561..eb71e86b 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -72,13 +72,21 @@ QString serialPortLockFilePath(const QString &portName)
#endif
;
+ QString fileName = portName;
+ fileName.replace(QLatin1Char('/'), QLatin1Char('_'));
+ fileName.prepend(QStringLiteral("/LCK.."));
+
QString lockFilePath;
foreach (const QString &lockDirectoryPath, lockDirectoryPaths) {
+ const QString filePath = lockDirectoryPath + fileName;
+
QFileInfo lockDirectoryInfo(lockDirectoryPath);
- if (lockDirectoryInfo.isReadable() && lockDirectoryInfo.isWritable()) {
- lockFilePath = lockDirectoryPath;
- break;
+ if (lockDirectoryInfo.isReadable()) {
+ if (QFile::exists(filePath) || lockDirectoryInfo.isWritable()) {
+ lockFilePath = filePath;
+ break;
+ }
}
}
@@ -89,11 +97,6 @@ QString serialPortLockFilePath(const QString &portName)
return QString();
}
- QString replacedPortName = portName;
-
- lockFilePath.append(QStringLiteral("/LCK.."));
- lockFilePath.append(replacedPortName.replace(QLatin1Char('/'), QLatin1Char('_')));
-
return lockFilePath;
}