Skip to content

Commit

Permalink
KDSingleApplicationLocalSocket: Handle maximum socket length on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaski authored and nicolasfella committed Dec 28, 2024
1 parent 20103dd commit 8690284
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/kdsingleapplication_localsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ KDSingleApplicationLocalSocket::KDSingleApplicationLocalSocket(const QString &na
userName = alternativeUserName;
}
#elif defined(Q_OS_WIN)

constexpr int maxSocketNameLength = MAX_PATH - 1;
const int tempPathLength = 16; // "\\.\pipe\LOCAL\"

// I'm not sure of a "global session identifier" on Windows; are
// multiple logins from the same user a possibility? For now, following this:
// https://docs.microsoft.com/en-us/windows/desktop/devnotes/getting-the-session-id-of-the-current-process
Expand Down Expand Up @@ -119,7 +123,6 @@ KDSingleApplicationLocalSocket::KDSingleApplicationLocalSocket(const QString &na
m_socketName += QStringLiteral("-");
m_socketName += name;

#if defined(Q_OS_UNIX)
int fullSocketNameLength = tempPathLength + m_socketName.length();
#if defined(Q_OS_LINUX) || defined(Q_OS_QNX)
fullSocketNameLength += 1; // PlatformSupportsAbstractNamespace, see qlocalserver_unix.cpp
Expand All @@ -128,7 +131,6 @@ KDSingleApplicationLocalSocket::KDSingleApplicationLocalSocket(const QString &na
qCDebug(kdsaLocalSocket) << "Chopping socket name because it is longer than" << maxSocketNameLength;
m_socketName.chop(fullSocketNameLength - maxSocketNameLength);
}
#endif

const QString lockFilePath =
QDir::tempPath() + QLatin1Char('/') + m_socketName + QLatin1String(".lock");
Expand Down

0 comments on commit 8690284

Please sign in to comment.