Allow hostname from lock files to be empty

The common format for lock files is to only contain the PID.
(See http://www.pathname.com/fhs/2.2/fhs-5.9.html)
Qt includes some extra information but we can not expect this
information to be present. Otherwise lock files created by other
(non-Qt) processes are not handled correctly.

Change-Id: Ib9be3c9f07eb8e87193f56d96f5559bbdd5180b8
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Rainer Keller 2014-10-23 09:50:57 +02:00
parent 81998b4e8e
commit 1ffe1a9a7c
2 changed files with 2 additions and 2 deletions

View File

@ -287,7 +287,7 @@ bool QLockFilePrivate::getLockInfo(qint64 *pid, QString *hostname, QString *appn
appNameLine.chop(1);
QByteArray hostNameLine = reader.readLine();
hostNameLine.chop(1);
if (pidLine.isEmpty() || appNameLine.isEmpty())
if (pidLine.isEmpty())
return false;
qint64 thePid = pidLine.toLongLong();

View File

@ -183,7 +183,7 @@ bool QLockFilePrivate::isApparentlyStale() const
QString hostname, appname;
if (!getLockInfo(&pid, &hostname, &appname))
return false;
if (hostname == QString::fromLocal8Bit(localHostName())) {
if (hostname.isEmpty() || hostname == QString::fromLocal8Bit(localHostName())) {
if (::kill(pid, 0) == -1 && errno == ESRCH)
return true; // PID doesn't exist anymore
}