Browse Source

Allow combining socket activation and extra ports

The common use case is probably to only listem to the systemd provided
socket when using socket activation, but it might not be the only use
case. Make sure things can be combined if explicitly requested.
pull/1722/head
Pierre Ossman 3 months ago
parent
commit
311ef22ffd
2 changed files with 50 additions and 36 deletions
  1. 46
    33
      unix/x0vncserver/x0vncserver.cxx
  2. 4
    3
      unix/x0vncserver/x0vncserver.man

+ 46
- 33
unix/x0vncserver/x0vncserver.cxx View File

@@ -116,9 +116,20 @@ static void CleanupSignalHandler(int /*sig*/)
caughtSignal = true;
}

static bool hasSystemdListeners()
{
#ifdef HAVE_SYSTEMD_H
// This also returns true on errors, because we then assume we were
// meant to use systemd but failed somewhere
return sd_listen_fds(0) != 0;
#else
return false;
#endif
}

static int createSystemdListeners(std::list<SocketListener*> *listeners)
{
#ifdef HAVE_SYSTEMD_H
int count = sd_listen_fds(0);
if (count < 0) {
vlog.error("Error getting listening sockets from systemd: %s",
@@ -130,13 +141,11 @@ static int createSystemdListeners(std::list<SocketListener*> *listeners)
listeners->push_back(new TcpListener(SD_LISTEN_FDS_START + i));

return count;
}
#else
static int createSystemdListeners(std::list<SocketListener*> *)
{
(void)listeners;
return 0;
}
#endif
}


class FileTcpFilter : public TcpFilter
@@ -277,6 +286,10 @@ int main(int argc, char** argv)
Configuration::removeParam("SendCutText");
Configuration::removeParam("MaxCutText");

// Assume different defaults when socket activated
if (hasSystemdListeners())
rfbport.setParam(-1);

for (int i = 1; i < argc; i++) {
if (Configuration::setParam(argv[i]))
continue;
@@ -325,40 +338,40 @@ int main(int argc, char** argv)

VNCServerST server(desktopName, &desktop);

if (createSystemdListeners(&listeners)) {
if (createSystemdListeners(&listeners) > 0) {
// When systemd is in charge of listeners, do not listen to anything else
vlog.info("Listening on systemd sockets");
} else {
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);
}
}

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

if (strcasecmp(addr, "all") == 0)
addr = 0;
if (localhostOnly)
createLocalTcpListeners(&tcp_listeners, (int)rfbport);
else
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);
}
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);
}

FileTcpFilter fileTcpFilter(hostsFile);
if (strlen(hostsFile) != 0)
for (std::list<SocketListener*>::iterator i = listeners.begin();
i != listeners.end();
i++)
(*i)->setFilter(&fileTcpFilter);
if ((int)rfbport != -1) {
std::list<network::SocketListener*> tcp_listeners;
const char *addr = interface;

if (strcasecmp(addr, "all") == 0)
addr = 0;
if (localhostOnly)
createLocalTcpListeners(&tcp_listeners, (int)rfbport);
else
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)
for (std::list<SocketListener*>::iterator i = listeners.begin();
i != listeners.end();
i++)
(*i)->setFilter(&fileTcpFilter);
}

if (listeners.empty()) {

+ 4
- 3
unix/x0vncserver/x0vncserver.man View File

@@ -60,8 +60,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. Specify \fB-1\fP to disable listening on a TCP
port. Ignored when activated by a systemd socket.
Specify \fB-1\fP to disable listening on a TCP port. The default port is
5900 when started directly, and -1 when activated by a systemd socket.
.
.TP
.B \-UseIPv4
@@ -74,7 +74,8 @@ 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. Ignored when activated by a systemd socket.
connections from viewers. Default is to not listen to any Unix domain
socket.
.
.TP
.B \-rfbunixmode \fImode\fP

Loading…
Cancel
Save