QNX: Fix support for abstract Unix-domain socket

As QNX claims to support abstract Unix-domain sockets, its getsockname
always returns for socket that has not been bound to local name
address_len of sun_path as maximum length (106) even when it does not
contain valid address.
https://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.neutrino.lib_ref/topic/u/unix_proto.html

Pick-to: 6.2 6.3
Change-Id: I0f0f5c05611c8db6af35377dde16450f58c83c56
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Pasi Petäjäjärvi 2022-02-21 12:19:49 +02:00 committed by Thiago Macieira
parent df270368ee
commit 3a151faec2
3 changed files with 7 additions and 3 deletions

View File

@ -59,7 +59,7 @@
QT_BEGIN_NAMESPACE
enum {
#ifdef Q_OS_LINUX
#if defined(Q_OS_LINUX) || defined(Q_OS_QNX)
PlatformSupportsAbstractNamespace = true
#else
PlatformSupportsAbstractNamespace = false

View File

@ -239,6 +239,10 @@ bool QLocalServerPrivate::listen(qintptr socketDescriptor)
QT_SOCKLEN_T len = sizeof(addr);
memset(&addr, 0, sizeof(addr));
if (::getsockname(socketDescriptor, (sockaddr *)&addr, &len) == 0) {
#if defined(Q_OS_QNX)
if (addr.sun_path[0] == 0 && addr.sun_path[1] == 0)
len = SUN_LEN(&addr);
#endif
if (QLocalSocketPrivate::parseSockaddr(addr, len, fullServerName, serverName,
abstractAddress)) {
QLocalServer::SocketOptions options = socketOptions.value();

View File

@ -1765,7 +1765,7 @@ void tst_QLocalSocket::verifyListenWithDescriptor()
QLocalServer server;
QVERIFY2(server.listen(listenSocket), "failed to start create QLocalServer with local socket");
#ifdef Q_OS_LINUX
#if defined(Q_OS_LINUX) || defined(Q_OS_QNX)
if (!bound) {
QCOMPARE(server.serverName().isEmpty(), true);
QCOMPARE(server.fullServerName().isEmpty(), true);
@ -1806,7 +1806,7 @@ void tst_QLocalSocket::verifyListenWithDescriptor_data()
QTest::addColumn<bool>("bound");
QTest::newRow("normal") << QDir::tempPath() + QLatin1String("/testsocket") << false << true;
#ifdef Q_OS_LINUX
#if defined(Q_OS_LINUX) || defined(Q_OS_QNX)
QTest::newRow("abstract") << QString::fromLatin1("abstractsocketname") << true << true;
QTest::newRow("abstractwithslash") << QString::fromLatin1("abstractsocketwitha/inthename") << true << true;
#endif