Skip to content

Commit 3242687

Browse files
fix(simulator): pin local socket to /tmp on Unix instead of $TMPDIR
QLocalServer's default TempLocation on macOS is a per-user $TMPDIR like /var/folders/.../T/, which is awkward to find when the other end of the socket is a Python script driven from a shell. Resolve bare names to /tmp/<name> on Unix so the path is predictable and matches Linux. Absolute paths supplied by the user pass through unchanged. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f557e0a commit 3242687

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

companion/src/simulation/hostserialbackend_localsocket.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,36 @@ QLocalSocketBackend::~QLocalSocketBackend()
4040
close();
4141
}
4242

43+
QString QLocalSocketBackend::resolveListenName(const QString & name)
44+
{
45+
#ifdef Q_OS_UNIX
46+
// Qt defaults to QStandardPaths::TempLocation, which on macOS is
47+
// a per-user $TMPDIR (e.g. /var/folders/.../T/) — fine for IPC
48+
// between Qt apps, painful when the other end is a Python script
49+
// a user is poking from a shell. Pin bare names to /tmp/<name>
50+
// so the resolved path is predictable on both macOS and Linux.
51+
// Absolute paths supplied by the user are passed through as-is.
52+
if (!name.startsWith(QLatin1Char('/')))
53+
return QStringLiteral("/tmp/") + name;
54+
#endif
55+
return name;
56+
}
57+
4358
bool QLocalSocketBackend::open()
4459
{
4560
if (server->isListening())
4661
return true;
4762

63+
const QString listenName = resolveListenName(socketName);
64+
4865
// A previous run (or another process) may have left a stale socket
4966
// file behind on Unix; QLocalServer::removeServer is the documented
5067
// way to clear it before re-listening.
51-
QLocalServer::removeServer(socketName);
68+
QLocalServer::removeServer(listenName);
5269

53-
if (!server->listen(socketName)) {
70+
if (!server->listen(listenName)) {
5471
emit errorOccurred(tr("Failed to listen on local socket \"%1\": %2")
55-
.arg(socketName, server->errorString()));
72+
.arg(listenName, server->errorString()));
5673
return false;
5774
}
5875

companion/src/simulation/hostserialbackend_localsocket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class QLocalSocketBackend : public HostSerialBackend
6262
void onClientDisconnected();
6363

6464
private:
65+
static QString resolveListenName(const QString & name);
66+
6567
QString socketName;
6668
QLocalServer * server;
6769
QLocalSocket * client;

0 commit comments

Comments
 (0)