summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaszlo Papp <lpapp@kde.org>2013-02-08 07:21:56 +0000
committerLaszlo Papp <lpapp@kde.org>2013-02-08 10:03:28 +0100
commitd79785cb977ad36cb71c88edb572e7082e96675f (patch)
tree295a2a45518dd979dd7442e5a7594554c00c305e /src
parent8b19c95722b32e3367dac69564a27565efd5cc0b (diff)
downloadqtserialport-d79785cb977ad36cb71c88edb572e7082e96675f.tar.gz
Rewrite the lock directory list handling
Change-Id: Id33e834d4b4ff6dc0cdbbd6dfd2fd970958a381a Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/serialport/qttylocker_unix.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/serialport/qttylocker_unix.cpp b/src/serialport/qttylocker_unix.cpp
index 88545d9..b67cd60 100644
--- a/src/serialport/qttylocker_unix.cpp
+++ b/src/serialport/qttylocker_unix.cpp
@@ -62,15 +62,17 @@ QT_BEGIN_NAMESPACE
#if !(defined (HAVE_BAUDBOY_H) || defined (HAVE_LOCKDEV_H))
-static
-const char * const entryLockDirectoryList[] = {
- "/var/lock",
- "/etc/locks",
- "/var/spool/locks",
- "/var/spool/uucp",
- "/tmp",
- 0
-};
+static inline const QStringList& lockDirectoryList()
+{
+ static const QStringList lockDirectoryEntries = QStringList()
+ << "/var/lock"
+ << "/etc/locks"
+ << "/var/spool/locks"
+ << "/var/spool/uucp"
+ << "/tmp";
+
+ return lockDirectoryEntries;
+}
// Returns the full path first found in the directory where you can create a lock file
// (ie a directory with access to the read/write).
@@ -79,9 +81,11 @@ const char * const entryLockDirectoryList[] = {
static
QString lookupFirstSharedLockDir()
{
- for (int i = 0; entryLockDirectoryList[i] != 0; ++i) {
- if (::access(entryLockDirectoryList[i], R_OK | W_OK) == 0)
- return QLatin1String(entryLockDirectoryList[i]);
+ QStringList directoryList = lockDirectoryList();
+
+ foreach (const QString &lockDirectory, directoryList) {
+ if (::access(lockDirectory.toLocal8Bit().constData(), R_OK | W_OK) == 0)
+ return lockDirectory;
}
return QString();
}