From 3c689c4b3fd24ead8726444723536452d0e89d85 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 30 Jun 2017 12:30:45 -0700 Subject: QLockFile: Move the check for Linux /proc to a central place I'll need it soon in QTemporaryFile. This also reduces the overhead, since QFile::exists -> QFileInfo::exists needs to check if there's a file engine that handles "/proc/version" (there isn't), convert the UTF-16 filename to UTF-8 and QFileSystemEngine::fillMetaData will issue a more expensive stat(2) syscall. access(2) is cheaper. This commit also introduces QT_LINUX_ALWAYS_HAVE_PROCFS that isn't defined anywhere, but could be passed during configure with -D if a build wants it. Change-Id: I1eba2b016de74620bfc8fffd14ccfd1593d59ade Reviewed-by: Lars Knoll --- src/corelib/io/qlockfile_unix.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/io/qlockfile_unix.cpp') diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp index ccc607afd5..f21aced87c 100644 --- a/src/corelib/io/qlockfile_unix.cpp +++ b/src/corelib/io/qlockfile_unix.cpp @@ -199,7 +199,7 @@ QLockFile::LockError QLockFilePrivate::tryLock_sys() } if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size()) { - close(fd); + qt_safe_close(fd); if (!QFile::remove(fileName)) qWarning("QLockFile: Could not remove our own lock file %s.", qPrintable(fileName)); return QLockFile::UnknownError; // partition full @@ -258,7 +258,7 @@ QString QLockFilePrivate::processNameByPid(qint64 pid) proc_name(pid, name, sizeof(name) / sizeof(char)); return QFile::decodeName(name); #elif defined(Q_OS_LINUX) - if (!QFile::exists(QStringLiteral("/proc/version"))) + if (!qt_haveLinuxProcfs()) return QString(); char exePath[64]; char buf[PATH_MAX + 1]; -- cgit v1.2.3