5
# This provides a stripped down 'failsafe' mode for situations
6
# where X is failing to start up.
8
# Author: Bryce W. Harrington <bryce@canonical.com>
10
# Copyright 2007 Canonical, Ltd
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.
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.
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
27
# Upstart jobs don't have a particular environment, we need to source the
28
# variables needed for localization ourselves
29
if [ -r /etc/default/locale ]; then
32
elif [ -r /etc/environment ]; then
37
xorg_conf_failsafe=${BPX_XORG_CONF_FAILSAFE:-"/etc/X11/xorg.conf.failsafe"}
38
xorg_conf=${BPX_XORG_CONF:-"/etc/X11/xorg.conf"}
39
fallback_driver=${BPX_FALLBACK_DRIVER:-"vesa"}
40
client=${BPX_CLIENT:-"/etc/gdm/failsafeXinit"}
41
clientargs=${BPX_CLIENTARGS:-$xorg_conf_failsafe}
42
blacklist=${BPX_BLACKLIST:-"/etc/gdm/failsafeBlacklist"}
43
main_driver=${BPX_DRIVER:-"vesa"}
44
checkduration=${BPX_CHECK_DURATION:-30}
45
failsafe_log=${BPX_LOG:-"/var/log/gdm/failsafe.log"}
47
server=${BPX_SERVER:-/usr/bin/X}
48
serverargs=${BPX_SERVERARGS:-"$*"}
49
serverargs="${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
57
echo "Warning: $1" 1>&2
63
/usr/bin/which $prog > /dev/null 2>&1
65
if [ ! $err = 0 ]; then
66
warn "Could not $need because $prog is not installed ($err)"
72
# Tests if the given pciids are in numerical order from least to greatest
73
# (e.g., $a <= $b <= $c <= ...)
77
# Strip embedded : and convert hex to dec
79
if [ $id -lt $lastid ]; then
89
if grep -q -E '(nouveau|drm)fb' /proc/fb; then
91
elif [ $machine = "ppc" ]; then
93
elif [ $machine = "powerpc" ]; then
95
elif [ $machine = "ppc64" ]; then
103
# Check if we've already attempted a failsafe session without success
104
if [ -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."
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
122
# Generate a fresh xorg.conf.failsafe using identified driver
123
cat > $xorg_conf_failsafe <<EOF
125
Identifier "Configured Video Device"
130
Identifier "Configured Monitor"
134
Identifier "Default Screen"
135
Monitor "Configured Monitor"
136
Device "Configured Video Device"
140
md5xorg=$(md5sum $xorg_conf)
141
date +"%s $md5xorg" >> $failsafe_log
142
if [ $? -ne 0 ]; then
143
warn "Cannot write to $failsafe_log"
146
if pidof /usr/sbin/gdm ; then
147
clientargs="${clientargs} with-gdm"
150
# Stop gdm if it's running, otherwise it will attempt to manage the display
152
if pidof /usr/sbin/gdm ; then
153
exec kill -STOP $PPID
156
echo "xinit $client $clientargs -- $server $serverargs"
157
xinit $client $clientargs -- $server $serverargs
159
# This seems to cause gdm to attempt to start a new x session
160
#exec kill -USR1 `cat /var/run/gdm.pid`