| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qlockfile.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | QLockFile::QLockFile(const QString &fileName) | - | ||||||||||||||||||
| 5 | : d_ptr(new QLockFilePrivate(fileName)) | - | ||||||||||||||||||
| 6 | { | - | ||||||||||||||||||
| 7 | } executed 4338 times by 33 tests: end of blockExecuted by:
| 4338 | ||||||||||||||||||
| 8 | - | |||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | - | |||||||||||||||||||
| 11 | - | |||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | QLockFile::~QLockFile() | - | ||||||||||||||||||
| 14 | { | - | ||||||||||||||||||
| 15 | unlock(); | - | ||||||||||||||||||
| 16 | } executed 4338 times by 33 tests: end of blockExecuted by:
| 4338 | ||||||||||||||||||
| 17 | void QLockFile::setStaleLockTime(int staleLockTime) | - | ||||||||||||||||||
| 18 | { | - | ||||||||||||||||||
| 19 | QLockFilePrivate * const d = d_func(); | - | ||||||||||||||||||
| 20 | d->staleLockTime = staleLockTime; | - | ||||||||||||||||||
| 21 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 22 | - | |||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | - | |||||||||||||||||||
| 25 | - | |||||||||||||||||||
| 26 | - | |||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | int QLockFile::staleLockTime() const | - | ||||||||||||||||||
| 30 | { | - | ||||||||||||||||||
| 31 | const QLockFilePrivate * const d = d_func(); | - | ||||||||||||||||||
| 32 | return never executed: d->staleLockTime;return d->staleLockTime;never executed: return d->staleLockTime; | 0 | ||||||||||||||||||
| 33 | } | - | ||||||||||||||||||
| 34 | - | |||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | - | |||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | - | |||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | bool QLockFile::isLocked() const | - | ||||||||||||||||||
| 42 | { | - | ||||||||||||||||||
| 43 | const QLockFilePrivate * const d = d_func(); | - | ||||||||||||||||||
| 44 | return executed 3 times by 2 tests: d->isLocked;return d->isLocked;Executed by:
executed 3 times by 2 tests: return d->isLocked;Executed by:
| 3 | ||||||||||||||||||
| 45 | } | - | ||||||||||||||||||
| 46 | bool QLockFile::lock() | - | ||||||||||||||||||
| 47 | { | - | ||||||||||||||||||
| 48 | return executed 576 times by 8 tests: tryLock(-1);return tryLock(-1);Executed by:
executed 576 times by 8 tests: return tryLock(-1);Executed by:
| 576 | ||||||||||||||||||
| 49 | } | - | ||||||||||||||||||
| 50 | bool QLockFile::tryLock(int timeout) | - | ||||||||||||||||||
| 51 | { | - | ||||||||||||||||||
| 52 | QLockFilePrivate * const d = d_func(); | - | ||||||||||||||||||
| 53 | QElapsedTimer timer; | - | ||||||||||||||||||
| 54 | if (timeout > 0
| 4-582 | ||||||||||||||||||
| 55 | timer.start(); executed 4 times by 1 test: timer.start();Executed by:
| 4 | ||||||||||||||||||
| 56 | int sleepTime = 100; | - | ||||||||||||||||||
| 57 | for(;;) { | - | ||||||||||||||||||
| 58 | d->lockError = d->tryLock_sys(); | - | ||||||||||||||||||
| 59 | switch (d->lockError) { | - | ||||||||||||||||||
| 60 | case executed 580 times by 8 tests: NoError:case NoError:Executed by:
executed 580 times by 8 tests: case NoError:Executed by:
| 580 | ||||||||||||||||||
| 61 | d->isLocked = true; | - | ||||||||||||||||||
| 62 | return executed 580 times by 8 tests: true;return true;Executed by:
executed 580 times by 8 tests: return true;Executed by:
| 580 | ||||||||||||||||||
| 63 | case executed 1 time by 1 test: PermissionError:case PermissionError:Executed by:
executed 1 time by 1 test: case PermissionError:Executed by:
| 1 | ||||||||||||||||||
| 64 | case never executed: UnknownError:case UnknownError:never executed: case UnknownError: | 0 | ||||||||||||||||||
| 65 | return executed 1 time by 1 test: false;return false;Executed by:
executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||
| 66 | case executed 17 times by 1 test: LockFailedError:case LockFailedError:Executed by:
executed 17 times by 1 test: case LockFailedError:Executed by:
| 17 | ||||||||||||||||||
| 67 | if (!d->isLocked
| 1-13 | ||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | QLockFile rmlock(d->fileName + QLatin1String(".rmlock")); | - | ||||||||||||||||||
| 71 | if (rmlock.tryLock()
| 0-1 | ||||||||||||||||||
| 72 | if (d->isApparentlyStale()
| 0-1 | ||||||||||||||||||
| 73 | continue; executed 1 time by 1 test: continue;Executed by:
| 1 | ||||||||||||||||||
| 74 | } never executed: end of block | 0 | ||||||||||||||||||
| 75 | } never executed: end of block | 0 | ||||||||||||||||||
| 76 | break; executed 16 times by 1 test: break;Executed by:
| 16 | ||||||||||||||||||
| 77 | } | - | ||||||||||||||||||
| 78 | if (timeout == 0
| 2-13 | ||||||||||||||||||
| 79 | return executed 5 times by 1 test: false;return false;Executed by:
executed 5 times by 1 test: return false;Executed by:
| 5 | ||||||||||||||||||
| 80 | QThread::msleep(sleepTime); | - | ||||||||||||||||||
| 81 | if (sleepTime < 5 * 1000
| 0-11 | ||||||||||||||||||
| 82 | sleepTime *= 2; executed 11 times by 1 test: sleepTime *= 2;Executed by:
| 11 | ||||||||||||||||||
| 83 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 86 | } | - | ||||||||||||||||||
| 87 | bool QLockFile::getLockInfo(qint64 *pid, QString *hostname, QString *appname) const | - | ||||||||||||||||||
| 88 | { | - | ||||||||||||||||||
| 89 | const QLockFilePrivate * const d = d_func(); | - | ||||||||||||||||||
| 90 | return executed 1 time by 1 test: d->getLockInfo(pid, hostname, appname);return d->getLockInfo(pid, hostname, appname);Executed by:
executed 1 time by 1 test: return d->getLockInfo(pid, hostname, appname);Executed by:
| 1 | ||||||||||||||||||
| 91 | } | - | ||||||||||||||||||
| 92 | - | |||||||||||||||||||
| 93 | bool QLockFilePrivate::getLockInfo(qint64 *pid, QString *hostname, QString *appname) const | - | ||||||||||||||||||
| 94 | { | - | ||||||||||||||||||
| 95 | QFile reader(fileName); | - | ||||||||||||||||||
| 96 | if (!reader.open(QIODevice::ReadOnly)
| 0-15 | ||||||||||||||||||
| 97 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 98 | - | |||||||||||||||||||
| 99 | QByteArray pidLine = reader.readLine(); | - | ||||||||||||||||||
| 100 | pidLine.chop(1); | - | ||||||||||||||||||
| 101 | if (pidLine.isEmpty()
| 2-13 | ||||||||||||||||||
| 102 | return executed 2 times by 1 test: false;return false;Executed by:
executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||
| 103 | QByteArray appNameLine = reader.readLine(); | - | ||||||||||||||||||
| 104 | appNameLine.chop(1); | - | ||||||||||||||||||
| 105 | QByteArray hostNameLine = reader.readLine(); | - | ||||||||||||||||||
| 106 | hostNameLine.chop(1); | - | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | qint64 thePid = pidLine.toLongLong(); | - | ||||||||||||||||||
| 109 | if (pid
| 0-13 | ||||||||||||||||||
| 110 | * executed 13 times by 1 test: pid = thePid;*pid = thePid;Executed by:
executed 13 times by 1 test: *pid = thePid;Executed by:
| 13 | ||||||||||||||||||
| 111 | if (appname
| 0-13 | ||||||||||||||||||
| 112 | * executed 13 times by 1 test: appname = QString::fromUtf8(appNameLine);*appname = QString::fromUtf8(appNameLine);Executed by:
executed 13 times by 1 test: *appname = QString::fromUtf8(appNameLine);Executed by:
| 13 | ||||||||||||||||||
| 113 | if (hostname
| 0-13 | ||||||||||||||||||
| 114 | * executed 13 times by 1 test: hostname = QString::fromUtf8(hostNameLine);*hostname = QString::fromUtf8(hostNameLine);Executed by:
executed 13 times by 1 test: *hostname = QString::fromUtf8(hostNameLine);Executed by:
| 13 | ||||||||||||||||||
| 115 | return executed 13 times by 1 test: thePid > 0;return thePid > 0;Executed by:
executed 13 times by 1 test: return thePid > 0;Executed by:
| 13 | ||||||||||||||||||
| 116 | } | - | ||||||||||||||||||
| 117 | bool QLockFile::removeStaleLockFile() | - | ||||||||||||||||||
| 118 | { | - | ||||||||||||||||||
| 119 | QLockFilePrivate * const d = d_func(); | - | ||||||||||||||||||
| 120 | if (d->isLocked
| 0 | ||||||||||||||||||
| 121 | QMessageLogger(__FILE__, 330, __PRETTY_FUNCTION__).warning("removeStaleLockFile can only be called when not holding the lock"); | - | ||||||||||||||||||
| 122 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 123 | } | - | ||||||||||||||||||
| 124 | return never executed: d->removeStaleLock();return d->removeStaleLock();never executed: return d->removeStaleLock(); | 0 | ||||||||||||||||||
| 125 | } | - | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | - | |||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | QLockFile::LockError QLockFile::error() const | - | ||||||||||||||||||
| 134 | { | - | ||||||||||||||||||
| 135 | const QLockFilePrivate * const d = d_func(); | - | ||||||||||||||||||
| 136 | return executed 14 times by 1 test: d->lockError;return d->lockError;Executed by:
executed 14 times by 1 test: return d->lockError;Executed by:
| 14 | ||||||||||||||||||
| 137 | } | - | ||||||||||||||||||
| 138 | - | |||||||||||||||||||
| 139 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |