Skip to content

Commit

Permalink
More graceful handling of disabled listeners
Browse files Browse the repository at this point in the history
Don't assume a lack of TCP listeners means the server will be
unreachable. There might be other methods of access, so let the higher
levels do that sanity check instead.
  • Loading branch information
CendioOssman committed Sep 8, 2023
1 parent b0c1dba commit 963f11e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
4 changes: 0 additions & 4 deletions common/network/TcpSocket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,6 @@ void network::createTcpListeners(std::list<SocketListener*> *listeners,
}
}

if (new_listeners.empty ())
throw SocketException("createTcpListeners: no addresses available",
EADDRNOTAVAIL);

listeners->splice (listeners->end(), new_listeners);
}

Expand Down
21 changes: 16 additions & 5 deletions unix/x0vncserver/x0vncserver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,22 @@ int main(int argc, char** argv)
}

if ((int)rfbport != -1) {
std::list<network::SocketListener*> tcp_listeners;
const char *addr = interface;

if (strcasecmp(addr, "all") == 0)
addr = 0;
if (localhostOnly)
createLocalTcpListeners(&listeners, (int)rfbport);
createLocalTcpListeners(&tcp_listeners, (int)rfbport);
else
createTcpListeners(&listeners, addr, (int)rfbport);
vlog.info("Listening for VNC connections on %s interface(s), port %d",
localhostOnly ? "local" : (const char*)interface,
(int)rfbport);
createTcpListeners(&tcp_listeners, addr, (int)rfbport);

if (!tcp_listeners.empty()) {
listeners.splice (listeners.end(), tcp_listeners);
vlog.info("Listening for VNC connections on %s interface(s), port %d",
localhostOnly ? "local" : (const char*)interface,
(int)rfbport);
}

FileTcpFilter fileTcpFilter(hostsFile);
if (strlen(hostsFile) != 0)
Expand All @@ -325,6 +331,11 @@ int main(int argc, char** argv)
(*i)->setFilter(&fileTcpFilter);
}

if (listeners.empty()) {
vlog.error("No path or port configured for incoming connections");
return -1;
}

PollingScheduler sched((int)pollingCycle, (int)maxProcessorUsage);

while (!caughtSignal) {
Expand Down
17 changes: 12 additions & 5 deletions unix/xserver/hw/vnc/vncExtInit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,29 @@ void vncExtensionInit(void)
}

if (!inetd && rfbport != -1) {
std::list<network::SocketListener*> tcp_listeners;
const char *addr = interface;
int port = rfbport;
if (port == 0) port = 5900 + atoi(vncGetDisplay());
port += 1000 * scr;
if (strcasecmp(addr, "all") == 0)
addr = 0;
if (localhostOnly)
network::createLocalTcpListeners(&listeners, port);
network::createLocalTcpListeners(&tcp_listeners, port);
else
network::createTcpListeners(&listeners, addr, port);
network::createTcpListeners(&tcp_listeners, addr, port);

vlog.info("Listening for VNC connections on %s interface(s), port %d",
localhostOnly ? "local" : (const char*)interface,
port);
if (!tcp_listeners.empty()) {
listeners.splice (listeners.end(), tcp_listeners);
vlog.info("Listening for VNC connections on %s interface(s), port %d",
localhostOnly ? "local" : (const char*)interface,
port);
}
}

if (!inetd && listeners.empty())
throw rdr::Exception("No path or port configured for incoming connections");

PixelFormat pf = vncGetPixelFormat(scr);

vncSetGlueContext(scr);
Expand Down
2 changes: 2 additions & 0 deletions vncviewer/vncviewer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,8 @@ int main(int argc, char** argv)
port = atoi(vncServerName);

createTcpListeners(&listeners, 0, port);
if (listeners.empty())
throw Exception(_("Unable to listen for incoming connections"));

vlog.info(_("Listening on port %d"), port);

Expand Down

0 comments on commit 963f11e

Please sign in to comment.