* All build requirements Xorg imposes (see its documentation) | * All build requirements Xorg imposes (see its documentation) | ||||
* patch | * patch | ||||
-- If building x0vncserver with socket activation support: | |||||
* libsystemd | |||||
-- Optional ffmpeg development kit support (libav) | -- Optional ffmpeg development kit support (libav) | ||||
* You might have to enable additional repositories for this. E.g., | * You might have to enable additional repositories for this. E.g., | ||||
on RHEL, EPEL and RPMFusion (free + nonfree) need to be enabled. | on RHEL, EPEL and RPMFusion (free + nonfree) need to be enabled. |
endif() | endif() | ||||
endif() | endif() | ||||
# check for systemd support (socket activation) | |||||
if(UNIX AND NOT APPLE) | |||||
find_package(PkgConfig) | |||||
if (PKG_CONFIG_FOUND) | |||||
pkg_check_modules(LIBSYSTEMD libsystemd) | |||||
endif() | |||||
endif() | |||||
# Generate config.h and make sure the source finds it | # Generate config.h and make sure the source finds it | ||||
configure_file(config.h.in config.h) | configure_file(config.h.in config.h) | ||||
add_definitions(-DHAVE_CONFIG_H) | add_definitions(-DHAVE_CONFIG_H) |
target_include_directories(x0vncserver PUBLIC ${CMAKE_SOURCE_DIR}/common) | target_include_directories(x0vncserver PUBLIC ${CMAKE_SOURCE_DIR}/common) | ||||
target_link_libraries(x0vncserver tx rfb network rdr unixcommon) | target_link_libraries(x0vncserver tx rfb network rdr unixcommon) | ||||
# systemd support (socket activation) | |||||
if (LIBSYSTEMD_FOUND) | |||||
add_definitions(-DHAVE_SYSTEMD_H) | |||||
target_link_libraries(x0vncserver ${LIBSYSTEMD_LIBRARIES}) | |||||
endif() | |||||
if(X11_FOUND AND X11_XTest_LIB) | if(X11_FOUND AND X11_XTest_LIB) | ||||
add_definitions(-DHAVE_XTEST) | add_definitions(-DHAVE_XTEST) | ||||
target_link_libraries(x0vncserver ${X11_XTest_LIB}) | target_link_libraries(x0vncserver ${X11_XTest_LIB}) |
#include <rfb/Timer.h> | #include <rfb/Timer.h> | ||||
#include <network/TcpSocket.h> | #include <network/TcpSocket.h> | ||||
#include <network/UnixSocket.h> | #include <network/UnixSocket.h> | ||||
#ifdef HAVE_SYSTEMD_H | |||||
# include <systemd/sd-daemon.h> | |||||
#endif | |||||
#include <signal.h> | #include <signal.h> | ||||
#include <X11/X.h> | #include <X11/X.h> | ||||
caughtSignal = true; | 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", | |||||
strerror(-count)); | |||||
return count; | |||||
} | |||||
for (int i = 0; i < count; ++i) | |||||
listeners->push_back(new TcpListener(SD_LISTEN_FDS_START + i)); | |||||
return count; | |||||
#else | |||||
(void)listeners; | |||||
return 0; | |||||
#endif | |||||
} | |||||
class FileTcpFilter : public TcpFilter | class FileTcpFilter : public TcpFilter | ||||
{ | { | ||||
Configuration::removeParam("SendCutText"); | Configuration::removeParam("SendCutText"); | ||||
Configuration::removeParam("MaxCutText"); | Configuration::removeParam("MaxCutText"); | ||||
// Assume different defaults when socket activated | |||||
if (hasSystemdListeners()) | |||||
rfbport.setParam(-1); | |||||
for (int i = 1; i < argc; i++) { | for (int i = 1; i < argc; i++) { | ||||
if (Configuration::setParam(argv[i])) | if (Configuration::setParam(argv[i])) | ||||
continue; | continue; | ||||
VNCServerST server(desktopName, &desktop); | VNCServerST server(desktopName, &desktop); | ||||
if (createSystemdListeners(&listeners) > 0) { | |||||
// When systemd is in charge of listeners, do not listen to anything else | |||||
vlog.info("Listening on systemd sockets"); | |||||
} | |||||
if (rfbunixpath.getValueStr()[0] != '\0') { | if (rfbunixpath.getValueStr()[0] != '\0') { | ||||
listeners.push_back(new network::UnixListener(rfbunixpath, rfbunixmode)); | listeners.push_back(new network::UnixListener(rfbunixpath, rfbunixmode)); | ||||
vlog.info("Listening on %s (mode %04o)", (const char*)rfbunixpath, (int)rfbunixmode); | vlog.info("Listening on %s (mode %04o)", (const char*)rfbunixpath, (int)rfbunixmode); |
.B \-rfbport \fIport\fP | .B \-rfbport \fIport\fP | ||||
Specifies the TCP port on which x0vncserver listens for connections from | Specifies the TCP port on which x0vncserver listens for connections from | ||||
viewers (the protocol used in VNC is called RFB - "remote framebuffer"). | 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. | |||||
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 | .TP | ||||
.B \-UseIPv4 | .B \-UseIPv4 | ||||
.TP | .TP | ||||
.B \-rfbunixpath \fIpath\fP | .B \-rfbunixpath \fIpath\fP | ||||
Specifies the path of a Unix domain socket on which x0vncserver listens for | Specifies the path of a Unix domain socket on which x0vncserver listens for | ||||
connections from viewers. | |||||
connections from viewers. Default is to not listen to any Unix domain | |||||
socket. | |||||
. | . | ||||
.TP | .TP | ||||
.B \-rfbunixmode \fImode\fP | .B \-rfbunixmode \fImode\fP |