From 775d432ec72055b3854d22a5fed7c43997e344da Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Sun, 13 Jun 2021 18:28:16 +0200 Subject: [PATCH] Use @ as the default desktop name Is a lot more useful default than the previous "x11", or "x0vncserver". At the same time give x0vncserver a parameter to change the name. --- unix/x0vncserver/x0vncserver.cxx | 37 ++++++++++++++++++++++++++++++- unix/x0vncserver/x0vncserver.man | 5 +++++ unix/xserver/hw/vnc/Xvnc.man | 2 +- unix/xserver/hw/vnc/vncExtInit.cc | 36 +++++++++++++++++++++++++++++- 4 files changed, 77 insertions(+), 3 deletions(-) diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx index 0bf10a90..89c9817e 100644 --- a/unix/x0vncserver/x0vncserver.cxx +++ b/unix/x0vncserver/x0vncserver.cxx @@ -25,6 +25,8 @@ #include #include #include +#include + #include #include #include @@ -50,11 +52,14 @@ using namespace network; static LogWriter vlog("Main"); +static const char* defaultDesktopName(); + IntParameter pollingCycle("PollingCycle", "Milliseconds per one polling " "cycle; actual interval may be dynamically " "adjusted to satisfy MaxProcessorUsage setting", 30); IntParameter maxProcessorUsage("MaxProcessorUsage", "Maximum percentage of " "CPU time to be consumed", 35); +StringParameter desktopName("desktop", "Name of VNC desktop", defaultDesktopName()); StringParameter displayname("display", "The X display", ""); IntParameter rfbport("rfbport", "TCP port to listen for RFB protocol",5900); StringParameter rfbunixpath("rfbunixpath", "Unix socket to listen for RFB protocol", ""); @@ -64,6 +69,36 @@ BoolParameter localhostOnly("localhost", "Only allow connections from localhost", false); +static const char* defaultDesktopName() +{ + static char* name = NULL; + + char hostname[HOST_NAME_MAX + 1]; + struct passwd* pwent; + + size_t len; + + delete [] name; + + if (gethostname(hostname, sizeof(hostname)) == -1) + return ""; + + pwent = getpwuid(getuid()); + if (pwent == NULL) + return ""; + + len = snprintf(NULL, 0, "%s@%s", pwent->pw_name, hostname); + if (len < 0) + return ""; + + name = new char[len + 1]; + + snprintf(name, len + 1, "%s@%s", pwent->pw_name, hostname); + + return name; +} + + // // Allow the main loop terminate itself gracefully on receiving a signal. // @@ -261,7 +296,7 @@ int main(int argc, char** argv) } XDesktop desktop(dpy, &geo); - VNCServerST server("x0vncserver", &desktop); + VNCServerST server(desktopName, &desktop); if (rfbunixpath.getValueStr()[0] != '\0') { listeners.push_back(new network::UnixListener(rfbunixpath, rfbunixmode)); diff --git a/unix/x0vncserver/x0vncserver.man b/unix/x0vncserver/x0vncserver.man index 55f30454..3ee0c97b 100644 --- a/unix/x0vncserver/x0vncserver.man +++ b/unix/x0vncserver/x0vncserver.man @@ -46,6 +46,11 @@ arbitrary. .SH PARAMETERS +.TP +.B \-desktop \fIdesktop-name\fP +Each desktop has a name which may be displayed by the viewer. It defaults to +"@". +. .TP .B \-display \fIdisplay\fP The X display name. If not specified, it defaults to the value of the diff --git a/unix/xserver/hw/vnc/Xvnc.man b/unix/xserver/hw/vnc/Xvnc.man index c85c396f..59ed4ac0 100644 --- a/unix/xserver/hw/vnc/Xvnc.man +++ b/unix/xserver/hw/vnc/Xvnc.man @@ -72,7 +72,7 @@ case-insensitive. .TP .B \-desktop \fIdesktop-name\fP Each desktop has a name which may be displayed by the viewer. It defaults to -"x11". +"@". . .TP .B \-rfbport \fIport\fP diff --git a/unix/xserver/hw/vnc/vncExtInit.cc b/unix/xserver/hw/vnc/vncExtInit.cc index 6c4612d1..bdf563a8 100644 --- a/unix/xserver/hw/vnc/vncExtInit.cc +++ b/unix/xserver/hw/vnc/vncExtInit.cc @@ -19,6 +19,9 @@ #include #include +#include +#include +#include #include #include @@ -73,10 +76,12 @@ struct CaseInsensitiveCompare { typedef std::set ParamSet; static ParamSet allowOverrideSet; +static const char* defaultDesktopName(); + rfb::IntParameter rfbport("rfbport", "TCP port to listen for RFB protocol",0); rfb::StringParameter rfbunixpath("rfbunixpath", "Unix socket to listen for RFB protocol", ""); rfb::IntParameter rfbunixmode("rfbunixmode", "Unix socket access mode", 0600); -rfb::StringParameter desktopName("desktop", "Name of VNC desktop","x11"); +rfb::StringParameter desktopName("desktop", "Name of VNC desktop", defaultDesktopName()); rfb::BoolParameter localhostOnly("localhost", "Only allow connections from localhost", false); @@ -95,6 +100,35 @@ rfb::BoolParameter sendPrimary("SendPrimary", "Send the PRIMARY as well as the CLIPBOARD selection", true); +static const char* defaultDesktopName() +{ + static char* name = NULL; + + char hostname[HOST_NAME_MAX + 1]; + struct passwd* pwent; + + size_t len; + + delete [] name; + + if (gethostname(hostname, sizeof(hostname)) == -1) + return ""; + + pwent = getpwuid(getuid()); + if (pwent == NULL) + return ""; + + len = snprintf(NULL, 0, "%s@%s", pwent->pw_name, hostname); + if (len < 0) + return ""; + + name = new char[len + 1]; + + snprintf(name, len + 1, "%s@%s", pwent->pw_name, hostname); + + return name; +} + static PixelFormat vncGetPixelFormat(int scrIdx) { int depth, bpp; -- 2.39.5