summaryrefslogtreecommitdiffstats
path: root/exception.py
blob: 0df4eab7a3dbd3e4d6d08ba430d730821f0e349c (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#
# exception.py - general exception formatting and saving
#
# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007  Red Hat, Inc.
# All rights reserved.
#
# 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 of the License, 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
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Author(s): Matt Wilson <msw@redhat.com>
#            Erik Troan <ewt@redhat.com>
#            Chris Lumens <clumens@redhat.com>
#
from meh.handler import *
from meh.dump import *
import isys
import sys
import os
import shutil
import signal
from flags import flags
import kickstart

import logging
log = logging.getLogger("anaconda")

class AnacondaExceptionHandler(ExceptionHandler):
    def postWriteHook(self, (ty, value, tb), anaconda):
        # See if /mnt/sysimage is present and put exception there as well
        if os.access("/mnt/sysimage/root", os.X_OK):
            try:
                shutil.copyfile("/tmp/anacdump.txt", "/mnt/sysimage/root/anacdump.txt")
            except:
                log.error("Failed to copy anacdump.txt to /mnt/sysimage/root")
                pass

        # run kickstart traceback scripts (if necessary)
        try:
            if anaconda.isKickstart:
                kickstart.runTracebackScripts(anaconda)
        except:
            pass

    def runDebug(self, (ty, value, tb)):
        # vtActivate does not work on certain ppc64 machines, so just skip
        # that and continue with the rest of the debugger setup.
        try:
            isys.vtActivate(1)
        except SystemError:
            pass

        self.intf.__del__ ()

        pidfl = "/tmp/vncshell.pid"
        if os.path.exists(pidfl) and os.path.isfile(pidfl):
            pf = open(pidfl, "r")
            for pid in pf.readlines():
                if not int(pid) == os.getpid():
                    os.kill(int(pid), signal.SIGKILL)
            pf.close()

        if not flags.test:
            os.open("/dev/console", os.O_RDWR)   # reclaim stdin
            os.dup2(0, 1)                        # reclaim stdout
            os.dup2(0, 2)                        # reclaim stderr
            #   ^
            #   |
            #   +------ dup2 is magic, I tells ya!

        # bring back the echo
        import termios
        si = sys.stdin.fileno()
        attr = termios.tcgetattr(si)
        attr[3] = attr[3] & termios.ECHO
        termios.tcsetattr(si, termios.TCSADRAIN, attr)

        print("\nEntering debugger...")
        import pdb
        pdb.post_mortem (tb)
        os.kill(os.getpid(), signal.SIGKILL)

def initExceptionHandling(anaconda):
    conf = Config(programName="anaconda", programVersion=os.environ["ANACONDAVERSION"],
                  bugFiler=anaconda.id.instClass.bugFiler,
                  attrSkipList=[ "anaconda.backend.ayum",
                                 "anaconda.backend.dlpkgs",
                                 "anaconda.id.accounts",
                                 "anaconda.id.bootloader.password",
                                 "anaconda.id.comps",
                                 "anaconda.id.dispatch",
                                 "anaconda.id.hdList",
                                 "anaconda.id.ksdata",
                                 "anaconda.id.instLanguage.font",
                                 "anaconda.id.instLanguage.kbd",
                                 "anaconda.id.instLanguage.info",
                                 "anaconda.id.instLanguage.localeInfo",
                                 "anaconda.id.instLanguage.nativeLangNames",
                                 "anaconda.id.instLanguage.tz",
                                 "anaconda.id.keyboard._mods._modelDict",
                                 "anaconda.id.keyboard.modelDict",
                                 "anaconda.id.storage.encryptionPassphrase",
                                 "anaconda.id.rootPassword",
                                 "anaconda.id.tmpData",
                                 "anaconda.intf.icw.buff",
                                 "anaconda.intf.icw.currentWindow.storage.encryptionPassphrase",
                                 "anaconda.intf.icw.stockButtons",
                                 "dispatch.sack.excludes",
                               ],
                  localSkipList=[ "passphrase", "password" ],
                  fileList=[ "/tmp/syslog", "/tmp/anaconda.log", "/tmp/lvmout",
                             "/tmp/resize.out", "/tmp/program.log",
                             "/tmp/storage.log", "/tmp/yum.log",
                             anaconda.rootPath + "/root/install.log",
                             anaconda.rootPath + "/root/upgrade.log",
                             "/proc/cmdline"])
    handler = AnacondaExceptionHandler(conf, anaconda.intf, ReverseExceptionDump)
    handler.install(anaconda)