gsky has asked for the wisdom of the Perl Monks concerning the following question:

I do not know perl but I would like to modify the perl wrapper script for vncserver provided by tigervnc to optionally parse a config file, say $HOME/.vnc/config to interpret the equivalent of the switches supported by vncserver.

For example:
~/.vnc/config geometry=2000x1200 desktop=sandbox alwaysshared=1 localhost=1

The goal is to avoid using switches when invoking /usr/bin/vncserver if ~/.vnc/config exists and has them defined such that the script will look for that file, and parse these variables out passing them to the invocation of Xvnc automatically. I see the section in /usr/bin/vncserver that parses physical switches and passes them along to Xvnc starting at line 254 of the code. I could do this in bash no problem, but I don't speak perl.

Can someone who does mock-up this modification? I am glad to repeat for each option, but I need some model on which to build.

Thanks!

Replies are listed 'Best First'.
Re: Like to modify /usr/bin/vncserver to parse a config file
by Anonymous Monk on Oct 13, 2015 at 14:50 UTC

    That script looks to be written in a quite old style of Perl, and it doesn't make use of any standard modules where it could, and could take a lot of clean up work to bring it up to modern standards. Sure, it could be modified*, but it might not hurt to take a step back:

    The goal is to avoid using switches when invoking /usr/bin/vncserver

    Are you sure that's the easiest solution to the problem (which you haven't described)? It requires you to maintain a patched version of a script you don't fully understand. Why not just write a small wrapper shell script around vncserver?

    #!/bin/sh /usr/bin/vncserver -geometry 2000x1200 # ... etc

    * Quick & dirty example (requires Config::Tiny):

    use Config::Tiny; my $cfg = Config::Tiny->read("$ENV{HOME}/.vnc/config"); $geometry = $cfg->{_}{geometry} if exists $cfg->{_}{geometry};

    Just enough rope ;)

      Thank you for the reply. I should have mentioned that I would like to submit a pull request upstream (to the proper tigervnc server project) to enable that script to find a parse out the config file. It is needed for another submission: a systemd user service which I have already written.

      For the user service to be general, any standard options (switches) should be captured in the config file so that they are not hard-coded into the service itself. Minimum needs: Check for $HOMEDIR/.vnc/config and source it, parse it, and use the options therein in the call to Xvnc as they do in their script.

        Check for $HOMEDIR/.vnc/config

        This should get your started:

        use Config::Tiny; my $CONFIGFILE = "$ENV{HOME}/.vnc/config"; if (-f $CONFIGFILE) { my $cfg = Config::Tiny->read($CONFIGFILE); $geometry = $cfg->{_}{geometry} if exists $cfg->{_}{geometry}; # ... etc. }
Re: Like to modify /usr/bin/vncserver to parse a config file
by stevieb (Canon) on Oct 13, 2015 at 15:09 UTC

    I was thinking along the same lines as Anonymonk above. Here's a little wrapper with example config file that I think should get you close to what you need. I don't know what the actual values for the parameters are supposed to be, nor can I test it. If there is no value after the =, it is considered undef and won't be loaded.

    Code:

    use warnings; use strict; use Config::Tiny; if (! $ARGV[0]){ print "Usage: $0 servername\n"; } my $server = $ARGV[0]; my $conf = Config::Tiny->read('~/vnc.conf'); my $cmd = "/usr/bin/vncviewer $server "; while (my ($option, $value) = each %{ $conf->{vnc} }){ if (defined $value && $value ne ''){ $cmd .= "$option $value "; } } system($cmd);

    Config file:

    [vnc] -name = steve -desktop = mine -httpd = 0 -auth = steve -geometry = 640x480 -depth = 1 -pixelformat = -rfbwait = -rfbauth = -rfbport = 5590 -fp = -pn =

    Here's the command that would be run by system() when you invoke the script like ./vnc.pl servername:

    /usr/bin/vncviewer servername -geometry 640x480 -auth steve -desktop m +ine -httpd 0 -depth 1 -name steve -rfbport 5590

      Thank you for this contribution. I think it's an elegant way to accomplish the goal. Is it possible to integrate this type of solution into the upstream script I linked such that if ~/.vnc/config exists, that would will invoke Xvnc parsing the file, else use the workflow upstream has setup?

      Again, the goal I should have mentioned in my original post is to have upstream (tigervnc) review and ultimately accept this modification, so I can't implement in a wrapper script as a one-off. Thanks again!