Shorten LocalPeer socket names
On most systems supporting Unix sockets, the maximum length of a socket name is quite low (e.g. on macOS 104 characters and on Linux 108). If the name is too long, the sockets will not work and thus sending messages to a running instance of the launcher will not work. Signed-off-by: Kenneth Chew <79120643+kthchew@users.noreply.github.com>
This commit is contained in:
@@ -76,7 +76,7 @@ ApplicationId ApplicationId::fromTraditionalApp()
|
||||
prefix.truncate(6);
|
||||
QByteArray idc = protoId.toUtf8();
|
||||
quint16 idNum = qChecksum(idc.constData(), idc.size());
|
||||
auto socketName = QLatin1String("qtsingleapp-") + prefix + QLatin1Char('-') + QString::number(idNum, 16);
|
||||
auto socketName = QLatin1String("pl") + prefix + QLatin1Char('-') + QString::number(idNum, 16).left(12);
|
||||
#if defined(Q_OS_WIN)
|
||||
if (!pProcessIdToSessionId) {
|
||||
QLibrary lib("kernel32");
|
||||
@@ -98,12 +98,12 @@ ApplicationId ApplicationId::fromPathAndVersion(const QString& dataPath, const Q
|
||||
QCryptographicHash shasum(QCryptographicHash::Algorithm::Sha1);
|
||||
QString result = dataPath + QLatin1Char('-') + version;
|
||||
shasum.addData(result.toUtf8());
|
||||
return ApplicationId(QLatin1String("qtsingleapp-") + QString::fromLatin1(shasum.result().toHex()));
|
||||
return ApplicationId(QLatin1String("pl") + QString::fromLatin1(shasum.result().toHex()).left(12));
|
||||
}
|
||||
|
||||
ApplicationId ApplicationId::fromCustomId(const QString& id)
|
||||
{
|
||||
return ApplicationId(QLatin1String("qtsingleapp-") + id);
|
||||
return ApplicationId(QLatin1String("pl") + id);
|
||||
}
|
||||
|
||||
ApplicationId ApplicationId::fromRawString(const QString& id)
|
||||
@@ -139,7 +139,7 @@ bool LocalPeer::isClient()
|
||||
#if defined(Q_OS_UNIX)
|
||||
// ### Workaround
|
||||
if (!res && server->serverError() == QAbstractSocket::AddressInUseError) {
|
||||
QFile::remove(QDir::cleanPath(QDir::tempPath()) + QLatin1Char('/') + socketName);
|
||||
QLocalServer::removeServer(socketName);
|
||||
res = server->listen(socketName);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user