From 1ffe1a9a7c5199e46bf280806456a5d86f314169 Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Thu, 23 Oct 2014 09:50:57 +0200 Subject: 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 --- src/corelib/io/qlockfile.cpp | 2 +- src/corelib/io/qlockfile_unix.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qlockfile.cpp b/src/corelib/io/qlockfile.cpp index 18a782a8f3..c256507430 100644 --- a/src/corelib/io/qlockfile.cpp +++ b/src/corelib/io/qlockfile.cpp @@ -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(); diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp index 2fe93f0af6..3ed973494b 100644 --- a/src/corelib/io/qlockfile_unix.cpp +++ b/src/corelib/io/qlockfile_unix.cpp @@ -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 } -- cgit v1.2.3