PageRenderTime 45ms CodeModel.GetById 37ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/gdm/failsafeXServer

http://github.com/brinkman83/bashrc
#! | 160 lines | 140 code | 20 blank | 0 comment | 0 complexity | 791297354d1c22d1616154b3c6060f2d MD5 | raw file
  1#!/bin/bash
  2
  3# $Id:$
  4#
  5# This provides a stripped down 'failsafe' mode for situations
  6# where X is failing to start up.
  7
  8# Author: Bryce W. Harrington <bryce@canonical.com>
  9
 10# Copyright 2007 Canonical, Ltd
 11#
 12# This is free software; you may redistribute it and/or modify
 13# it under the terms of the GNU General Public License as
 14# published by the Free Software Foundation; either version 2,
 15# or (at your option) any later version.
 16#
 17# This is distributed in the hope that it will be useful, but
 18# WITHOUT ANY WARRANTY; without even the implied warranty of
 19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 20# GNU General Public License for more details.
 21#
 22# You should have received a copy of the GNU General Public License with
 23# the Debian operating system, in /usr/share/common-licenses/GPL;  if
 24# not, write to the Free Software Foundation, Inc., 59 Temple Place,
 25# Suite 330, Boston, MA 02111-1307 USA
 26
 27# Upstart jobs don't have a particular environment, we need to source the
 28# variables needed for localization ourselves
 29if [ -r /etc/default/locale ]; then
 30    . /etc/default/locale
 31    export LANG LANGUAGE
 32elif [ -r /etc/environment ]; then
 33    . /etc/environment
 34    export LANG LANGUAGE
 35fi
 36
 37xorg_conf_failsafe=${BPX_XORG_CONF_FAILSAFE:-"/etc/X11/xorg.conf.failsafe"}
 38xorg_conf=${BPX_XORG_CONF:-"/etc/X11/xorg.conf"}
 39fallback_driver=${BPX_FALLBACK_DRIVER:-"vesa"}
 40client=${BPX_CLIENT:-"/etc/gdm/failsafeXinit"}
 41clientargs=${BPX_CLIENTARGS:-$xorg_conf_failsafe}
 42blacklist=${BPX_BLACKLIST:-"/etc/gdm/failsafeBlacklist"}
 43main_driver=${BPX_DRIVER:-"vesa"}
 44checkduration=${BPX_CHECK_DURATION:-30}
 45failsafe_log=${BPX_LOG:-"/var/log/gdm/failsafe.log"}
 46
 47server=${BPX_SERVER:-/usr/bin/X}
 48serverargs=${BPX_SERVERARGS:-"$*"}
 49serverargs="${serverargs} -br -once -config $xorg_conf_failsafe -logfile /var/log/Xorg.failsafe.log"
 50   # -br:      Black background
 51   # -once:    Terminate server after one session
 52   # -config:  Specify location of xorg.conf file to use
 53   #           Note: Only root can specify absolute paths
 54   # -logfile: Don't overwrite Xorg.0.log
 55
 56warn() {
 57    echo "Warning:  $1" 1>&2
 58}
 59
 60is_installed() {
 61    prog=$1
 62    need=$2
 63    /usr/bin/which $prog > /dev/null 2>&1
 64    err=$?
 65    if [ ! $err = 0 ]; then
 66	warn "Could not $need because $prog is not installed ($err)"
 67	return $err
 68    fi
 69    return 0
 70}
 71
 72# Tests if the given pciids are in numerical order from least to greatest
 73# (e.g., $a <= $b <= $c <= ...)
 74pciids_in_order() {
 75    lastid=0
 76    for pciid in $* ; do
 77        # Strip embedded : and convert hex to dec
 78        id=$((0x${pciid/:/}))
 79        if [ $id -lt $lastid ]; then
 80            return 1
 81        fi
 82        lastid=$id
 83    done
 84    return 0
 85}
 86
 87get_driver() {
 88    machine=$(uname -m)
 89    if grep -q -E '(nouveau|drm)fb' /proc/fb; then
 90        echo "fbdev"
 91    elif [ $machine = "ppc" ]; then
 92        echo "fbdev"
 93    elif [ $machine = "powerpc" ]; then
 94        echo "fbdev"
 95    elif [ $machine = "ppc64" ]; then
 96        echo "fbdev"
 97    else
 98        echo $fallback_driver
 99    fi
100    return 0
101}
102
103# Check if we've already attempted a failsafe session without success
104if [ -e "$failsafe_log" ]; then
105    cur_time=$(date +"%s")
106    last_run=$(tail -n 1 $failsafe_log | cut -d' ' -f1)
107    time_diff=$(expr $cur_time - $last_run)
108    if [ $time_diff -lt $checkduration ]; then
109        warn "Failsafe mode was already attempted within $checkduration seconds."
110        warn "Falling back to gdm to report the issue."
111        exit 1
112    fi
113fi
114
115# When failsafe mode is activated, check the blacklist for systems we
116# know do not support VESA 800x600/256
117#      Use EDID + PCI IDs as key to lookup (Can get PCI IDs from discover)
118#      If the display does not give EDID info, then use VGA 640x480/16 mode
119#      If a matching entry is found, then use VGA 640x480/16 mode
120driver=$(get_driver)
121
122# Generate a fresh xorg.conf.failsafe using identified driver
123cat > $xorg_conf_failsafe <<EOF
124Section "Device"
125	Identifier	"Configured Video Device"
126	Driver		"$driver"
127EndSection
128
129Section "Monitor"
130	Identifier	"Configured Monitor"
131EndSection
132
133Section "Screen"
134	Identifier	"Default Screen"
135	Monitor		"Configured Monitor"
136	Device		"Configured Video Device"
137EndSection
138EOF
139
140md5xorg=$(md5sum $xorg_conf)
141date +"%s $md5xorg" >> $failsafe_log
142if [ $? -ne 0 ]; then
143    warn "Cannot write to $failsafe_log"
144fi
145
146if pidof /usr/sbin/gdm ; then
147    clientargs="${clientargs} with-gdm"
148fi
149
150# Stop gdm if it's running, otherwise it will attempt to manage the display
151# out from under us
152if pidof /usr/sbin/gdm ; then
153    exec kill -STOP $PPID
154fi
155
156echo "xinit $client $clientargs -- $server $serverargs"
157xinit $client $clientargs -- $server $serverargs
158
159# This seems to cause gdm to attempt to start a new x session
160#exec kill -USR1 `cat /var/run/gdm.pid`