Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | # |
DRC | b9d8e76 | 2011-02-09 08:24:58 +0000 | [diff] [blame] | 3 | # Copyright (C) 2009-2010 D. R. Commander. All Rights Reserved. |
DRC | 190854c | 2009-03-26 18:13:00 +0000 | [diff] [blame] | 4 | # Copyright (C) 2005-2006 Sun Microsystems, Inc. All Rights Reserved. |
| 5 | # Copyright (C) 2002-2003 Constantin Kaplinsky. All Rights Reserved. |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 6 | # Copyright (C) 2002-2005 RealVNC Ltd. |
| 7 | # Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. |
| 8 | # |
| 9 | # This is free software; you can redistribute it and/or modify |
| 10 | # it under the terms of the GNU General Public License as published by |
| 11 | # the Free Software Foundation; either version 2 of the License, or |
| 12 | # (at your option) any later version. |
| 13 | # |
| 14 | # This software is distributed in the hope that it will be useful, |
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | # GNU General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU General Public License |
| 20 | # along with this software; if not, write to the Free Software |
| 21 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 22 | # USA. |
| 23 | # |
| 24 | |
| 25 | # |
| 26 | # vncserver - wrapper script to start an X VNC server. |
| 27 | # |
| 28 | |
| 29 | # |
| 30 | # First make sure we're operating in a sane environment. |
| 31 | # |
| 32 | |
DRC | 190854c | 2009-03-26 18:13:00 +0000 | [diff] [blame] | 33 | $exedir = ""; |
| 34 | $slashndx = rindex($0, "/"); |
| 35 | if($slashndx>=0) { |
| 36 | $exedir = substr($0, 0, $slashndx+1); |
| 37 | } |
| 38 | |
| 39 | $vncClasses = ""; |
| 40 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 41 | &SanityCheck(); |
| 42 | |
| 43 | # |
| 44 | # Global variables. You may want to configure some of these for your site. |
| 45 | # |
| 46 | |
| 47 | $geometry = "1024x768"; |
DRC | 9d1c157 | 2009-03-26 18:18:51 +0000 | [diff] [blame] | 48 | #$depth = 16; |
DRC | e85eba5 | 2011-10-04 06:57:19 +0000 | [diff] [blame] | 49 | $vncJavaFiles = (((-d "$vncClasses") && "$vncClasses") || |
| 50 | ((-d "/usr/share/vnc/classes") && "/usr/share/vnc/classes") || |
| 51 | ((-d "/usr/local/vnc/classes") && "/usr/local/vnc/classes")); |
| 52 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 53 | $vncUserDir = "$ENV{HOME}/.vnc"; |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 54 | $skipxstartup = 0; |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 55 | $xauthorityFile = "$ENV{XAUTHORITY}" || "$ENV{HOME}/.Xauthority"; |
| 56 | |
Llorenç Garcia Martinez | e76c2fb | 2015-10-30 11:07:40 +0100 | [diff] [blame] | 57 | $xstartup = $vncUserDir . "/xstartup"; |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 58 | $defaultXStartup |
| 59 | = ("#!/bin/sh\n\n". |
DRC | 9324898 | 2009-03-26 18:14:38 +0000 | [diff] [blame] | 60 | "unset SESSION_MANAGER\n". |
Adam Tkac | c071e49 | 2009-05-20 09:01:24 +0000 | [diff] [blame] | 61 | "unset DBUS_SESSION_BUS_ADDRESS\n". |
DRC | 9324898 | 2009-03-26 18:14:38 +0000 | [diff] [blame] | 62 | "OS=`uname -s`\n". |
| 63 | "if [ \$OS = 'Linux' ]; then\n". |
| 64 | " case \"\$WINDOWMANAGER\" in\n". |
| 65 | " \*gnome\*)\n". |
| 66 | " if [ -e /etc/SuSE-release ]; then\n". |
| 67 | " PATH=\$PATH:/opt/gnome/bin\n". |
| 68 | " export PATH\n". |
| 69 | " fi\n". |
| 70 | " ;;\n". |
| 71 | " esac\n". |
| 72 | "fi\n". |
| 73 | "if [ -x /etc/X11/xinit/xinitrc ]; then\n". |
| 74 | " exec /etc/X11/xinit/xinitrc\n". |
| 75 | "fi\n". |
| 76 | "if [ -f /etc/X11/xinit/xinitrc ]; then\n". |
| 77 | " exec sh /etc/X11/xinit/xinitrc\n". |
| 78 | "fi\n". |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 79 | "[ -r \$HOME/.Xresources ] && xrdb \$HOME/.Xresources\n". |
| 80 | "xsetroot -solid grey\n". |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 81 | "xterm -geometry 80x24+10+10 -ls -title \"\$VNCDESKTOP Desktop\" &\n". |
| 82 | "twm &\n"); |
| 83 | |
graysky | ddff8d0 | 2015-10-19 08:24:14 -0400 | [diff] [blame] | 84 | $defaultConfig |
| 85 | = ("## Supported server options to pass to vncserver upon invocation can be listed\n". |
| 86 | "## in this file. See the following manpages for more: vncserver(1) Xvnc(1).\n". |
| 87 | "## Several common ones are shown below. Uncomment and modify to your liking.\n". |
| 88 | "##\n". |
| 89 | "# securitytypes=vncauth,tlsvnc\n". |
| 90 | "# desktop=sandbox\n". |
| 91 | "# geometry=2000x1200\n". |
| 92 | "# localhost\n". |
| 93 | "# alwaysshared\n"); |
| 94 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 95 | chop($host = `uname -n`); |
| 96 | |
DRC | 989dbd1 | 2009-04-22 13:23:17 +0000 | [diff] [blame] | 97 | if (-d "/etc/X11/fontpath.d") { |
| 98 | $fontPath = "catalogue:/etc/X11/fontpath.d"; |
| 99 | } |
DRC | 36546c1 | 2009-04-15 06:47:23 +0000 | [diff] [blame] | 100 | |
DRC | d6821bf | 2009-03-26 18:17:49 +0000 | [diff] [blame] | 101 | @fontpaths = ('/usr/share/X11/fonts', '/usr/share/fonts', '/usr/share/fonts/X11/'); |
| 102 | if (! -l "/usr/lib/X11") {push(@fontpaths, '/usr/lib/X11/fonts');} |
| 103 | if (! -l "/usr/X11") {push(@fontpaths, '/usr/X11/lib/X11/fonts');} |
| 104 | if (! -l "/usr/X11R6") {push(@fontpaths, '/usr/X11R6/lib/X11/fonts');} |
| 105 | push(@fontpaths, '/usr/share/fonts/default'); |
| 106 | |
| 107 | @fonttypes = ('misc', |
| 108 | '75dpi', |
| 109 | '100dpi', |
| 110 | 'Speedo', |
| 111 | 'Type1'); |
| 112 | |
| 113 | foreach $_fpath (@fontpaths) { |
| 114 | foreach $_ftype (@fonttypes) { |
| 115 | if (-f "$_fpath/$_ftype/fonts.dir") { |
| 116 | if (! -l "$_fpath/$_ftype") { |
DRC | 36546c1 | 2009-04-15 06:47:23 +0000 | [diff] [blame] | 117 | $defFontPath .= "$_fpath/$_ftype,"; |
DRC | d6821bf | 2009-03-26 18:17:49 +0000 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |
DRC | d28792b | 2010-01-11 20:53:00 +0000 | [diff] [blame] | 122 | |
DRC | 36546c1 | 2009-04-15 06:47:23 +0000 | [diff] [blame] | 123 | if ($defFontPath) { |
| 124 | if (substr($defFontPath, -1, 1) == ',') { |
| 125 | chop $defFontPath; |
DRC | d6821bf | 2009-03-26 18:17:49 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
DRC | d28792b | 2010-01-11 20:53:00 +0000 | [diff] [blame] | 129 | if ($fontPath eq "") { |
| 130 | $fontPath = $defFontPath; |
| 131 | } |
| 132 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 133 | # Check command line options |
| 134 | |
| 135 | &ParseOptions("-geometry",1,"-depth",1,"-pixelformat",1,"-name",1,"-kill",1, |
Llorenç Garcia Martinez | e76c2fb | 2015-10-30 11:07:40 +0100 | [diff] [blame] | 136 | "-help",0,"-h",0,"--help",0,"-fp",1,"-list",0,"-fg",0,"-autokill",0,"-noxstartup",0,"-xstartup",1); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 137 | |
| 138 | &Usage() if ($opt{'-help'} || $opt{'-h'} || $opt{'--help'}); |
| 139 | |
| 140 | &Kill() if ($opt{'-kill'}); |
| 141 | |
DRC | b9d8e76 | 2011-02-09 08:24:58 +0000 | [diff] [blame] | 142 | &List() if ($opt{'-list'}); |
| 143 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 144 | # Uncomment this line if you want default geometry, depth and pixelformat |
| 145 | # to match the current X display: |
| 146 | # &GetXDisplayDefaults(); |
| 147 | |
| 148 | if ($opt{'-geometry'}) { |
| 149 | $geometry = $opt{'-geometry'}; |
| 150 | } |
| 151 | if ($opt{'-depth'}) { |
| 152 | $depth = $opt{'-depth'}; |
| 153 | $pixelformat = ""; |
| 154 | } |
| 155 | if ($opt{'-pixelformat'}) { |
| 156 | $pixelformat = $opt{'-pixelformat'}; |
| 157 | } |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 158 | if ($opt{'-noxstartup'}) { |
| 159 | $skipxstartup = 1; |
| 160 | } |
Llorenç Garcia Martinez | e76c2fb | 2015-10-30 11:07:40 +0100 | [diff] [blame] | 161 | if ($opt{'-xstartup'}) { |
| 162 | $xstartup = $opt{'-xstartup'}; |
| 163 | } |
DRC | eed5d1f | 2009-03-26 19:16:19 +0000 | [diff] [blame] | 164 | if ($opt{'-fp'}) { |
| 165 | $fontPath = $opt{'-fp'}; |
DRC | 36546c1 | 2009-04-15 06:47:23 +0000 | [diff] [blame] | 166 | $fpArgSpecified = 1; |
DRC | eed5d1f | 2009-03-26 19:16:19 +0000 | [diff] [blame] | 167 | } |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 168 | |
| 169 | &CheckGeometryAndDepth(); |
| 170 | |
| 171 | |
| 172 | # Create the user's vnc directory if necessary. |
| 173 | |
| 174 | if (!(-e $vncUserDir)) { |
| 175 | if (!mkdir($vncUserDir,0755)) { |
| 176 | die "$prog: Could not create $vncUserDir.\n"; |
| 177 | } |
| 178 | } |
| 179 | |
Adam Tkac | f586b84 | 2011-04-27 11:20:18 +0000 | [diff] [blame] | 180 | # Check whether VNC authentication is enabled, and if so, prompt the user to |
| 181 | # create a VNC password if they don't already have one. |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 182 | |
Adam Tkac | f586b84 | 2011-04-27 11:20:18 +0000 | [diff] [blame] | 183 | $securityTypeArgSpecified = 0; |
| 184 | $vncAuthEnabled = 0; |
| 185 | $passwordArgSpecified = 0; |
| 186 | |
| 187 | for ($i = 0; $i < @ARGV; ++$i) { |
| 188 | # -SecurityTypes can be followed by a space or "=" |
| 189 | my @splitargs = split('=', $ARGV[$i]); |
| 190 | if (@splitargs <= 1 && $i < @ARGV - 1) { |
| 191 | push(@splitargs, $ARGV[$i + 1]); |
| 192 | } |
| 193 | if (lc(@splitargs[0]) eq "-securitytypes") { |
| 194 | if (@splitargs > 1) { |
| 195 | $securityTypeArgSpecified = 1; |
| 196 | } |
| 197 | foreach $arg2 (split(',', @splitargs[1])) { |
| 198 | if (lc($arg2) eq "vncauth" || lc($arg2) eq "tlsvnc" |
| 199 | || lc($arg2) eq "x509vnc") { |
| 200 | $vncAuthEnabled = 1; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | if ((lc(@splitargs[0]) eq "-password") |
| 205 | || (lc(@splitargs[0]) eq "-passwordfile" |
| 206 | || (lc(@splitargs[0]) eq "-rfbauth"))) { |
| 207 | $passwordArgSpecified = 1; |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
Adam Tkac | f586b84 | 2011-04-27 11:20:18 +0000 | [diff] [blame] | 211 | if ((!$securityTypeArgSpecified || $vncAuthEnabled) && !$passwordArgSpecified) { |
| 212 | ($z,$z,$mode) = stat("$vncUserDir/passwd"); |
| 213 | if (!(-e "$vncUserDir/passwd") || ($mode & 077)) { |
| 214 | warn "\nYou will require a password to access your desktops.\n\n"; |
| 215 | system($exedir."vncpasswd -q $vncUserDir/passwd"); |
| 216 | if (($? >> 8) != 0) { |
| 217 | exit 1; |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 222 | # Find display number. |
| 223 | |
| 224 | if ((@ARGV > 0) && ($ARGV[0] =~ /^:(\d+)$/)) { |
| 225 | $displayNumber = $1; |
| 226 | shift(@ARGV); |
| 227 | if (!&CheckDisplayNumber($displayNumber)) { |
| 228 | die "A VNC server is already running as :$displayNumber\n"; |
| 229 | } |
Adam Tkac | 39c9d99 | 2010-07-21 14:08:38 +0000 | [diff] [blame] | 230 | } elsif ((@ARGV > 0) && ($ARGV[0] !~ /^-/) && ($ARGV[0] !~ /^\+/)) { |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 231 | &Usage(); |
| 232 | } else { |
| 233 | $displayNumber = &GetDisplayNumber(); |
| 234 | } |
| 235 | |
| 236 | $vncPort = 5900 + $displayNumber; |
| 237 | |
| 238 | $desktopLog = "$vncUserDir/$host:$displayNumber.log"; |
| 239 | unlink($desktopLog); |
| 240 | |
Pierre Ossman | 5fe6070 | 2015-12-29 14:27:07 +0100 | [diff] [blame] | 241 | # Make an X server cookie and set up the Xauthority file |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 242 | |
Pierre Ossman | 5fe6070 | 2015-12-29 14:27:07 +0100 | [diff] [blame] | 243 | $cookie = `mcookie`; |
Adam Tkac | 6cbd9d1 | 2009-11-12 10:39:54 +0000 | [diff] [blame] | 244 | |
Pierre Ossman | cddd648 | 2015-12-29 14:30:32 +0100 | [diff] [blame] | 245 | open(XAUTH, "|xauth -f $xauthorityFile source -"); |
| 246 | print XAUTH "add $host:$displayNumber . $cookie\n"; |
| 247 | print XAUTH "add $host/unix:$displayNumber . $cookie\n"; |
| 248 | close(XAUTH); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 249 | |
| 250 | if ($opt{'-name'}) { |
| 251 | $desktopName = $opt{'-name'}; |
| 252 | } else { |
| 253 | $desktopName = "$host:$displayNumber ($ENV{USER})"; |
| 254 | } |
| 255 | |
| 256 | # Now start the X VNC Server |
| 257 | |
DRC | 190854c | 2009-03-26 18:13:00 +0000 | [diff] [blame] | 258 | $cmd = $exedir."Xvnc :$displayNumber"; |
graysky | ddff8d0 | 2015-10-19 08:24:14 -0400 | [diff] [blame] | 259 | |
| 260 | my %default_opts; |
| 261 | my %config; |
| 262 | |
| 263 | $default_opts{desktop} = "edString($desktopName); |
| 264 | $default_opts{httpd} = $vncJavaFiles if ($vncJavaFiles); |
| 265 | $default_opts{auth} = $xauthorityFile; |
| 266 | $default_opts{geometry} = $geometry if ($geometry); |
| 267 | $default_opts{depth} = $depth if ($depth); |
| 268 | $default_opts{pixelformat} = $pixelformat if ($pixelformat); |
| 269 | $default_opts{rfbwait} = 30000; |
| 270 | $default_opts{rfbauth} = "$vncUserDir/passwd"; |
| 271 | $default_opts{rfbport} = $vncPort; |
| 272 | $default_opts{fp} = $fontPath if ($fontPath); |
| 273 | $default_opts{pn} = ""; |
| 274 | |
| 275 | # if a user configuration file already exists |
| 276 | if(stat("$vncUserDir/config")) { |
| 277 | |
| 278 | # loads and parses configuration file |
| 279 | if(open(IN, "$vncUserDir/config")) { |
| 280 | while(<IN>) { |
| 281 | next if /^#/; |
| 282 | if(my ($k, $v) = /^\s*(\w+)\s*=\s*(.+)$/) { |
| 283 | $config{$k} = $v; |
| 284 | } elsif ($_ =~ m/^\s*(\S+)/) { |
| 285 | $config{$1} = $k; |
| 286 | } |
| 287 | } |
| 288 | close(IN); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | foreach my $k (sort keys %config) { |
| 293 | $cmd .= " -$k $config{$k}"; |
| 294 | # user's option takes precedence |
| 295 | delete $default_opts{$k}; |
| 296 | } |
| 297 | |
| 298 | foreach my $k (sort keys %default_opts) { |
| 299 | $cmd .= " -$k $default_opts{$k}"; |
| 300 | } |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 301 | |
DRC | d6821bf | 2009-03-26 18:17:49 +0000 | [diff] [blame] | 302 | # Add color database stuff here, e.g.: |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 303 | # |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 304 | # $cmd .= " -co /usr/lib/X11/rgb"; |
| 305 | # |
| 306 | |
| 307 | foreach $arg (@ARGV) { |
| 308 | $cmd .= " " . "edString($arg); |
| 309 | } |
| 310 | $cmd .= " >> " . "edString($desktopLog) . " 2>&1"; |
| 311 | |
| 312 | # Run $cmd and record the process ID. |
| 313 | |
| 314 | $pidFile = "$vncUserDir/$host:$displayNumber.pid"; |
| 315 | system("$cmd & echo \$! >$pidFile"); |
| 316 | |
| 317 | # Give Xvnc a chance to start up |
| 318 | |
| 319 | sleep(3); |
DRC | d28792b | 2010-01-11 20:53:00 +0000 | [diff] [blame] | 320 | if ($fontPath ne $defFontPath) { |
| 321 | unless (kill 0, `cat $pidFile`) { |
| 322 | if ($fpArgSpecified) { |
| 323 | warn "\nWARNING: The first attempt to start Xvnc failed, probably because the font\n"; |
| 324 | warn "path you specified using the -fp argument is incorrect. Attempting to\n"; |
| 325 | warn "determine an appropriate font path for this system and restart Xvnc using\n"; |
| 326 | warn "that font path ...\n"; |
| 327 | } else { |
| 328 | warn "\nWARNING: The first attempt to start Xvnc failed, possibly because the font\n"; |
| 329 | warn "catalog is not properly configured. Attempting to determine an appropriate\n"; |
| 330 | warn "font path for this system and restart Xvnc using that font path ...\n"; |
| 331 | } |
| 332 | $cmd =~ s@-fp [^ ]+@@; |
| 333 | $cmd .= " -fp $defFontPath" if ($defFontPath); |
| 334 | system("$cmd & echo \$! >$pidFile"); |
| 335 | sleep(3); |
DRC | 36546c1 | 2009-04-15 06:47:23 +0000 | [diff] [blame] | 336 | } |
DRC | d6821bf | 2009-03-26 18:17:49 +0000 | [diff] [blame] | 337 | } |
| 338 | unless (kill 0, `cat $pidFile`) { |
| 339 | warn "Could not start Xvnc.\n\n"; |
Michal Srb | e6e11f9 | 2015-10-02 02:28:26 +0300 | [diff] [blame] | 340 | unlink $pidFile; |
DRC | d6821bf | 2009-03-26 18:17:49 +0000 | [diff] [blame] | 341 | open(LOG, "<$desktopLog"); |
| 342 | while (<LOG>) { print; } |
| 343 | close(LOG); |
| 344 | die "\n"; |
| 345 | } |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 346 | |
| 347 | warn "\nNew '$desktopName' desktop is $host:$displayNumber\n\n"; |
| 348 | |
| 349 | # Create the user's xstartup script if necessary. |
| 350 | |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 351 | if (! $skipxstartup) { |
Llorenç Garcia Martinez | e76c2fb | 2015-10-30 11:07:40 +0100 | [diff] [blame] | 352 | if (!(-e "$xstartup")) { |
| 353 | warn "Creating default startup script $xstartup\n"; |
| 354 | open(XSTARTUP, ">$xstartup"); |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 355 | print XSTARTUP $defaultXStartup; |
| 356 | close(XSTARTUP); |
Llorenç Garcia Martinez | e76c2fb | 2015-10-30 11:07:40 +0100 | [diff] [blame] | 357 | chmod 0755, "$xstartup"; |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 358 | } |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 359 | } |
| 360 | |
graysky | ddff8d0 | 2015-10-19 08:24:14 -0400 | [diff] [blame] | 361 | # Create the user's config file if necessary. |
| 362 | |
| 363 | if (!(-e "$vncUserDir/config")) { |
| 364 | warn "Creating default config $vncUserDir/config\n"; |
| 365 | open(XSTARTUP, ">$vncUserDir/config"); |
| 366 | print XSTARTUP $defaultConfig; |
| 367 | close(XSTARTUP); |
| 368 | chmod 0644, "$vncUserDir/config"; |
| 369 | } |
| 370 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 371 | # Run the X startup script. |
| 372 | |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 373 | if (! $skipxstartup) { |
Llorenç Garcia Martinez | e76c2fb | 2015-10-30 11:07:40 +0100 | [diff] [blame] | 374 | warn "Starting applications specified in $xstartup\n"; |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 375 | } |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 376 | warn "Log file is $desktopLog\n\n"; |
| 377 | |
| 378 | # If the unix domain socket exists then use that (DISPLAY=:n) otherwise use |
| 379 | # TCP (DISPLAY=host:n) |
| 380 | |
| 381 | if (-e "/tmp/.X11-unix/X$displayNumber" || |
| 382 | -e "/usr/spool/sockets/X11/$displayNumber") |
| 383 | { |
| 384 | $ENV{DISPLAY}= ":$displayNumber"; |
| 385 | } else { |
| 386 | $ENV{DISPLAY}= "$host:$displayNumber"; |
| 387 | } |
| 388 | $ENV{VNCDESKTOP}= $desktopName; |
| 389 | |
Pierre Ossman | a5b37c0 | 2015-07-30 11:04:02 +0200 | [diff] [blame] | 390 | system($exedir."vncconfig -nowin >> " . "edString($desktopLog) . " 2>&1 &"); |
DRC | f6b5840 | 2011-10-05 21:28:03 +0000 | [diff] [blame] | 391 | |
DRC | 8fb1191 | 2011-03-03 10:42:14 +0000 | [diff] [blame] | 392 | if ($opt{'-fg'}) { |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 393 | if (! $skipxstartup) { |
Llorenç Garcia Martinez | e76c2fb | 2015-10-30 11:07:40 +0100 | [diff] [blame] | 394 | system("$xstartup >> " . "edString($desktopLog) . " 2>&1"); |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 395 | } |
Adam Tkac | 38ba8cf | 2011-04-27 11:28:09 +0000 | [diff] [blame] | 396 | if (kill 0, `cat $pidFile`) { |
| 397 | $opt{'-kill'} = ':'.$displayNumber; |
| 398 | &Kill(); |
| 399 | } |
DRC | 8fb1191 | 2011-03-03 10:42:14 +0000 | [diff] [blame] | 400 | } else { |
Adam Tkac | 38ba8cf | 2011-04-27 11:28:09 +0000 | [diff] [blame] | 401 | if ($opt{'-autokill'}) { |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 402 | if (! $skipxstartup) { |
Llorenç Garcia Martinez | e76c2fb | 2015-10-30 11:07:40 +0100 | [diff] [blame] | 403 | system("($xstartup; $0 -kill :$displayNumber) >> " |
| 404 | . "edString($desktopLog) . " 2>&1 &"); |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 405 | } |
Adam Tkac | 38ba8cf | 2011-04-27 11:28:09 +0000 | [diff] [blame] | 406 | } else { |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 407 | if (! $skipxstartup) { |
Llorenç Garcia Martinez | e76c2fb | 2015-10-30 11:07:40 +0100 | [diff] [blame] | 408 | system("$xstartup >> " . "edString($desktopLog) |
| 409 | . " 2>&1 &"); |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 410 | } |
Adam Tkac | 38ba8cf | 2011-04-27 11:28:09 +0000 | [diff] [blame] | 411 | } |
DRC | 8fb1191 | 2011-03-03 10:42:14 +0000 | [diff] [blame] | 412 | } |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 413 | |
| 414 | exit; |
| 415 | |
| 416 | |
| 417 | ############################################################################### |
| 418 | # |
| 419 | # CheckGeometryAndDepth simply makes sure that the geometry and depth values |
| 420 | # are sensible. |
| 421 | # |
| 422 | |
| 423 | sub CheckGeometryAndDepth |
| 424 | { |
| 425 | if ($geometry =~ /^(\d+)x(\d+)$/) { |
| 426 | $width = $1; $height = $2; |
| 427 | |
| 428 | if (($width<1) || ($height<1)) { |
| 429 | die "$prog: geometry $geometry is invalid\n"; |
| 430 | } |
| 431 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 432 | $geometry = "${width}x$height"; |
| 433 | } else { |
| 434 | die "$prog: geometry $geometry is invalid\n"; |
| 435 | } |
| 436 | |
DRC | e5b4f75 | 2009-03-26 18:23:29 +0000 | [diff] [blame] | 437 | if ($depth && (($depth < 8) || ($depth > 32))) { |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 438 | die "Depth must be between 8 and 32\n"; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | |
| 443 | # |
| 444 | # GetDisplayNumber gets the lowest available display number. A display number |
| 445 | # n is taken if something is listening on the VNC server port (5900+n) or the |
| 446 | # X server port (6000+n). |
| 447 | # |
| 448 | |
| 449 | sub GetDisplayNumber |
| 450 | { |
| 451 | foreach $n (1..99) { |
| 452 | if (&CheckDisplayNumber($n)) { |
| 453 | return $n+0; # Bruce Mah's workaround for bug in perl 5.005_02 |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | die "$prog: no free display number on $host.\n"; |
| 458 | } |
| 459 | |
| 460 | |
| 461 | # |
| 462 | # CheckDisplayNumber checks if the given display number is available. A |
| 463 | # display number n is taken if something is listening on the VNC server port |
| 464 | # (5900+n) or the X server port (6000+n). |
| 465 | # |
| 466 | |
| 467 | sub CheckDisplayNumber |
| 468 | { |
| 469 | local ($n) = @_; |
| 470 | |
| 471 | socket(S, $AF_INET, $SOCK_STREAM, 0) || die "$prog: socket failed: $!\n"; |
| 472 | eval 'setsockopt(S, &SOL_SOCKET, &SO_REUSEADDR, pack("l", 1))'; |
| 473 | if (!bind(S, pack('S n x12', $AF_INET, 6000 + $n))) { |
| 474 | close(S); |
| 475 | return 0; |
| 476 | } |
| 477 | close(S); |
| 478 | |
| 479 | socket(S, $AF_INET, $SOCK_STREAM, 0) || die "$prog: socket failed: $!\n"; |
| 480 | eval 'setsockopt(S, &SOL_SOCKET, &SO_REUSEADDR, pack("l", 1))'; |
| 481 | if (!bind(S, pack('S n x12', $AF_INET, 5900 + $n))) { |
| 482 | close(S); |
| 483 | return 0; |
| 484 | } |
| 485 | close(S); |
| 486 | |
| 487 | if (-e "/tmp/.X$n-lock") { |
| 488 | warn "\nWarning: $host:$n is taken because of /tmp/.X$n-lock\n"; |
| 489 | warn "Remove this file if there is no X server $host:$n\n"; |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | if (-e "/tmp/.X11-unix/X$n") { |
| 494 | warn "\nWarning: $host:$n is taken because of /tmp/.X11-unix/X$n\n"; |
| 495 | warn "Remove this file if there is no X server $host:$n\n"; |
| 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | if (-e "/usr/spool/sockets/X11/$n") { |
| 500 | warn("\nWarning: $host:$n is taken because of ". |
| 501 | "/usr/spool/sockets/X11/$n\n"); |
| 502 | warn "Remove this file if there is no X server $host:$n\n"; |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | return 1; |
| 507 | } |
| 508 | |
| 509 | |
| 510 | # |
| 511 | # GetXDisplayDefaults uses xdpyinfo to find out the geometry, depth and pixel |
| 512 | # format of the current X display being used. If successful, it sets the |
| 513 | # options as appropriate so that the X VNC server will use the same settings |
| 514 | # (minus an allowance for window manager decorations on the geometry). Using |
| 515 | # the same depth and pixel format means that the VNC server won't have to |
| 516 | # translate pixels when the desktop is being viewed on this X display (for |
| 517 | # TrueColor displays anyway). |
| 518 | # |
| 519 | |
| 520 | sub GetXDisplayDefaults |
| 521 | { |
| 522 | local (@lines, @matchlines, $width, $height, $defaultVisualId, $i, |
| 523 | $red, $green, $blue); |
| 524 | |
| 525 | $wmDecorationWidth = 4; # a guess at typical size for window manager |
| 526 | $wmDecorationHeight = 24; # decoration size |
| 527 | |
| 528 | return if (!defined($ENV{DISPLAY})); |
| 529 | |
| 530 | @lines = `xdpyinfo 2>/dev/null`; |
| 531 | |
| 532 | return if ($? != 0); |
| 533 | |
| 534 | @matchlines = grep(/dimensions/, @lines); |
| 535 | if (@matchlines) { |
| 536 | ($width, $height) = ($matchlines[0] =~ /(\d+)x(\d+) pixels/); |
| 537 | |
| 538 | $width -= $wmDecorationWidth; |
| 539 | $height -= $wmDecorationHeight; |
| 540 | |
| 541 | $geometry = "${width}x$height"; |
| 542 | } |
| 543 | |
| 544 | @matchlines = grep(/default visual id/, @lines); |
| 545 | if (@matchlines) { |
| 546 | ($defaultVisualId) = ($matchlines[0] =~ /id:\s+(\S+)/); |
| 547 | |
| 548 | for ($i = 0; $i < @lines; $i++) { |
| 549 | if ($lines[$i] =~ /^\s*visual id:\s+$defaultVisualId$/) { |
| 550 | if (($lines[$i+1] !~ /TrueColor/) || |
| 551 | ($lines[$i+2] !~ /depth/) || |
| 552 | ($lines[$i+4] !~ /red, green, blue masks/)) |
| 553 | { |
| 554 | return; |
| 555 | } |
| 556 | last; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | return if ($i >= @lines); |
| 561 | |
| 562 | ($depth) = ($lines[$i+2] =~ /depth:\s+(\d+)/); |
| 563 | ($red,$green,$blue) |
| 564 | = ($lines[$i+4] |
| 565 | =~ /masks:\s+0x([0-9a-f]+), 0x([0-9a-f]+), 0x([0-9a-f]+)/); |
| 566 | |
| 567 | $red = hex($red); |
| 568 | $green = hex($green); |
| 569 | $blue = hex($blue); |
| 570 | |
| 571 | if ($red > $blue) { |
| 572 | $red = int(log($red) / log(2)) - int(log($green) / log(2)); |
| 573 | $green = int(log($green) / log(2)) - int(log($blue) / log(2)); |
| 574 | $blue = int(log($blue) / log(2)) + 1; |
| 575 | $pixelformat = "rgb$red$green$blue"; |
| 576 | } else { |
| 577 | $blue = int(log($blue) / log(2)) - int(log($green) / log(2)); |
| 578 | $green = int(log($green) / log(2)) - int(log($red) / log(2)); |
| 579 | $red = int(log($red) / log(2)) + 1; |
| 580 | $pixelformat = "bgr$blue$green$red"; |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | |
| 586 | # |
| 587 | # quotedString returns a string which yields the original string when parsed |
| 588 | # by a shell. |
| 589 | # |
| 590 | |
| 591 | sub quotedString |
| 592 | { |
| 593 | local ($in) = @_; |
| 594 | |
| 595 | $in =~ s/\'/\'\"\'\"\'/g; |
| 596 | |
| 597 | return "'$in'"; |
| 598 | } |
| 599 | |
| 600 | |
| 601 | # |
| 602 | # removeSlashes turns slashes into underscores for use as a file name. |
| 603 | # |
| 604 | |
| 605 | sub removeSlashes |
| 606 | { |
| 607 | local ($in) = @_; |
| 608 | |
| 609 | $in =~ s|/|_|g; |
| 610 | |
| 611 | return "$in"; |
| 612 | } |
| 613 | |
| 614 | |
| 615 | # |
| 616 | # Usage |
| 617 | # |
| 618 | |
| 619 | sub Usage |
| 620 | { |
| 621 | die("\nusage: $prog [:<number>] [-name <desktop-name>] [-depth <depth>]\n". |
| 622 | " [-geometry <width>x<height>]\n". |
| 623 | " [-pixelformat rgbNNN|bgrNNN]\n". |
DRC | eed5d1f | 2009-03-26 19:16:19 +0000 | [diff] [blame] | 624 | " [-fp <font-path>]\n". |
DRC | 8fb1191 | 2011-03-03 10:42:14 +0000 | [diff] [blame] | 625 | " [-fg]\n". |
Adam Tkac | 38ba8cf | 2011-04-27 11:28:09 +0000 | [diff] [blame] | 626 | " [-autokill]\n". |
Llorenç Garcia Martinez | 861cb06 | 2015-10-23 13:37:42 +0200 | [diff] [blame] | 627 | " [-noxstartup]\n". |
Llorenç Garcia Martinez | e76c2fb | 2015-10-30 11:07:40 +0100 | [diff] [blame] | 628 | " [-xstartup <file>]\n". |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 629 | " <Xvnc-options>...\n\n". |
DRC | b9d8e76 | 2011-02-09 08:24:58 +0000 | [diff] [blame] | 630 | " $prog -kill <X-display>\n\n". |
| 631 | " $prog -list\n\n"); |
| 632 | } |
| 633 | |
| 634 | |
| 635 | # |
| 636 | # List |
| 637 | # |
| 638 | |
| 639 | sub List |
| 640 | { |
| 641 | opendir(dir, $vncUserDir); |
| 642 | my @filelist = readdir(dir); |
| 643 | closedir(dir); |
DRC | 075d9fa | 2011-02-10 04:19:46 +0000 | [diff] [blame] | 644 | print "\nTigerVNC server sessions:\n\n"; |
DRC | b9d8e76 | 2011-02-09 08:24:58 +0000 | [diff] [blame] | 645 | print "X DISPLAY #\tPROCESS ID\n"; |
| 646 | foreach my $file (@filelist) { |
| 647 | if ($file =~ /$host:(\d+)$\.pid/) { |
Michal Srb | e6e11f9 | 2015-10-02 02:28:26 +0300 | [diff] [blame] | 648 | chop($tmp_pid = `cat $vncUserDir/$file`); |
| 649 | if (kill 0, $tmp_pid) { |
| 650 | print ":".$1."\t\t".`cat $vncUserDir/$file`; |
| 651 | } else { |
| 652 | unlink ($vncUserDir . "/" . $file); |
| 653 | } |
DRC | b9d8e76 | 2011-02-09 08:24:58 +0000 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | exit 1; |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | |
| 660 | # |
| 661 | # Kill |
| 662 | # |
| 663 | |
| 664 | sub Kill |
| 665 | { |
| 666 | $opt{'-kill'} =~ s/(:\d+)\.\d+$/$1/; # e.g. turn :1.0 into :1 |
| 667 | |
| 668 | if ($opt{'-kill'} =~ /^:\d+$/) { |
| 669 | $pidFile = "$vncUserDir/$host$opt{'-kill'}.pid"; |
| 670 | } else { |
| 671 | if ($opt{'-kill'} !~ /^$host:/) { |
| 672 | die "\nCan't tell if $opt{'-kill'} is on $host\n". |
| 673 | "Use -kill :<number> instead\n\n"; |
| 674 | } |
| 675 | $pidFile = "$vncUserDir/$opt{'-kill'}.pid"; |
| 676 | } |
| 677 | |
| 678 | if (! -r $pidFile) { |
| 679 | die "\nCan't find file $pidFile\n". |
| 680 | "You'll have to kill the Xvnc process manually\n\n"; |
| 681 | } |
| 682 | |
| 683 | $SIG{'HUP'} = 'IGNORE'; |
| 684 | chop($pid = `cat $pidFile`); |
| 685 | warn "Killing Xvnc process ID $pid\n"; |
DRC | b9d8e76 | 2011-02-09 08:24:58 +0000 | [diff] [blame] | 686 | |
| 687 | if (kill 0, $pid) { |
| 688 | system("kill $pid"); |
| 689 | sleep(1); |
| 690 | if (kill 0, $pid) { |
| 691 | print "Xvnc seems to be deadlocked. Kill the process manually and then re-run\n"; |
| 692 | print " ".$0." -kill ".$opt{'-kill'}."\n"; |
| 693 | print "to clean up the socket files.\n"; |
| 694 | exit |
| 695 | } |
| 696 | |
| 697 | } else { |
| 698 | warn "Xvnc process ID $pid already killed\n"; |
| 699 | $opt{'-kill'} =~ s/://; |
| 700 | |
| 701 | if (-e "/tmp/.X11-unix/X$opt{'-kill'}") { |
| 702 | print "Xvnc did not appear to shut down cleanly."; |
| 703 | print " Removing /tmp/.X11-unix/X$opt{'-kill'}\n"; |
| 704 | unlink "/tmp/.X11-unix/X$opt{'-kill'}"; |
| 705 | } |
| 706 | if (-e "/tmp/.X$opt{'-kill'}-lock") { |
| 707 | print "Xvnc did not appear to shut down cleanly."; |
| 708 | print " Removing /tmp/.X$opt{'-kill'}-lock\n"; |
| 709 | unlink "/tmp/.X$opt{'-kill'}-lock"; |
| 710 | } |
| 711 | } |
| 712 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 713 | unlink $pidFile; |
| 714 | exit; |
| 715 | } |
| 716 | |
| 717 | |
| 718 | # |
| 719 | # ParseOptions takes a list of possible options and a boolean indicating |
| 720 | # whether the option has a value following, and sets up an associative array |
| 721 | # %opt of the values of the options given on the command line. It removes all |
| 722 | # the arguments it uses from @ARGV and returns them in @optArgs. |
| 723 | # |
| 724 | |
| 725 | sub ParseOptions |
| 726 | { |
| 727 | local (@optval) = @_; |
| 728 | local ($opt, @opts, %valFollows, @newargs); |
| 729 | |
| 730 | while (@optval) { |
| 731 | $opt = shift(@optval); |
| 732 | push(@opts,$opt); |
| 733 | $valFollows{$opt} = shift(@optval); |
| 734 | } |
| 735 | |
| 736 | @optArgs = (); |
| 737 | %opt = (); |
| 738 | |
| 739 | arg: while (defined($arg = shift(@ARGV))) { |
| 740 | foreach $opt (@opts) { |
| 741 | if ($arg eq $opt) { |
| 742 | push(@optArgs, $arg); |
| 743 | if ($valFollows{$opt}) { |
| 744 | if (@ARGV == 0) { |
| 745 | &Usage(); |
| 746 | } |
| 747 | $opt{$opt} = shift(@ARGV); |
| 748 | push(@optArgs, $opt{$opt}); |
| 749 | } else { |
| 750 | $opt{$opt} = 1; |
| 751 | } |
| 752 | next arg; |
| 753 | } |
| 754 | } |
| 755 | push(@newargs,$arg); |
| 756 | } |
| 757 | |
| 758 | @ARGV = @newargs; |
| 759 | } |
| 760 | |
| 761 | |
| 762 | # |
| 763 | # Routine to make sure we're operating in a sane environment. |
| 764 | # |
| 765 | |
| 766 | sub SanityCheck |
| 767 | { |
| 768 | local ($cmd); |
| 769 | |
| 770 | # |
| 771 | # Get the program name |
| 772 | # |
| 773 | |
| 774 | ($prog) = ($0 =~ m|([^/]+)$|); |
| 775 | |
| 776 | # |
| 777 | # Check we have all the commands we'll need on the path. |
| 778 | # |
| 779 | |
| 780 | cmd: |
Pierre Ossman | 5fe6070 | 2015-12-29 14:27:07 +0100 | [diff] [blame] | 781 | foreach $cmd ("uname","mcookie","xauth") { |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 782 | for (split(/:/,$ENV{PATH})) { |
| 783 | if (-x "$_/$cmd") { |
| 784 | next cmd; |
| 785 | } |
| 786 | } |
| 787 | die "$prog: couldn't find \"$cmd\" on your PATH.\n"; |
| 788 | } |
DRC | 190854c | 2009-03-26 18:13:00 +0000 | [diff] [blame] | 789 | |
| 790 | if($exedir eq "") { |
| 791 | cmd2: |
| 792 | foreach $cmd ("Xvnc","vncpasswd") { |
| 793 | for (split(/:/,$ENV{PATH})) { |
| 794 | if (-x "$_/$cmd") { |
| 795 | $vncClasses = "$_/../vnc/classes"; |
| 796 | next cmd2; |
| 797 | } |
| 798 | } |
| 799 | die "$prog: couldn't find \"$cmd\" on your PATH.\n"; |
| 800 | } |
| 801 | } |
| 802 | else { |
| 803 | cmd3: |
| 804 | foreach $cmd ($exedir."Xvnc",$exedir."vncpasswd") { |
| 805 | for (split(/:/,$ENV{PATH})) { |
| 806 | if (-x "$cmd") { |
| 807 | $vncClasses = $exedir."../vnc/classes"; |
| 808 | next cmd3; |
| 809 | } |
| 810 | } |
| 811 | die "$prog: couldn't find \"$cmd\".\n"; |
| 812 | } |
| 813 | } |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 814 | |
| 815 | # |
| 816 | # Check the HOME environment variable is set |
| 817 | # |
| 818 | |
| 819 | if (!defined($ENV{HOME})) { |
| 820 | die "$prog: The HOME environment variable is not set.\n"; |
| 821 | } |
DRC | 190854c | 2009-03-26 18:13:00 +0000 | [diff] [blame] | 822 | # chdir($ENV{HOME}); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 823 | |
| 824 | # |
| 825 | # Find socket constants. 'use Socket' is a perl5-ism, so we wrap it in an |
| 826 | # eval, and if it fails we try 'require "sys/socket.ph"'. If this fails, |
| 827 | # we just guess at the values. If you find perl moaning here, just |
| 828 | # hard-code the values of AF_INET and SOCK_STREAM. You can find these out |
| 829 | # for your platform by looking in /usr/include/sys/socket.h and related |
| 830 | # files. |
| 831 | # |
| 832 | |
| 833 | chop($os = `uname`); |
| 834 | chop($osrev = `uname -r`); |
| 835 | |
| 836 | eval 'use Socket'; |
| 837 | if ($@) { |
| 838 | eval 'require "sys/socket.ph"'; |
| 839 | if ($@) { |
| 840 | if (($os eq "SunOS") && ($osrev !~ /^4/)) { |
| 841 | $AF_INET = 2; |
| 842 | $SOCK_STREAM = 2; |
| 843 | } else { |
| 844 | $AF_INET = 2; |
| 845 | $SOCK_STREAM = 1; |
| 846 | } |
| 847 | } else { |
| 848 | $AF_INET = &AF_INET; |
| 849 | $SOCK_STREAM = &SOCK_STREAM; |
| 850 | } |
| 851 | } else { |
| 852 | $AF_INET = &AF_INET; |
| 853 | $SOCK_STREAM = &SOCK_STREAM; |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 854 | } |
| 855 | } |