From 701605e424c7f9d6b38722b30876df3417cfd0a1 Mon Sep 17 00:00:00 2001 From: Jocelyn Le Sage Date: Fri, 22 Jan 2021 19:56:53 -0500 Subject: [PATCH] Added the ability to listen on both Unix socket and TCP port. Setting `rfbport` to `-1` disables TCP port listening. --- unix/x0vncserver/x0vncserver.cxx | 4 +++- unix/x0vncserver/x0vncserver.man | 5 +++-- unix/xserver/hw/vnc/Xvnc.man | 5 +++-- unix/xserver/hw/vnc/vncExtInit.cc | 10 ++++++++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx index 1531de60..0aa2a92b 100644 --- a/unix/x0vncserver/x0vncserver.cxx +++ b/unix/x0vncserver/x0vncserver.cxx @@ -261,7 +261,9 @@ int main(int argc, char** argv) if (rfbunixpath.getValueStr()[0] != '\0') { listeners.push_back(new network::UnixListener(rfbunixpath, rfbunixmode)); vlog.info("Listening on %s (mode %04o)", (const char*)rfbunixpath, (int)rfbunixmode); - } else { + } + + if ((int)rfbport != -1) { if (localhostOnly) createLocalTcpListeners(&listeners, (int)rfbport); else diff --git a/unix/x0vncserver/x0vncserver.man b/unix/x0vncserver/x0vncserver.man index 094abbe9..e1a4646f 100644 --- a/unix/x0vncserver/x0vncserver.man +++ b/unix/x0vncserver/x0vncserver.man @@ -55,7 +55,8 @@ DISPLAY environment variable. .B \-rfbport \fIport\fP Specifies the TCP port on which x0vncserver listens for connections from viewers (the protocol used in VNC is called RFB - "remote framebuffer"). -The default port is 5900. +The default port is 5900. Listening on TCP port can be disabled with +-\frfbport\fP=-1. . .TP .B \-UseIPv4 @@ -68,7 +69,7 @@ Use IPv6 for incoming and outgoing connections. Default is on. .TP .B \-rfbunixpath \fIpath\fP Specifies the path of a Unix domain socket on which x0vncserver listens for -connections from viewers, instead of listening on a TCP port. +connections from viewers. . .TP .B \-rfbunixmode \fImode\fP diff --git a/unix/xserver/hw/vnc/Xvnc.man b/unix/xserver/hw/vnc/Xvnc.man index 2d0089d7..c85c396f 100644 --- a/unix/xserver/hw/vnc/Xvnc.man +++ b/unix/xserver/hw/vnc/Xvnc.man @@ -78,7 +78,8 @@ Each desktop has a name which may be displayed by the viewer. It defaults to .B \-rfbport \fIport\fP Specifies the TCP port on which Xvnc listens for connections from viewers (the protocol used in VNC is called RFB - "remote framebuffer"). The default is -5900 plus the display number. +5900 plus the display number. Listening on TCP port can be disabled with +-\frfbport\fP=-1. . .TP .B \-UseIPv4 @@ -91,7 +92,7 @@ Use IPv6 for incoming and outgoing connections. Default is on. .TP .B \-rfbunixpath \fIpath\fP Specifies the path of a Unix domain socket on which Xvnc listens for -connections from viewers, instead of listening on a TCP port. +connections from viewers. . .TP .B \-rfbunixmode \fImode\fP diff --git a/unix/xserver/hw/vnc/vncExtInit.cc b/unix/xserver/hw/vnc/vncExtInit.cc index 1e7513a9..a45c5bde 100644 --- a/unix/xserver/hw/vnc/vncExtInit.cc +++ b/unix/xserver/hw/vnc/vncExtInit.cc @@ -168,13 +168,17 @@ void vncExtensionInit(void) if (!desktop[scr]) { std::list listeners; + bool inetd = false; if (scr == 0 && vncInetdSock != -1) { + inetd = true; if (network::isSocketListening(vncInetdSock)) { listeners.push_back(new network::TcpListener(vncInetdSock)); vlog.info("inetd wait"); } - } else if (((const char*)rfbunixpath)[0] != '\0') { + } + + if (!inetd && ((const char*)rfbunixpath)[0] != '\0') { char path[PATH_MAX]; int mode = (int)rfbunixmode; @@ -189,7 +193,9 @@ void vncExtensionInit(void) vlog.info("Listening for VNC connections on %s (mode %04o)", path, mode); - } else { + } + + if (!inetd && rfbport != -1) { const char *addr = interface; int port = rfbport; if (port == 0) port = 5900 + atoi(vncGetDisplay()); -- 2.39.5