From 64cff16e0da3ae9928910a716d9e520ef1070a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pasi=20Pet=C3=A4j=C3=A4j=C3=A4rvi?= Date: Tue, 23 Nov 2021 12:50:02 +0200 Subject: QNX: Fix QLockFile support Implement getting pid by process name and enable using flock(). Pick-to: 6.2 Change-Id: I500e645b451baddea788d834374a7ae29a4d223f Reviewed-by: Thiago Macieira --- src/corelib/io/qlockfile_unix.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp index 4123543c28..6dcd548441 100644 --- a/src/corelib/io/qlockfile_unix.cpp +++ b/src/corelib/io/qlockfile_unix.cpp @@ -59,7 +59,7 @@ #include // flock #endif -#if defined(Q_OS_RTEMS) || defined(Q_OS_QNX) +#if defined(Q_OS_RTEMS) // flock() does not work in these OSes and produce warnings when we try to use # undef LOCK_EX # undef LOCK_NB @@ -278,7 +278,27 @@ QString QLockFilePrivate::processNameByPid(qint64 pid) QString name = QFile::decodeName(kp.ki_comm); # endif return name; +#elif defined(Q_OS_QNX) + char exePath[PATH_MAX]; + sprintf(exePath, "/proc/%lld/exefile", pid); + int fd = qt_safe_open(exePath, O_RDONLY); + if (fd == -1) + return QString(); + + QT_STATBUF sbuf; + if (QT_FSTAT(fd, &sbuf) == -1) { + qt_safe_close(fd); + return QString(); + } + + QByteArray buffer(sbuf.st_size, Qt::Uninitialized); + buffer.resize(qt_safe_read(fd, buffer.data(), sbuf.st_size - 1)); + if (buffer.isEmpty()) { + // The pid is gone. Return some invalid process name to fail the test. + return QStringLiteral("/ERROR/"); + } + return QFileSystemEntry(buffer, QFileSystemEntry::FromNativePath()).fileName(); #else Q_UNUSED(pid); return QString(); -- cgit v1.2.3