Add pid to the internal socket name, clarify websocketport bind error

This commit is contained in:
Lauri Kasanen 2021-08-13 12:15:17 +03:00
parent ec6bd697a8
commit 9ca850a108
2 changed files with 14 additions and 5 deletions

View File

@ -40,6 +40,8 @@
#include <unistd.h>
#include <pthread.h>
#include <wordexp.h>
#include <sys/types.h>
#include <unistd.h>
#include "websocket.h"
#include <network/GetAPI.h>
@ -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);
}

View File

@ -21,6 +21,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#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));