From 9ca850a108cab215a72e579271dcfccad7df075b Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Fri, 13 Aug 2021 12:15:17 +0300 Subject: [PATCH] Add pid to the internal socket name, clarify websocketport bind error --- common/network/TcpSocket.cxx | 11 ++++++++--- common/network/websockify.c | 8 ++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 141bdf7..f6f4a5a 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include "websocket.h" #include @@ -564,7 +566,7 @@ WebsocketListener::WebsocketListener(const struct sockaddr *listenaddr, if (bind(sock, &sa.u.sa, listenaddrlen) == -1) { int e = errorNumber; closesocket(sock); - throw SocketException("failed to bind socket", e); + throw SocketException("failed to bind socket, is someone else on our -websocketPort?", e); } listen(sock); // sets the internal fd @@ -574,13 +576,16 @@ WebsocketListener::WebsocketListener(const struct sockaddr *listenaddr, // internalSocket = socket(AF_UNIX, SOCK_STREAM, 0); + char sockname[32]; + sprintf(sockname, ".KasmVNCSock%u", getpid()); + struct sockaddr_un addr; addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, ".KasmVNCSock"); + strcpy(addr.sun_path, sockname); addr.sun_path[0] = '\0'; if (bind(internalSocket, (struct sockaddr *) &addr, - sizeof(sa_family_t) + sizeof(".KasmVNCSock"))) { + sizeof(sa_family_t) + strlen(sockname))) { throw SocketException("failed to bind socket", errorNumber); } diff --git a/common/network/websockify.c b/common/network/websockify.c index 08491c9..a97c189 100644 --- a/common/network/websockify.c +++ b/common/network/websockify.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "websocket.h" /* @@ -223,9 +224,12 @@ static void do_proxy(ws_ctx_t *ws_ctx, int target) { void proxy_handler(ws_ctx_t *ws_ctx) { + char sockname[32]; + sprintf(sockname, ".KasmVNCSock%u", getpid()); + struct sockaddr_un addr; addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, ".KasmVNCSock"); + strcpy(addr.sun_path, sockname); addr.sun_path[0] = '\0'; struct timeval tv; @@ -243,7 +247,7 @@ void proxy_handler(ws_ctx_t *ws_ctx) { handler_msg("connecting to VNC target\n"); if (connect(tsock, (struct sockaddr *) &addr, - sizeof(sa_family_t) + sizeof(".KasmVNCSock")) < 0) { + sizeof(sa_family_t) + strlen(sockname)) < 0) { handler_emsg("Could not connect to target: %s\n", strerror(errno));