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]; diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index eca575ba01..ea5d98cbf3 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -340,6 +340,21 @@ static inline pid_t qt_safe_waitpid(pid_t pid, int *status, int options) timespec qt_gettime() Q_DECL_NOTHROW; void qt_nanosleep(timespec amount); +/* non-static */ +inline bool qt_haveLinuxProcfs() +{ +#ifdef Q_OS_LINUX +# ifdef QT_LINUX_ALWAYS_HAVE_PROCFS + return true; +# else + static const bool present = (access("/proc/version", F_OK) == 0); + return present; +# endif +#else + return false; +#endif +} + Q_CORE_EXPORT int qt_safe_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts); static inline int qt_poll_msecs(struct pollfd *fds, nfds_t nfds, int timeout)