File: ldm

package info (click to toggle)
ldm 2:2.0.6-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,012 kB
  • ctags: 144
  • sloc: sh: 3,813; ansic: 1,648; makefile: 105; sed: 16
file content (98 lines) | stat: -rwxr-xr-x 3,314 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
# Depend on the ldm package
#
# Copyright 2005, Canonical Ltd.
# Copyright 2006-2008 Vagrant Cascadian
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License with your
# Debian GNU system, in /usr/share/common-licenses/GPL.  If not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

#
# Load code common to X based screen scripts
#

. /usr/share/ltsp/screen-x-common

while :; do
    #
    # Server scalability.  If there exists a /usr/share/ltsp/get_hosts file, then
    # use it to populate the LDM_SERVER environment variable.
    #

    if [ -z "${LDM_SERVER}" ]; then
        if [ -x /usr/share/ltsp/get_hosts ]; then
            LDM_SERVER=$(/usr/share/ltsp/get_hosts)
        else
            LDM_SERVER=${SERVER}
        fi
    fi
    export LDM_SERVER

    #
    # Loop though each of the hosts, and get their ldminfo
    #

    if [ -n "${LDM_SERVER}" ]; then
        test ! -d /var/run/ldm && mkdir -p /var/run/ldm
        for SRV in $LDM_SERVER ; do
            nc -w 5 $SRV 9571 > /var/run/ldm/$SRV
            # Write server to /etc/hosts so reverse DNS lookup is not necessary
            if ! grep -q "$SRV" /etc/hosts ; then
                echo "$SRV	server-$SRV" >> /etc/hosts
            fi
        done
    fi

    get_xfs_settings "$LDM_SERVER"

    # FIXME: It should not be necessary to disable xauth generation for ssh.
    # However it causes ssh X11 forwarding to fail because we are doing something wrong.
    if boolean_is_true "$LDM_DIRECTX" ; then
        # Generate X server's xauth
        # /dev/random is not usable here because there is likely not 
        # 16 bytes of entropy since the thin client probably lacks keyboard/mouse
        # input at this point, and there is no IDE to generate timing entropy.
        mcookie=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | hexdump -e \\"%08x\\"`
        if [ -z "$mcookie" ]; then
            echo "Couldn't create cookie"
            exit 1
        fi
        # FIXME: This needs to non-destructively operate  in parallel with other
        # X servers running on the same machine.  See /usr/bin/startx for example.
        export XAUTHORITY=/root/.Xauthority
        xauth -q -f $XAUTHORITY << EOF
add ${DISP} . $mcookie
EOF
        # Might not be necessary to do these... 
        xauth -q -f $XAUTHORITY << EOF
add `hostname`${DISP} . $mcookie
EOF
        xauth -q -f $XAUTHORITY << EOF
add 127.0.0.1/unix${DISP} . $mcookie
EOF
    fi
    
    ldm vt${TTY} ${DISP} $X_ARGS

    # Clean up from some buggy video drivers that need two kills
    XPROC=$(pgrep -f "${DISP}")
    while [ -n "${XPROC}" ]; do
	kill $XPROC
        sleep 1
	XPROC=$(pgrep -f "${DISP}")
    done

    rm -f /root/.Xauthority
    rm -f /tmp/.X11-unix/X${TTY}
    rm -f /tmp/.X${TTY}-lock
done