Fri Oct 1 11:42:23 2021 UTC ()
tigervnc: Avoid hardcoding X11BASE


(nia)
diff -r1.43 -r1.44 pkgsrc/net/tigervnc/Makefile
diff -r1.2 -r1.3 pkgsrc/net/tigervnc/files/vncserver.pl

cvs diff -r1.43 -r1.44 pkgsrc/net/tigervnc/Makefile (switch to unified diff)

--- pkgsrc/net/tigervnc/Makefile 2021/09/30 21:38:23 1.43
+++ pkgsrc/net/tigervnc/Makefile 2021/10/01 11:42:23 1.44
@@ -1,142 +1,143 @@ @@ -1,142 +1,143 @@
1# $NetBSD: Makefile,v 1.43 2021/09/30 21:38:23 wiz Exp $ 1# $NetBSD: Makefile,v 1.44 2021/10/01 11:42:23 nia Exp $
2 2
3DISTNAME= tigervnc-1.11.0 3DISTNAME= tigervnc-1.11.0
4PKGNAME= ${DISTNAME}.1.20.11 4PKGNAME= ${DISTNAME}.1.20.11
5PKGREVISION= 5 5PKGREVISION= 6
6CATEGORIES= net 6CATEGORIES= net
7MASTER_SITES= ${MASTER_SITE_GITHUB:=TigerVNC/} 7MASTER_SITES= ${MASTER_SITE_GITHUB:=TigerVNC/}
8GITHUB_TAG= v1.11.0 8GITHUB_TAG= v1.11.0
9XORG_SERVER_FILE= xorg-server-1.20.11 9XORG_SERVER_FILE= xorg-server-1.20.11
10SITES.${XORG_SERVER_FILE}.tar.bz2= ${MASTER_SITE_XORG:=xserver/} 10SITES.${XORG_SERVER_FILE}.tar.bz2= ${MASTER_SITE_XORG:=xserver/}
11DISTFILES= ${DISTNAME}${EXTRACT_SUFX} ${XORG_SERVER_FILE}.tar.bz2 11DISTFILES= ${DISTNAME}${EXTRACT_SUFX} ${XORG_SERVER_FILE}.tar.bz2
12 12
13MAINTAINER= pkgsrc-users@NetBSD.org 13MAINTAINER= pkgsrc-users@NetBSD.org
14HOMEPAGE= https://tigervnc.org/ 14HOMEPAGE= https://tigervnc.org/
15COMMENT= High-performance, platform-neutral VNC client/server 15COMMENT= High-performance, platform-neutral VNC client/server
16LICENSE= gnu-gpl-v2 16LICENSE= gnu-gpl-v2
17 17
18BUILD_DEPENDS+= xorg-util-macros-[0-9]*:../../devel/xorg-util-macros 18BUILD_DEPENDS+= xorg-util-macros-[0-9]*:../../devel/xorg-util-macros
19BUILD_DEPENDS+= font-util-[0-9]*:../../fonts/font-util 19BUILD_DEPENDS+= font-util-[0-9]*:../../fonts/font-util
20BUILD_DEPENDS+= tradcpp-[0-9]*:../../devel/tradcpp 20BUILD_DEPENDS+= tradcpp-[0-9]*:../../devel/tradcpp
21 21
22DEPENDS+= mcookie-[0-9]*:../../x11/mcookie 22DEPENDS+= mcookie-[0-9]*:../../x11/mcookie
23DEPENDS+= xkeyboard-config-[0-9]*:../../x11/xkeyboard-config 23DEPENDS+= xkeyboard-config-[0-9]*:../../x11/xkeyboard-config
24 24
25REPLACE_BASH+= unix/vncserver/vncsession-start.in 25REPLACE_BASH+= unix/vncserver/vncsession-start.in
26REPLACE_PERL+= unix/vncserver/vncserver.in 26REPLACE_PERL+= unix/vncserver/vncserver.in
27 27
28WRKSRC= ${WRKDIR}/${DISTNAME} 28WRKSRC= ${WRKDIR}/${DISTNAME}
29 29
30USE_CMAKE= yes 30USE_CMAKE= yes
31USE_LIBTOOL= yes 31USE_LIBTOOL= yes
32USE_LANGUAGES= c c++ 32USE_LANGUAGES= c c++
33USE_TOOLS+= intltool msgfmt msgmerge patch perl:run autoconf automake autoreconf pkg-config gmake bash:run 33USE_TOOLS+= intltool msgfmt msgmerge patch perl:run autoconf automake autoreconf pkg-config gmake bash:run
34BUILD_DIRS= . unix/xserver 34BUILD_DIRS= . unix/xserver
35INSTALL_DIRS= . unix/xserver/hw/vnc 35INSTALL_DIRS= . unix/xserver/hw/vnc
36 36
37CMAKE_ARGS+= CMAKE_INSTALL_SYSCONFDIR=${PKG_SYSCONFDIR} 37CMAKE_ARGS+= CMAKE_INSTALL_SYSCONFDIR=${PKG_SYSCONFDIR}
38# for reallocarray() 38# for reallocarray()
39CPPFLAGS.NetBSD+= -D_OPENBSD_SOURCE 39CPPFLAGS.NetBSD+= -D_OPENBSD_SOURCE
40 40
41LDFLAGS+= ${BUILDLINK_LDADD.gettext} 41LDFLAGS+= ${BUILDLINK_LDADD.gettext}
42 42
43CONFIGURE_ENV+= ac_cv_path_RAWCPP="${PREFIX}/bin/tradcpp -Uunix" 43CONFIGURE_ENV+= ac_cv_path_RAWCPP="${PREFIX}/bin/tradcpp -Uunix"
44OVERRIDE_GNU_CONFIG_SCRIPTS= yes 44OVERRIDE_GNU_CONFIG_SCRIPTS= yes
45LIBTOOL_OVERRIDE= unix/xserver/libtool 45LIBTOOL_OVERRIDE= unix/xserver/libtool
46 46
47SUBST_CLASSES+= hpath 47SUBST_CLASSES+= hpath
48SUBST_STAGE.hpath= pre-configure 48SUBST_STAGE.hpath= pre-configure
49SUBST_MESSAGE.hpath= fixing hardcoded paths 49SUBST_MESSAGE.hpath= fixing hardcoded paths
50SUBST_FILES.hpath= unix/vncserver/vncserver.in 50SUBST_FILES.hpath= unix/vncserver/vncserver.in
 51SUBST_FILES.hpath= vncserver.pl
51SUBST_SED.hpath+= -e 's|/usr/local/vnc/classes|${PREFIX}/share/vnc/classes|g' 52SUBST_SED.hpath+= -e 's|/usr/local/vnc/classes|${PREFIX}/share/vnc/classes|g'
52SUBST_VARS.hpath+= PREFIX X11BASE 53SUBST_VARS.hpath+= PREFIX X11BASE
53 54
54REPLACE_PERL+= unix/vncserver 55REPLACE_PERL+= unix/vncserver
55REPLACE_PERL+= vncserver.pl 56REPLACE_PERL+= vncserver.pl
56 57
57post-extract: 58post-extract:
58 cd ${WRKDIR} && ${EXTRACTOR} ${_DISTDIR}/${XORG_SERVER_FILE}.tar.bz2 59 cd ${WRKDIR} && ${EXTRACTOR} ${_DISTDIR}/${XORG_SERVER_FILE}.tar.bz2
59 cp -r ${WRKDIR}/${XORG_SERVER_FILE}/* ${WRKSRC}/unix/xserver 60 cp -r ${WRKDIR}/${XORG_SERVER_FILE}/* ${WRKSRC}/unix/xserver
60 cp ${FILESDIR}/vncserver.pl ${WRKSRC} 61 cp ${FILESDIR}/vncserver.pl ${WRKSRC}
61 62
62post-patch: 63post-patch:
63 cd ${WRKSRC}/unix/xserver && ${PATCH} --batch -p1 <../xserver120.patch 64 cd ${WRKSRC}/unix/xserver && ${PATCH} --batch -p1 <../xserver120.patch
64 65
65# suggested by BUILDING.txt: 66# suggested by BUILDING.txt:
66#./configure --with-pic --without-dtrace --disable-static --disable-dri \ 67#./configure --with-pic --without-dtrace --disable-static --disable-dri \
67# --disable-xinerama --disable-xvfb --disable-xnest --disable-xorg \ 68# --disable-xinerama --disable-xvfb --disable-xnest --disable-xorg \
68# --disable-dmx --disable-xwin --disable-xephyr --disable-kdrive \ 69# --disable-dmx --disable-xwin --disable-xephyr --disable-kdrive \
69# --disable-config-dbus --disable-config-hal --disable-config-udev \ 70# --disable-config-dbus --disable-config-hal --disable-config-udev \
70# --disable-dri2 --enable-install-libxf86config --enable-glx \ 71# --disable-dri2 --enable-install-libxf86config --enable-glx \
71# --with-default-font-path="catalogue:/etc/X11/fontpath.d,built-ins" \ 72# --with-default-font-path="catalogue:/etc/X11/fontpath.d,built-ins" \
72# --with-fontdir=/usr/share/X11/fonts \ 73# --with-fontdir=/usr/share/X11/fonts \
73# --with-xkb-path=/usr/share/X11/xkb \ 74# --with-xkb-path=/usr/share/X11/xkb \
74# --with-xkb-output=/var/lib/xkb \ 75# --with-xkb-output=/var/lib/xkb \
75# --with-xkb-bin-directory=/usr/bin \ 76# --with-xkb-bin-directory=/usr/bin \
76# --with-serverconfig-path=/usr/lib[64]/xorg \ 77# --with-serverconfig-path=/usr/lib[64]/xorg \
77# --with-dri-driver-path=/usr/lib[64]/dri \ 78# --with-dri-driver-path=/usr/lib[64]/dri \
78# {additional configure options} 79# {additional configure options}
79 80
80XORG_CONFIGURE_ARGS+= --prefix=${PREFIX} --mandir=${PREFIX}/${PKGMANDIR} 81XORG_CONFIGURE_ARGS+= --prefix=${PREFIX} --mandir=${PREFIX}/${PKGMANDIR}
81XORG_CONFIGURE_ARGS+= --disable-xwayland --disable-kdrive --disable-xephyr 82XORG_CONFIGURE_ARGS+= --disable-xwayland --disable-kdrive --disable-xephyr
82XORG_CONFIGURE_ARGS+= --disable-static --disable-xinerama --without-dtrace 83XORG_CONFIGURE_ARGS+= --disable-static --disable-xinerama --without-dtrace
83XORG_CONFIGURE_ARGS+= --disable-xorg --disable-xnest --disable-xvfb --disable-dmx 84XORG_CONFIGURE_ARGS+= --disable-xorg --disable-xnest --disable-xvfb --disable-dmx
84XORG_CONFIGURE_ARGS+= --disable-config-hal --disable-config-udev --with-pic 85XORG_CONFIGURE_ARGS+= --disable-config-hal --disable-config-udev --with-pic
85XORG_CONFIGURE_ARGS+= --disable-unit-tests --disable-devel-docs --disable-selective-werror 86XORG_CONFIGURE_ARGS+= --disable-unit-tests --disable-devel-docs --disable-selective-werror
86XORG_CONFIGURE_ARGS+= --disable-dri --enable-dri2 --disable-dri3 --enable-glx --enable-glx-tls 87XORG_CONFIGURE_ARGS+= --disable-dri --enable-dri2 --disable-dri3 --enable-glx --enable-glx-tls
87 88
88EGDIR= share/examples/tigervnc 89EGDIR= share/examples/tigervnc
89INSTALLATION_DIRS+= ${EGDIR} 90INSTALLATION_DIRS+= ${EGDIR}
90MAKE_DIRS+= ${PKG_SYSCONFDIR}/pam.d 91MAKE_DIRS+= ${PKG_SYSCONFDIR}/pam.d
91MAKE_DIRS+= ${PKG_SYSCONFDIR}/tigervnc 92MAKE_DIRS+= ${PKG_SYSCONFDIR}/tigervnc
92CONF_FILES+= ${EGDIR}/tigervnc ${PKG_SYSCONFDIR}/pam.d/tigervnc 93CONF_FILES+= ${EGDIR}/tigervnc ${PKG_SYSCONFDIR}/pam.d/tigervnc
93CONF_FILES+= ${EGDIR}/vncserver-config-defaults ${PKG_SYSCONFDIR}/tigervnc/vncserver-config-defaults 94CONF_FILES+= ${EGDIR}/vncserver-config-defaults ${PKG_SYSCONFDIR}/tigervnc/vncserver-config-defaults
94CONF_FILES+= ${EGDIR}/vncserver-config-mandatory ${PKG_SYSCONFDIR}/tigervnc/vncserver-config-mandatory 95CONF_FILES+= ${EGDIR}/vncserver-config-mandatory ${PKG_SYSCONFDIR}/tigervnc/vncserver-config-mandatory
95CONF_FILES+= ${EGDIR}/vncserver.users ${PKG_SYSCONFDIR}/tigervnc/vncserver.users 96CONF_FILES+= ${EGDIR}/vncserver.users ${PKG_SYSCONFDIR}/tigervnc/vncserver.users
96 97
97post-install: 98post-install:
98 ${INSTALL_SCRIPT} ${WRKSRC}/vncserver.pl ${DESTDIR}${PREFIX}/bin/vncserver 99 ${INSTALL_SCRIPT} ${WRKSRC}/vncserver.pl ${DESTDIR}${PREFIX}/bin/vncserver
99 ${MV} ${DESTDIR}${PREFIX}/etc/pam.d/tigervnc ${DESTDIR}${PREFIX}/${EGDIR} 100 ${MV} ${DESTDIR}${PREFIX}/etc/pam.d/tigervnc ${DESTDIR}${PREFIX}/${EGDIR}
100 ${MV} ${DESTDIR}${PREFIX}/etc/tigervnc/vncserver-config-defaults ${DESTDIR}${PREFIX}/${EGDIR} 101 ${MV} ${DESTDIR}${PREFIX}/etc/tigervnc/vncserver-config-defaults ${DESTDIR}${PREFIX}/${EGDIR}
101 ${MV} ${DESTDIR}${PREFIX}/etc/tigervnc/vncserver-config-mandatory ${DESTDIR}${PREFIX}/${EGDIR} 102 ${MV} ${DESTDIR}${PREFIX}/etc/tigervnc/vncserver-config-mandatory ${DESTDIR}${PREFIX}/${EGDIR}
102 ${MV} ${DESTDIR}${PREFIX}/etc/tigervnc/vncserver.users ${DESTDIR}${PREFIX}/${EGDIR} 103 ${MV} ${DESTDIR}${PREFIX}/etc/tigervnc/vncserver.users ${DESTDIR}${PREFIX}/${EGDIR}
103 104
104.include "../../mk/bsd.prefs.mk" 105.include "../../mk/bsd.prefs.mk"
105 106
106.if ${X11_TYPE} != "modular" 107.if ${X11_TYPE} != "modular"
107# when using native X, tigervnc server can't find xkb rules or xkbcomp without the following: 108# when using native X, tigervnc server can't find xkb rules or xkbcomp without the following:
108XORG_CONFIGURE_ARGS+= --with-xkb-path=${X11BASE}/lib/X11/xkb 109XORG_CONFIGURE_ARGS+= --with-xkb-path=${X11BASE}/lib/X11/xkb
109XORG_CONFIGURE_ARGS+= --with-xkb-bin-directory=${X11BASE}/bin 110XORG_CONFIGURE_ARGS+= --with-xkb-bin-directory=${X11BASE}/bin
110.endif 111.endif
111 112
112pre-configure: 113pre-configure:
113 cd ${WRKSRC}/unix/xserver && \ 114 cd ${WRKSRC}/unix/xserver && \
114 ${PKGSRC_SETENV} ACLOCAL_PATH=${X11BASE}/share/aclocal \ 115 ${PKGSRC_SETENV} ACLOCAL_PATH=${X11BASE}/share/aclocal \
115 autoreconf -fvi && \ 116 autoreconf -fvi && \
116 ${PKGSRC_SETENV} ${_CONFIGURE_SCRIPT_ENV} CONFIG_SHELL=${BASH} \ 117 ${PKGSRC_SETENV} ${_CONFIGURE_SCRIPT_ENV} CONFIG_SHELL=${BASH} \
117 ${CONFIG_SHELL} ${CONFIG_SHELL_FLAGS} \ 118 ${CONFIG_SHELL} ${CONFIG_SHELL_FLAGS} \
118 ./configure ${XORG_CONFIGURE_ARGS} 119 ./configure ${XORG_CONFIGURE_ARGS}
119 120
120.include "../../mk/jpeg.buildlink3.mk" 121.include "../../mk/jpeg.buildlink3.mk"
121.include "../../converters/libiconv/buildlink3.mk" 122.include "../../converters/libiconv/buildlink3.mk"
122.include "../../devel/gettext-lib/buildlink3.mk" 123.include "../../devel/gettext-lib/buildlink3.mk"
123.include "../../devel/zlib/buildlink3.mk" 124.include "../../devel/zlib/buildlink3.mk"
124.include "../../graphics/hicolor-icon-theme/buildlink3.mk" 125.include "../../graphics/hicolor-icon-theme/buildlink3.mk"
125.include "../../security/gnutls/buildlink3.mk" 126.include "../../security/gnutls/buildlink3.mk"
126.include "../../security/libgcrypt/buildlink3.mk" 127.include "../../security/libgcrypt/buildlink3.mk"
127.include "../../x11/libXft/buildlink3.mk" 128.include "../../x11/libXft/buildlink3.mk"
128.include "../../x11/libX11/buildlink3.mk" 129.include "../../x11/libX11/buildlink3.mk"
129.include "../../x11/libXcursor/buildlink3.mk" 130.include "../../x11/libXcursor/buildlink3.mk"
130.include "../../x11/libXinerama/buildlink3.mk" 131.include "../../x11/libXinerama/buildlink3.mk"
131.include "../../x11/libXtst/buildlink3.mk" 132.include "../../x11/libXtst/buildlink3.mk"
132.include "../../x11/libdrm/buildlink3.mk" 133.include "../../x11/libdrm/buildlink3.mk"
133BUILDLINK_API_DEPENDS.fltk+= fltk>=1.3.3 134BUILDLINK_API_DEPENDS.fltk+= fltk>=1.3.3
134.include "../../x11/fltk13/buildlink3.mk" 135.include "../../x11/fltk13/buildlink3.mk"
135.include "../../x11/pixman/buildlink3.mk" 136.include "../../x11/pixman/buildlink3.mk"
136.include "../../x11/xorgproto/buildlink3.mk" 137.include "../../x11/xorgproto/buildlink3.mk"
137.include "../../x11/xtrans/buildlink3.mk" 138.include "../../x11/xtrans/buildlink3.mk"
138.include "../../x11/libXfont2/buildlink3.mk" 139.include "../../x11/libXfont2/buildlink3.mk"
139.include "../../x11/libXrandr/buildlink3.mk" 140.include "../../x11/libXrandr/buildlink3.mk"
140.include "../../x11/libxkbfile/buildlink3.mk" 141.include "../../x11/libxkbfile/buildlink3.mk"
141.include "../../mk/pthread.buildlink3.mk" 142.include "../../mk/pthread.buildlink3.mk"
142.include "../../mk/bsd.pkg.mk" 143.include "../../mk/bsd.pkg.mk"

cvs diff -r1.2 -r1.3 pkgsrc/net/tigervnc/files/vncserver.pl (switch to unified diff)

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