def test_enabled(self): '''enabled.''' impl.configuration = '/nonexisting' self.assertEqual(impl.enabled(), True) f = tempfile.NamedTemporaryFile() impl.configuration = f.name f.write('# configuration file\nenabled = 1'.encode()) f.flush() self.assertEqual(impl.enabled(), True) f.close() f = tempfile.NamedTemporaryFile() impl.configuration = f.name f.write('# configuration file\n enabled =0 '.encode()) f.flush() self.assertEqual(impl.enabled(), False) f.close() f = tempfile.NamedTemporaryFile() impl.configuration = f.name f.write('# configuration file\nnothing here'.encode()) f.flush() self.assertEqual(impl.enabled(), True) f.close()
def main(argv=None): if argv is None: argv = sys.argv from apport.packaging_impl import impl as packaging if not packaging.enabled(): return -1 import apport.report report = apport.report.Report(type='Crash') report.setdefault('Tags', '') report.setdefault('Title', 'GPU lockup') report.add_os_info() report.add_proc_info() report.add_user_info() report['Package'] = 'xserver-xorg-video-intel' report['Tags'] += ' freeze' report['Lspci'] = command_output(['lspci', '-vvnn']) device = get_pci_device(report['Lspci']) if device and 'name' in device: if 'supported' in device and device['supported'] == False: # Unsupported chipset; we don't want bugs reported for this HW return -1 report['Chipset'] = device['name'] report['Title'] = "[%s] GPU lockup" %(device['name']) attach_hardware(report) attach_related_packages(report, ["xserver-xorg", "libdrm2", "xserver-xorg-video-intel"]) attach_file_if_exists(report, '/etc/X11/xorg.conf', 'XorgConf') attach_file(report, '/var/log/Xorg.0.log', 'XorgLog') attach_file_if_exists(report, '/var/log/Xorg.0.log.old', 'XorgLogOld') attach_file_if_exists(report, '/sys/kernel/debug/dri/0/i915_error_state', 'i915_error_state') signature = get_signature(report.get('i915_error_state', '')) if signature: report['Title'] += " " + signature report['DuplicateSignature'] = "%s %s" %(report['Title'], report['DistroRelease']) nowtime = datetime.datetime.now() report_filename = '/var/crash/%s.%s.crash' % (report['Package'], str(nowtime).replace(' ', '_')) if '--stdout' in argv: print "# %s" %(report_filename) report.write(sys.stdout) return 0 report_file = os.fdopen(os.open(report_filename, os.O_WRONLY|os.O_CREAT|os.O_EXCL), 'w') os.chmod(report_filename, 0600) try: report.write(report_file) finally: report_file.close() return 0
def apport_excepthook(exc_type, exc_obj, exc_tb): '''Catch an uncaught exception and make a traceback.''' # create and save a problem report. Note that exceptions in this code # are bad, and we probably need a per-thread reentrancy guard to # prevent that happening. However, on Ubuntu there should never be # a reason for an exception here, other than [say] a read only var # or some such. So what we do is use a try - finally to ensure that # the original excepthook is invoked, and until we get bug reports # ignore the other issues. # import locally here so that there is no routine overhead on python # startup time - only when a traceback occurs will this trigger. try: # ignore 'safe' exit types. if exc_type in (KeyboardInterrupt, ): return # do not do anything if apport was disabled from apport.packaging_impl import impl as packaging if not packaging.enabled(): return from cStringIO import StringIO import re, tempfile, traceback from apport.fileutils import likely_packaged # apport will look up the package from the executable path. try: binary = os.path.realpath(os.path.join(os.getcwdu(), sys.argv[0])) except (TypeError, AttributeError, IndexError): # the module has mutated sys.argv, plan B try: binary = os.readlink('/proc/%i/exe' % os.getpid()) except OSError: return # for interactive python sessions, sys.argv[0] == ''; catch that and # other irregularities if not os.access(binary, os.X_OK) or not os.path.isfile(binary): return # filter out binaries in user accessible paths if not likely_packaged(binary): return import apport.report pr = apport.report.Report() # append a basic traceback. In future we may want to include # additional data such as the local variables, loaded modules etc. tb_file = StringIO() traceback.print_exception(exc_type, exc_obj, exc_tb, file=tb_file) pr['Traceback'] = tb_file.getvalue().strip() pr.add_proc_info() pr.add_user_info() # override the ExecutablePath with the script that was actually running. pr['ExecutablePath'] = binary pr['PythonArgs'] = '%r' % sys.argv if pr.check_ignored(): return mangled_program = re.sub('/', '_', binary) # get the uid for now, user name later user = os.getuid() pr_filename = '/var/crash/%s.%i.crash' % (mangled_program, user) if os.path.exists(pr_filename): if apport.fileutils.seen_report(pr_filename): # remove the old file, so that we can create the new one with # os.O_CREAT|os.O_EXCL os.unlink(pr_filename) else: # don't clobber existing report return report_file = os.fdopen(os.open(pr_filename, os.O_WRONLY|os.O_CREAT|os.O_EXCL), 'w') os.chmod(pr_filename, 0600) try: pr.write(report_file) finally: report_file.close() finally: # resume original processing to get the default behaviour, # but do not trigger an AttributeError on interpreter shutdown. if sys: sys.__excepthook__(exc_type, exc_obj, exc_tb)
def apport_excepthook(exc_type, exc_obj, exc_tb): '''Catch an uncaught exception and make a traceback.''' # create and save a problem report. Note that exceptions in this code # are bad, and we probably need a per-thread reentrancy guard to # prevent that happening. However, on Ubuntu there should never be # a reason for an exception here, other than [say] a read only var # or some such. So what we do is use a try - finally to ensure that # the original excepthook is invoked, and until we get bug reports # ignore the other issues. # import locally here so that there is no routine overhead on python # startup time - only when a traceback occurs will this trigger. try: # ignore 'safe' exit types. if exc_type in (KeyboardInterrupt, ): return # do not do anything if apport was disabled from apport.packaging_impl import impl as packaging if not packaging.enabled(): return from cStringIO import StringIO import re, tempfile, traceback from apport.fileutils import likely_packaged # apport will look up the package from the executable path. try: binary = os.path.realpath(os.path.join(os.getcwdu(), sys.argv[0])) except (TypeError, AttributeError, IndexError): # the module has mutated sys.argv, plan B try: binary = os.readlink('/proc/%i/exe' % os.getpid()) except OSError: return # for interactive python sessions, sys.argv[0] == ''; catch that and # other irregularities if not os.access(binary, os.X_OK) or not os.path.isfile(binary): return # filter out binaries in user accessible paths if not likely_packaged(binary): return import apport.report pr = apport.report.Report() # append a basic traceback. In future we may want to include # additional data such as the local variables, loaded modules etc. tb_file = StringIO() traceback.print_exception(exc_type, exc_obj, exc_tb, file=tb_file) pr['Traceback'] = tb_file.getvalue().strip() pr.add_proc_info() pr.add_user_info() # override the ExecutablePath with the script that was actually running. pr['ExecutablePath'] = binary pr['PythonArgs'] = '%r' % sys.argv if pr.check_ignored(): return mangled_program = re.sub('/', '_', binary) # get the uid for now, user name later user = os.getuid() pr_filename = '/var/crash/%s.%i.crash' % (mangled_program, user) if os.path.exists(pr_filename): if apport.fileutils.seen_report(pr_filename): # remove the old file, so that we can create the new one with # os.O_CREAT|os.O_EXCL os.unlink(pr_filename) else: # don't clobber existing report return report_file = os.fdopen( os.open(pr_filename, os.O_WRONLY | os.O_CREAT | os.O_EXCL), 'w') os.chmod(pr_filename, 0600) try: pr.write(report_file) finally: report_file.close() finally: # resume original processing to get the default behaviour, # but do not trigger an AttributeError on interpreter shutdown. if sys: sys.__excepthook__(exc_type, exc_obj, exc_tb)