You are not logged in.

#1 2015-10-13 01:04:25

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Perl gurus: like to modify vncserver to parse a config [solved]

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.

How would one go about doing this?  I see the section in /usr/bin/vncserver that parses physical switches and passes them along to Xvnc starting at line 254.  Again, I do not know 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!

Last edited by graysky (2015-10-14 23:38:13)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2015-10-13 01:15:12

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,524
Website

Re: Perl gurus: like to modify vncserver to parse a config [solved]

You could do something fancy to parse an ini style config file, but the simplest would be to add just a single line:

  $cmd = $exedir."Xvnc :$displayNumber";
+ do $ENV{'HOME'} . '/.vnc/config';
  $cmd .= " -desktop " . &quotedString($desktopName);

And just format ~/.vmc/config as follows:

$cmd .= ' -geometry=2000x1200';
$cmd .= ' -desktop=sandbox';

Each line should append flags as desired to the $cmd variable.

EDIT: oops - as there are defaults already in the file this wouldn't work quite as is as parameters like 'desktop' would be overrided.  But
you could enclose that whole defaults block in a conditional and either use those, or use the 'do file' if the file exists.  So:

$cmd = $exedir."Xvnc :$displayNumber";

$rcfile = $ENV{'HOME'} . '/.vnc/config';
if ( -e $rcfile ) {
   do $rcfile;
}
else {
   $cmd .= " -desktop " . &quotedString($desktopName);
   ...
}

Also a huge caveat: I hate perl, and all I know about perl is extrapolated (or backward extrapolated) from PHP which I have a bit of experience with.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2015-10-13 01:20:15

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: Perl gurus: like to modify vncserver to parse a config [solved]

Thanks for the suggestion, Trilby.  You going to need to spoon feed me a bit more since I know 0 of perl.  My goal is to send a pull request (or for you to) upstream so whatever you or someone comes up with to accomplish it would probably need to work within the current construct of the script.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#4 2015-10-13 01:21:53

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,524
Website

Re: Perl gurus: like to modify vncserver to parse a config [solved]

Ah, if you are sending it upstream it'd need a bit more polishing.  They probably wouldn't want to just use 'do' and assume the rc file will be well formed perl.  Instead it would need a proper parsing of the config file.  I may come back to this tomorrow after a night of sleep if no one else chimes in.

EDIT: sorry, it turns out I'm not particularly well equipped for this.  Apprently, one of the big differences between php and perl is that the former includes a lot of useful modules by default that are absent from 'vanilla' perl.  If you are able to add perl modules as dependencies this would be very easy.  Without this, it would still be fairly easy to implement in an ugly way - but the "right" way would probably be to use one of the existing modules (ini parser or json decoder for example).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2015-10-14 23:37:36

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: Perl gurus: like to modify vncserver to parse a config [solved]

https://github.com/graysky2/tigervnc/co … 65af3c21e1

Last edited by graysky (2015-10-15 19:39:06)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB