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