# # xserver.py - initial xserver startup for GUI mode. # # Matt Wilson # Brent Fox # # Copyright 1999-2002 Red Hat, Inc. # # This software may be freely redistributed under the terms of the GNU # library public license. # # You should have received a copy of the GNU Library Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # import os import string import kudzu import isys import sys import time from xf86config import * from flags import flags from snack import * from constants_text import * from mouse_text import MouseWindow, MouseDeviceWindow from rhpl.translate import _ from rhpl.keyboard import Keyboard from rhpl.mouse import Mouse from rhpl.videocard import VGA16Card, VESADriverCard serverPath = "" def mouseWindow(mouse): screen = SnackScreen() STEP_MESSAGE = 0 STEP_TYPE = 1 STEP_DEVICE = 2 STEP_DONE = 3 step = 0 while step < STEP_DONE: if step == STEP_MESSAGE: button = ButtonChoiceWindow(screen, _("Mouse Not Detected"), _("Your mouse was not automatically " "detected. To proceed in the graphical " "installation mode, please proceed to " "the next screen and provide your mouse " "information. You may also use text mode " "installation which does not require a mouse."), buttons = [ _("OK"), _("Use text mode") ]) if button == string.lower (_("Use text mode")): screen.finish () return 0 else: step = STEP_TYPE continue if step == STEP_TYPE: rc = MouseWindow()(screen, mouse) if rc == INSTALL_BACK: step = STEP_MESSAGE continue else: step = STEP_DEVICE continue if step == STEP_DEVICE: rc = MouseDeviceWindow()(screen, mouse) if rc == INSTALL_BACK: step = STEP_TYPE continue else: step = STEP_DONE continue screen.finish() return 1 # start miniWM def startMiniWM(root='/'): childpid = os.fork() if not childpid: args = [root + '/usr/bin/mini-wm', '--display', ':1'] os.execv(args[0], args) sys.exit (1) return childpid # start X server for install process ONLY def startX(resolution, nofbmode, video, monitor, mouse, keyboard): global serverPath global mode os.environ['DISPLAY'] = ':1' serverPath = None attempt = 'PROBED' failed = 1 next_attempt = None while next_attempt != 'END': card = None if attempt == 'PROBED': if video.primaryCard(): print _("Attempting to start native X server") card = video.primaryCard() else: card = None next_attempt = 'VESA' elif attempt == 'VESA': if video.primaryCard(): print _("Attempting to start VESA driver X server") vram = video.primaryCard().getVideoRam() if vram: card = VESADriverCard(vram) else: card = None else: card = None next_attempt = 'END' # # Disabling VGA16 - does bad things with Xft currently # # elif attempt == 'VGA16': # if no xserver then try falling back to VGA16 in no fb # card = VGA16Card() # # print _("Attempting to start VGA16 X server") # next_attempt = 'END' else: print "Got off end somehow!" break if card and card.getXServer() != None: serverPath = '/usr/X11R6/bin/' + card.getXServer() if os.access (serverPath, os.X_OK): try: x = XF86Config (card, monitor, mouse, keyboard, resolution) if x.res == "640x480": x.setForcedDPI(75) else: x.setForcedDPI(96) testx(x) failed = 0 break except (RuntimeError, IOError): pass attempt = next_attempt #--If original server isn't there...send them to text mode if failed: raise RuntimeError, "No X server binaries found to run" return x def testx(x): try: server = x.test ([':1', 'vt7', '-s', '1440', '-terminate', '-dpms', '-v', '-ac', '-nolisten', 'tcp'], spawn=1) except: import traceback server = None (type, value, tb) = sys.exc_info() list = traceback.format_exception (type, value, tb) text = string.joinfields (list, "") print text # give time for the server to fail (if it is going to fail...) # FIXME: Should find out if X server is already running # otherwise with NFS installs the X server may be still being # fetched from the network while we already continue to run if not server: sys.stderr.write("X SERVER FAILED"); raise RuntimeError, "X server failed to start" count = 0 sys.stdout.write(_("Waiting for X server to start...log located in /tmp/X.log\n")) sys.stdout.flush() for i in range(5): time.sleep(1) sys.stdout.write("%s..." % (i+1)) sys.stdout.flush() while count < 60: sys.stdout.write(".") sys.stdout.flush() pid = 0 try: pid, status = os.waitpid (server, os.WNOHANG) except OSError, (errno, msg): print __name__, "waitpid:", msg if pid: sys.stderr.write("X SERVER FAILED"); raise RuntimeError, "X server failed to start" try: os.stat ("/tmp/.X11-unix/X1") break except OSError: pass time.sleep(1) count = count + 1 print _(" X server started successfully.") # now start up mini-wm if not flags.test: try: miniwm_pid = startMiniWM() log("Started mini-wm") except: miniwm_pid = None log("Unable to start mini-wm") else: miniwm_pid = None child = os.fork() if (child): # here we fork and wait on our child, which will contine # on being anaconda, to finish. When the child finishes # we kill the X server and exit with the exit status set to # the same exit status of our child (which is now the main # anaconda process). try: pid, status = os.waitpid(child, 0) except OSError, (errno, msg): print __name__, "waitpid:", msg sys.exit (-1) # kill miniwm first if miniwm_pid is not None: try: os.kill(miniwm_pid, 15) os.waitpid(miniwm_pid, 0) except: pass # now the X server try: os.kill(server, 15) os.waitpid(server, 0) except: pass if os.WIFEXITED(status) and not os.WEXITSTATUS(status): sys.exit(0) sys.exit(-1)