mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdecore: block only when another process is holding the lock in KLockFile::lock()
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
2e9adc69c4
commit
0812a98d19
2 changed files with 6 additions and 5 deletions
|
@ -594,8 +594,10 @@ bool KConfigIniBackend::lock(const KComponentData& componentData)
|
|||
m_lockfile = new KLockFile(filePath());
|
||||
}
|
||||
|
||||
if (m_lockfile->lock() == KLockFile::LockStale) // attempt to break the lock
|
||||
if (m_lockfile->lock() == KLockFile::LockStale) {
|
||||
// attempt to break the lock
|
||||
m_lockfile->lock(KLockFile::ForceFlag);
|
||||
}
|
||||
return m_lockfile->isLocked();
|
||||
}
|
||||
|
||||
|
|
|
@ -68,12 +68,12 @@ KLockFile::LockResult KLockFilePrivate::tryLock()
|
|||
QFile infofile(QFile::decodeName(m_lockfile));
|
||||
if (Q_UNLIKELY(!infofile.open(QFile::ReadOnly))) {
|
||||
kWarning() << infofile.errorString();
|
||||
return KLockFile::LockError;
|
||||
return KLockFile::LockFail;
|
||||
}
|
||||
const QList<QByteArray> lockinfo = infofile.readAll().split('\t');
|
||||
if (Q_UNLIKELY(lockinfo.size() != 2)) {
|
||||
kWarning() << "Invalid lock information";
|
||||
return KLockFile::LockError;
|
||||
return KLockFile::LockFail;
|
||||
}
|
||||
const qint64 lockpid = lockinfo.at(0).toLongLong();
|
||||
const QByteArray lockhost = lockinfo.at(1);
|
||||
|
@ -104,7 +104,6 @@ KLockFile::LockResult KLockFilePrivate::tryLock()
|
|||
}
|
||||
|
||||
|
||||
|
||||
KLockFile::KLockFile(const QString &file)
|
||||
: d(new KLockFilePrivate())
|
||||
{
|
||||
|
@ -129,7 +128,7 @@ tryagain:
|
|||
}
|
||||
result = d->tryLock();
|
||||
}
|
||||
if (!(options & KLockFile::NoBlockFlag) && result != KLockFile::LockOK) {
|
||||
if (!(options & KLockFile::NoBlockFlag) && result == KLockFile::LockFail) {
|
||||
const int randomtimeout = KRandom::randomMax(KLOCKFILE_TIMEOUT) + KLOCKFILE_TIMEOUT;
|
||||
kDebug() << "Retrying to lock after" << (randomtimeout + KLOCKFILE_SLEEPTIME);
|
||||
QCoreApplication::processEvents(QEventLoop::AllEvents, randomtimeout);
|
||||
|
|
Loading…
Add table
Reference in a new issue