diff options
author | Pasi Petäjäjärvi <pasi.petajajarvi@qt.io> | 2021-11-23 12:50:02 +0200 |
---|---|---|
committer | Pasi Petäjäjärvi <pasi.petajajarvi@qt.io> | 2021-12-14 21:50:52 +0200 |
commit | 64cff16e0da3ae9928910a716d9e520ef1070a7b (patch) | |
tree | 2ce12cf4212e9b893676c19e0a4d0b3f8a976236 /src/corelib/io/qlockfile_unix.cpp | |
parent | f370a4c49c686a54325efc5499449da8cdc4056e (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qlockfile_unix.cpp')
-rw-r--r-- | src/corelib/io/qlockfile_unix.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
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 <sys/file.h> // 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(); |