qlockfile_unix.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qlockfile_unix.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>-
4** Copyright (C) 2015 The Qt Company Ltd.-
5** Contact: http://www.qt.io/licensing/-
6**-
7** This file is part of the QtCore module of the Qt Toolkit.-
8**-
9** $QT_BEGIN_LICENSE:LGPL21$-
10** Commercial License Usage-
11** Licensees holding valid commercial Qt licenses may use this file in-
12** accordance with the commercial license agreement provided with the-
13** Software or, alternatively, in accordance with the terms contained in-
14** a written agreement between you and The Qt Company. For licensing terms-
15** and conditions see http://www.qt.io/terms-conditions. For further-
16** information use the contact form at http://www.qt.io/contact-us.-
17**-
18** GNU Lesser General Public License Usage-
19** Alternatively, this file may be used under the terms of the GNU Lesser-
20** General Public License version 2.1 or version 3 as published by the Free-
21** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
22** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
23** following information to ensure the GNU Lesser General Public License-
24** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
25** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
26**-
27** As a special exception, The Qt Company gives you certain additional-
28** rights. These rights are described in The Qt Company LGPL Exception-
29** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
30**-
31** $QT_END_LICENSE$-
32**-
33****************************************************************************/-
34-
35#include "private/qlockfile_p.h"-
36-
37#include "QtCore/qtemporaryfile.h"-
38#include "QtCore/qcoreapplication.h"-
39#include "QtCore/qfileinfo.h"-
40#include "QtCore/qdebug.h"-
41#include "QtCore/qdatetime.h"-
42#include "QtCore/qfileinfo.h"-
43#include "QtCore/qcache.h"-
44#include "QtCore/qglobalstatic.h"-
45#include "QtCore/qmutex.h"-
46-
47#include "private/qcore_unix_p.h" // qt_safe_open-
48#include "private/qabstractfileengine_p.h"-
49#include "private/qtemporaryfile_p.h"-
50-
51#include <sys/file.h> // flock-
52#include <sys/types.h> // kill-
53#include <signal.h> // kill-
54#include <unistd.h> // gethostname-
55-
56#if defined(Q_OS_OSX)-
57# include <libproc.h>-
58#elif defined(Q_OS_LINUX)-
59# include <unistd.h>-
60# include <cstdio>-
61#elif defined(Q_OS_BSD4) && !defined(Q_OS_IOS)-
62# include <sys/cdefs.h>-
63# include <sys/param.h>-
64# include <sys/sysctl.h>-
65# if !defined(Q_OS_NETBSD)-
66# include <sys/user.h>-
67# endif-
68#endif-
69-
70QT_BEGIN_NAMESPACE-
71-
72static QByteArray localHostName() // from QHostInfo::localHostName(), modified to return a QByteArray-
73{-
74 QByteArray hostName(512, Qt::Uninitialized);-
75 if (gethostname(hostName.data(), hostName.size()) == -1)
gethostname(ho....size()) == -1Description
TRUEnever evaluated
FALSEevaluated 608 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
0-608
76 return QByteArray();
never executed: return QByteArray();
0
77 hostName.truncate(strlen(hostName.data()));-
78 return hostName;
executed 608 times by 8 tests: return hostName;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
608
79}-
80-
81// ### merge into qt_safe_write?-
82static qint64 qt_write_loop(int fd, const char *data, qint64 len)-
83{-
84 qint64 pos = 0;-
85 while (pos < len) {
pos < lenDescription
TRUEevaluated 578 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
FALSEevaluated 578 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
578
86 const qint64 ret = qt_safe_write(fd, data + pos, len - pos);-
87 if (ret == -1) // e.g. partition full
ret == -1Description
TRUEnever evaluated
FALSEevaluated 578 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
0-578
88 return pos;
never executed: return pos;
0
89 pos += ret;-
90 }
executed 578 times by 8 tests: end of block
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
578
91 return pos;
executed 578 times by 8 tests: return pos;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
578
92}-
93-
94int QLockFilePrivate::checkFcntlWorksAfterFlock(const QString &fn)-
95{-
96#ifndef QT_NO_TEMPORARYFILE-
97 QTemporaryFile file(fn);-
98 if (!file.open())
!file.open()Description
TRUEnever evaluated
FALSEevaluated 23 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
0-23
99 return 0;
never executed: return 0;
0
100 const int fd = file.d_func()->engine()->handle();-
101#if defined(LOCK_EX) && defined(LOCK_NB)-
102 if (flock(fd, LOCK_EX | LOCK_NB) == -1) // other threads, and other processes on a local fs
flock(fd, 2 | 4) == -1Description
TRUEnever evaluated
FALSEevaluated 23 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
0-23
103 return 0;
never executed: return 0;
0
104#endif-
105 struct flock flockData;-
106 flockData.l_type = F_WRLCK;-
107 flockData.l_whence = SEEK_SET;-
108 flockData.l_start = 0;-
109 flockData.l_len = 0; // 0 = entire file-
110 flockData.l_pid = getpid();-
111 if (fcntl(fd, F_SETLK, &flockData) == -1) // for networked filesystems
fcntl(fd, 6, &flockData) == -1Description
TRUEnever evaluated
FALSEevaluated 23 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
0-23
112 return 0;
never executed: return 0;
0
113 return 1;
executed 23 times by 8 tests: return 1;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
23
114#else-
115 return 0;-
116#endif-
117}-
118-
119// Cache the result of checkFcntlWorksAfterFlock for each directory a lock-
120// file is created in because in some filesystems, like NFS, both locks-
121// are the same. This does not take into account a filesystem changing.-
122// QCache is set to hold a maximum of 10 entries, this is to avoid unbounded-
123// growth, this is caching directories of files and it is assumed a low number-
124// will be sufficient.-
125typedef QCache<QString, bool> CacheType;-
126Q_GLOBAL_STATIC_WITH_ARGS(CacheType, fcntlOK, (10));
executed 7 times by 7 tests: end of block
Executed by:
  • tst_languagechange - unknown status
  • tst_qcolordialog - unknown status
  • tst_qfiledialog - unknown status
  • tst_qfiledialog2 - unknown status
  • tst_qgraphicsproxywidget - unknown status
  • tst_qlockfile - unknown status
  • tst_qsettings - unknown status
executed 7 times by 7 tests: guard.store(QtGlobalStatic::Destroyed);
Executed by:
  • tst_languagechange - unknown status
  • tst_qcolordialog - unknown status
  • tst_qfiledialog - unknown status
  • tst_qfiledialog2 - unknown status
  • tst_qgraphicsproxywidget - unknown status
  • tst_qlockfile - unknown status
  • tst_qsettings - unknown status
executed 600 times by 7 tests: return &holder.value;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
guard.load() =...c::InitializedDescription
TRUEevaluated 7 times by 7 tests
Evaluated by:
  • tst_languagechange - unknown status
  • tst_qcolordialog - unknown status
  • tst_qfiledialog - unknown status
  • tst_qfiledialog2 - unknown status
  • tst_qgraphicsproxywidget - unknown status
  • tst_qlockfile - unknown status
  • tst_qsettings - unknown status
FALSEnever evaluated
0-600
127static QBasicMutex fcntlLock;-
128-
129/*!-
130 \internal-
131 Checks that the OS isn't using POSIX locks to emulate flock().-
132 \macos is one of those.-
133*/-
134static bool fcntlWorksAfterFlock(const QString &fn)-
135{-
136 QMutexLocker lock(&fcntlLock);-
137 if (fcntlOK.isDestroyed())
fcntlOK.isDestroyed()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_qlockfile - unknown status
FALSEevaluated 578 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
1-578
138 return QLockFilePrivate::checkFcntlWorksAfterFlock(fn);
executed 1 time by 1 test: return QLockFilePrivate::checkFcntlWorksAfterFlock(fn);
Executed by:
  • tst_qlockfile - unknown status
1
139 bool *worksPtr = fcntlOK->object(fn);-
140 if (worksPtr)
worksPtrDescription
TRUEevaluated 556 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
FALSEevaluated 22 times by 7 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
22-556
141 return *worksPtr;
executed 556 times by 7 tests: return *worksPtr;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
556
142-
143 const bool val = QLockFilePrivate::checkFcntlWorksAfterFlock(fn);-
144 worksPtr = new bool(val);-
145 fcntlOK->insert(fn, worksPtr);-
146-
147 return val;
executed 22 times by 7 tests: return val;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
22
148}-
149-
150static bool setNativeLocks(const QString &fileName, int fd)-
151{-
152#if defined(LOCK_EX) && defined(LOCK_NB)-
153 if (flock(fd, LOCK_EX | LOCK_NB) == -1) // other threads, and other processes on a local fs
flock(fd, 2 | 4) == -1Description
TRUEnever evaluated
FALSEevaluated 579 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
0-579
154 return false;
never executed: return false;
0
155#endif-
156 struct flock flockData;-
157 flockData.l_type = F_WRLCK;-
158 flockData.l_whence = SEEK_SET;-
159 flockData.l_start = 0;-
160 flockData.l_len = 0; // 0 = entire file-
161 flockData.l_pid = getpid();-
162 if (fcntlWorksAfterFlock(QDir::cleanPath(QFileInfo(fileName).absolutePath()) + QString('/'))
fcntlWorksAfte... QString('/'))Description
TRUEevaluated 579 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
FALSEnever evaluated
0-579
163 && fcntl(fd, F_SETLK, &flockData) == -1) { // for networked filesystems
fcntl(fd, 6, &flockData) == -1Description
TRUEnever evaluated
FALSEevaluated 579 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
0-579
164 return false;
never executed: return false;
0
165 }-
166 return true;
executed 579 times by 8 tests: return true;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
579
167}-
168-
169QLockFile::LockError QLockFilePrivate::tryLock_sys()-
170{-
171 // Assemble data, to write in a single call to write-
172 // (otherwise we'd have to check every write call)-
173 // Use operator% from the fast builder to avoid multiple memory allocations.-
174 QByteArray fileData = QByteArray::number(QCoreApplication::applicationPid()) % '\n'-
175 % QCoreApplication::applicationName().toUtf8() % '\n'-
176 % localHostName() % '\n';-
177-
178 const QByteArray lockFileName = QFile::encodeName(fileName);-
179 const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY | O_CREAT | O_EXCL, 0666);-
180 if (fd < 0) {
fd < 0Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEevaluated 578 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
18-578
181 switch (errno) {-
182 case EEXIST:
executed 17 times by 1 test: case 17:
Executed by:
  • tst_QLockFile
17
183 return QLockFile::LockFailedError;
executed 17 times by 1 test: return QLockFile::LockFailedError;
Executed by:
  • tst_QLockFile
17
184 case EACCES:
executed 1 time by 1 test: case 13:
Executed by:
  • tst_QLockFile
1
185 case EROFS:
never executed: case 30:
0
186 return QLockFile::PermissionError;
executed 1 time by 1 test: return QLockFile::PermissionError;
Executed by:
  • tst_QLockFile
1
187 default:
never executed: default:
0
188 return QLockFile::UnknownError;
never executed: return QLockFile::UnknownError;
0
189 }-
190 }-
191 // Ensure nobody else can delete the file while we have it-
192 if (!setNativeLocks(fileName, fd)) {
!setNativeLocks(fileName, fd)Description
TRUEnever evaluated
FALSEevaluated 578 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
0-578
193 const int errnoSaved = errno;-
194 qWarning() << "setNativeLocks failed:" << qt_error_string(errnoSaved);-
195 }
never executed: end of block
0
196-
197 if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size()) {
qt_write_loop(...ileData.size()Description
TRUEnever evaluated
FALSEevaluated 578 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
0-578
198 close(fd);-
199 if (!QFile::remove(fileName))
!QFile::remove(fileName)Description
TRUEnever evaluated
FALSEnever evaluated
0
200 qWarning("QLockFile: Could not remove our own lock file %s.", qPrintable(fileName));
never executed: QMessageLogger(__FILE__, 200, __PRETTY_FUNCTION__).warning("QLockFile: Could not remove our own lock file %s.", QString(fileName).toLocal8Bit().constData());
0
201 return QLockFile::UnknownError; // partition full
never executed: return QLockFile::UnknownError;
0
202 }-
203-
204 // We hold the lock, continue.-
205 fileHandle = fd;-
206-
207 // Sync to disk if possible. Ignore errors (e.g. not supported).-
208#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0-
209 fdatasync(fileHandle);-
210#else-
211 fsync(fileHandle);-
212#endif-
213-
214 return QLockFile::NoError;
executed 578 times by 8 tests: return QLockFile::NoError;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
578
215}-
216-
217bool QLockFilePrivate::removeStaleLock()-
218{-
219 const QByteArray lockFileName = QFile::encodeName(fileName);-
220 const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY, 0666);-
221 if (fd < 0) // gone already?
fd < 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QLockFile
0-1
222 return false;
never executed: return false;
0
223 bool success = setNativeLocks(fileName, fd) && (::unlink(lockFileName) == 0);
setNativeLocks(fileName, fd)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QLockFile
FALSEnever evaluated
(::unlink(lockFileName) == 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QLockFile
FALSEnever evaluated
0-1
224 close(fd);-
225 return success;
executed 1 time by 1 test: return success;
Executed by:
  • tst_QLockFile
1
226}-
227-
228bool QLockFilePrivate::isApparentlyStale() const-
229{-
230 qint64 pid;-
231 QString hostname, appname;-
232 if (getLockInfo(&pid, &hostname, &appname)) {
getLockInfo(&p...ame, &appname)Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QLockFile
2-12
233 if (hostname.isEmpty() || hostname == QString::fromLocal8Bit(localHostName())) {
hostname.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QLockFile
hostname == QS...calHostName())Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEnever evaluated
0-12
234 if (::kill(pid, 0) == -1 && errno == ESRCH)
::kill(pid, 0) == -1Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QLockFile
(*__errno_location ()) == 3Description
TRUEnever evaluated
FALSEnever evaluated
0-12
235 return true; // PID doesn't exist anymore
never executed: return true;
0
236 const QString processName = processNameByPid(pid);-
237 if (!processName.isEmpty()) {
!processName.isEmpty()Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEnever evaluated
0-12
238 QFileInfo fi(appname);-
239 if (fi.isSymLink())
fi.isSymLink()Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QLockFile
0-12
240 fi.setFile(fi.symLinkTarget());
never executed: fi.setFile(fi.symLinkTarget());
0
241 if (processName != fi.fileName())
processName != fi.fileName()Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QLockFile
0-12
242 return true; // PID got reused by a different application.
never executed: return true;
0
243 }
executed 12 times by 1 test: end of block
Executed by:
  • tst_QLockFile
12
244 }
executed 12 times by 1 test: end of block
Executed by:
  • tst_QLockFile
12
245 }
executed 12 times by 1 test: end of block
Executed by:
  • tst_QLockFile
12
246 const qint64 age = QFileInfo(fileName).lastModified().msecsTo(QDateTime::currentDateTime());-
247 return staleLockTime > 0 && age > staleLockTime;
executed 14 times by 1 test: return staleLockTime > 0 && age > staleLockTime;
Executed by:
  • tst_QLockFile
staleLockTime > 0Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEnever evaluated
age > staleLockTimeDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QLockFile
0-14
248}-
249-
250QString QLockFilePrivate::processNameByPid(qint64 pid)-
251{-
252#if defined(Q_OS_OSX)-
253 char name[1024];-
254 proc_name(pid, name, sizeof(name) / sizeof(char));-
255 return QFile::decodeName(name);-
256#elif defined(Q_OS_LINUX)-
257 if (!QFile::exists(QStringLiteral("/proc/version")))
executed 12 times by 1 test: return qstring_literal_temp;
Executed by:
  • tst_QLockFile
!QFile::exists...al_temp; }()))Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QLockFile
0-12
258 return QString();
never executed: return QString();
0
259 char exePath[64];-
260 char buf[PATH_MAX + 1];-
261 sprintf(exePath, "/proc/%lld/exe", pid);-
262 size_t len = (size_t)readlink(exePath, buf, sizeof(buf));-
263 if (len >= sizeof(buf)) {
len >= sizeof(buf)Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QLockFile
0-12
264 // The pid is gone. Return some invalid process name to fail the test.-
265 return QStringLiteral("/ERROR/");
never executed: return ([]() -> QString { enum { Size = sizeof(u"" "/ERROR/")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "/ERROR/" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());
never executed: return qstring_literal_temp;
0
266 }-
267 buf[len] = 0;-
268 return QFileInfo(QFile::decodeName(buf)).fileName();
executed 12 times by 1 test: return QFileInfo(QFile::decodeName(buf)).fileName();
Executed by:
  • tst_QLockFile
12
269#elif defined(Q_OS_BSD4) && !defined(Q_OS_IOS)-
270# if defined(Q_OS_NETBSD)-
271 struct kinfo_proc2 kp;-
272 int mib[6] = { CTL_KERN, KERN_PROC2, KERN_PROC_PID, (int)pid, sizeof(struct kinfo_proc2), 1 };-
273# elif defined(Q_OS_OPENBSD)-
274 struct kinfo_proc kp;-
275 int mib[6] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)pid, sizeof(struct kinfo_proc), 1 };-
276# else-
277 struct kinfo_proc kp;-
278 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)pid };-
279# endif-
280 size_t len = sizeof(kp);-
281 u_int mib_len = sizeof(mib)/sizeof(u_int);-
282-
283 if (sysctl(mib, mib_len, &kp, &len, NULL, 0) < 0)-
284 return QString();-
285-
286# if defined(Q_OS_OPENBSD) || defined(Q_OS_NETBSD)-
287 if (kp.p_pid != pid)-
288 return QString();-
289 QString name = QFile::decodeName(kp.p_comm);-
290# else-
291 if (kp.ki_pid != pid)-
292 return QString();-
293 QString name = QFile::decodeName(kp.ki_comm);-
294# endif-
295 return name;-
296-
297#else-
298 Q_UNUSED(pid);-
299 return QString();-
300#endif-
301}-
302-
303void QLockFile::unlock()-
304{-
305 Q_D(QLockFile);-
306 if (!d->isLocked)
!d->isLockedDescription
TRUEevaluated 3626 times by 31 tests
Evaluated by:
  • tst_QAbstractItemView
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDateTimeEdit
  • tst_QErrorMessage
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QIcon
  • tst_QLabel
  • tst_QLineEdit
  • tst_QLockFile
  • tst_QMessageBox
  • tst_QPlainTextEdit
  • tst_QPrinter
  • tst_QSettings
  • tst_QSidebar
  • tst_QStyle
  • tst_QStyleSheetStyle
  • tst_QSystemTrayIcon
  • ...
FALSEevaluated 578 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
578-3626
307 return;
executed 3626 times by 31 tests: return;
Executed by:
  • tst_QAbstractItemView
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDateTimeEdit
  • tst_QErrorMessage
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QIcon
  • tst_QLabel
  • tst_QLineEdit
  • tst_QLockFile
  • tst_QMessageBox
  • tst_QPlainTextEdit
  • tst_QPrinter
  • tst_QSettings
  • tst_QSidebar
  • tst_QStyle
  • tst_QStyleSheetStyle
  • tst_QSystemTrayIcon
  • ...
3626
308 close(d->fileHandle);-
309 d->fileHandle = -1;-
310 if (!QFile::remove(d->fileName)) {
!QFile::remove(d->fileName)Description
TRUEnever evaluated
FALSEevaluated 578 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
0-578
311 qWarning() << "Could not remove our own lock file" << d->fileName << "maybe permissions changed meanwhile?";-
312 // This is bad because other users of this lock file will now have to wait for the stale-lock-timeout...-
313 }
never executed: end of block
0
314 d->lockError = QLockFile::NoError;-
315 d->isLocked = false;-
316}
executed 578 times by 8 tests: end of block
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
578
317-
318QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9