예제 #1
0
def apport_crash(type, value, tb):
    logging.debug("running apport_crash()")
    if "RELEASE_UPRADER_NO_APPORT" in os.environ:
        logging.debug("RELEASE_UPRADER_NO_APPORT env set")
        return False
    try:
        # we don't depend on python3-apport because of servers
        from apport_python_hook import apport_excepthook
        from apport.report import Report
    except ImportError as e:
        logging.error("failed to import apport python module, can't "
                      "generate crash: %s" % e)
        return False
    from .DistUpgradeVersion import VERSION
    # we pretend we are do-release-upgrade
    sys.argv[0] = "/usr/bin/do-release-upgrade"
    apport_excepthook(type, value, tb)
    # now add the files in /var/log/dist-upgrade/*
    if os.path.exists('/var/crash/_usr_bin_do-release-upgrade.0.crash'):
        report = Report()
        report.setdefault('Tags', 'dist-upgrade')
        release = 'Ubuntu %s' % VERSION[0:5]
        report.setdefault('DistroRelease', release)
        # use the version of the release-upgrader tarball, not the installed
        # package
        report.setdefault('Package',
                          'ubuntu-release-upgrader-core 1:%s' % VERSION)
        _apport_append_logfiles(report)
        report.add_to_existing(
            '/var/crash/_usr_bin_do-release-upgrade.0.crash')
    return True
예제 #2
0
def set_package_info(target):
    """Set Package and Dependencies field"""
    if not os.path.isfile(target):
        raise SystemError("%s is not a file" % target)

    report = Report()
    with open(target, 'rb') as f:
        try:
            report.load(f)
        except Exception as exc:
            raise SystemError("Cannot load file %s: %s" % (target, exc))

        additional_deps = ""
        if 'ExecutablePath' in report and re.search('samba', report['ExecutablePath']):
            try:
                for pkg_name in ('openchangeserver', 'openchange-rpcproxy', 'openchange-ocsmanager',
                                 'sogo-openchange'):
                    packaging.get_version(pkg_name)
                    report.add_package_info(pkg_name)
                    if additional_deps:
                        additional_deps += '\n'
                    additional_deps += report['Package'] + "\n" + report['Dependencies']
            except ValueError:
                # Any of previous packages is not installed
                pass

        # Add executable deps
        report.add_package_info()
        if additional_deps:
            report['Dependencies'] += '\n' + additional_deps
            report['Dependencies'] = '\n'.join(sorted(set(report['Dependencies'].split('\n'))))

        with open(target, 'wb') as f:
            report.write(f)
예제 #3
0
def apport_crash(type, value, tb):
    logging.debug("running apport_crash()")
    if "RELEASE_UPRADER_NO_APPORT" in os.environ:
        logging.debug("RELEASE_UPRADER_NO_APPORT env set")
        return False
    try:
        # we don't depend on python3-apport because of servers
        from apport_python_hook import apport_excepthook
        from apport.report import Report
    except ImportError as e:
        logging.error("failed to import apport python module, can't "
                      "generate crash: %s" % e)
        return False
    from .DistUpgradeVersion import VERSION
    # we pretend we are do-release-upgrade
    sys.argv[0] = "/usr/bin/do-release-upgrade"
    apport_excepthook(type, value, tb)
    # now add the files in /var/log/dist-upgrade/*
    if os.path.exists('/var/crash/_usr_bin_do-release-upgrade.0.crash'):
        report = Report()
        report.setdefault('Tags', 'dist-upgrade')
        release = 'Ubuntu %s' % VERSION[0:5]
        report.setdefault('DistroRelease', release)
        # use the version of the release-upgrader tarball, not the installed
        # package
        report.setdefault('Package', 'ubuntu-release-upgrader-core 1:%s' %
                          VERSION)
        _apport_append_logfiles(report)
        report.add_to_existing(
            '/var/crash/_usr_bin_do-release-upgrade.0.crash')
    return True
 def test_no_information_leak_in_apport_append_logfiles(self):
     tmpdir = tempfile.mkdtemp()
     from apport.report import Report
     report = Report()
     for name in ["apt.log", "system_state.tar.gz", "bar", "main.log"]:
         with open(os.path.join(tmpdir, name), "w") as f:
             f.write("some-data")
     _apport_append_logfiles(report, tmpdir)
     self.assertEqual(
         sorted([
             fname[0].name for fname in report.values()
             if isinstance(f, tuple)
         ]),
         sorted([
             os.path.join(tmpdir, "main.log"),
             os.path.join(tmpdir, "apt.log")
         ]))
예제 #5
0
 def setUp(self):
     self.crash_base = os.path.sep + 'tmp'
     self.crash_base_url = 'file://' + self.crash_base + '/'
     self.crash_path = os.path.join(self.crash_base, 'test.crash')
     self.r = Report()
     self.r['ExecutablePath'] = '/usr/bin/napoleon-solod'
     self.r['Package'] = 'libnapoleon-solo1 1.2-1'
     self.r['Signal'] = '11'
     self.r['StacktraceTop'] = """foo_bar (x=2) at crash.c:28
예제 #6
0
파일: sqlite.py 프로젝트: bencer/openchange
    def download(self, id):
        """
        Download the report from the database

        :raises TypeError: if the report does not exist
        """
        cur = self.db.cursor()
        cur.execute("""SELECT crash_url
                       FROM crashes
                       WHERE crash_id = ?""", [id])
        url = cur.fetchone()[0]

        fh = urlopen(url)

        # Actually read the content
        buf = BytesIO(bytes(fh.read()))

        report = Report()
        report.load(buf)
        return report
예제 #7
0
    def download(self, id):
        """
        Download the report from the database

        :raises TypeError: if the report does not exist
        """
        cur = self.db.cursor()
        cur.execute(
            """SELECT crash_url
                       FROM crashes
                       WHERE crash_id = ?""", [id])
        url = cur.fetchone()[0]

        fh = urlopen(url)

        # Actually read the content
        buf = BytesIO(bytes(fh.read()))

        report = Report()
        report.load(buf)
        return report
def run(target):
    crashes_files = []
    if os.path.isdir(target):
        for fname in os.listdir(target):
            crashes_files.append(os.path.join(target, fname))
    elif os.path.isfile(target):
        crashes_files = [target]
    else:
        raise SystemError("%s is not a directory neither a file" % target)

    for fpath in crashes_files:
        report = Report()

        # This may lead to bad guesses...
        if fpath.endswith('.gz'):
            open_f = gzip.open
        else:
            open_f = open

        with open_f(fpath, 'rb') as f:
            try:
                report.load(f)
                log('%s loaded.' % fpath)
            except Exception as exc:
                log("Cannot load %s: %s" % (fpath, exc))
                continue

        if 'Package' in report:
            log("%s has already the Package field: %s" % (fpath, report['Package']))
        else:
            try:
                mapped_package = map_package(report)
            except KeyError as exc:
                log("Cannot map the package field %s: %s" % (fpath, exc))
                continue
            log("%s package is set to %s" % (fpath, mapped_package))
            report['Package'] = "%s %s" % (mapped_package[0], mapped_package[1])
            with open_f(fpath, 'wb') as f:
                report.write(f)
예제 #9
0
def run(target):
    crashes_files = []
    if os.path.isdir(target):
        for fname in os.listdir(target):
            crashes_files.append(os.path.join(target, fname))
    elif os.path.isfile(target):
        crashes_files = [target]
    else:
        raise SystemError("%s is not a directory neither a file" % target)

    for fpath in crashes_files:
        report = Report()

        # This may lead to bad guesses...
        if fpath.endswith('.gz'):
            open_f = gzip.open
        else:
            open_f = open

        with open_f(fpath, 'rb') as f:
            try:
                report.load(f)
                log('%s loaded.' % fpath)
            except Exception as exc:
                log("Cannot load %s: %s" % (fpath, exc))
                continue

        if 'Package' in report:
            log("%s has already the Package field: %s" %
                (fpath, report['Package']))
        else:
            try:
                mapped_package = map_package(report)
            except KeyError as exc:
                log("Cannot map the package field %s: %s" % (fpath, exc))
                continue
            log("%s package is set to %s" % (fpath, mapped_package))
            report['Package'] = "%s %s" % (mapped_package[0],
                                           mapped_package[1])
            with open_f(fpath, 'wb') as f:
                report.write(f)
예제 #10
0
def _write_apport_report_to_file(exc_info):
    import traceback
    from apport.report import Report

    exc_type, exc_object, exc_tb = exc_info

    pr = Report()
    # add_proc_info sets the ExecutablePath, InterpreterPath, etc.
    pr.add_proc_info()
    # It also adds ProcMaps which for us is rarely useful and mostly noise, so
    # let's remove it.
    del pr['ProcMaps']
    pr.add_user_info()

    # Package and SourcePackage are needed so that apport will report about even
    # non-packaged versions of bzr; also this reports on their packaged
    # dependencies which is useful.
    pr['SourcePackage'] = 'bzr'
    pr['Package'] = 'bzr'

    pr['CommandLine'] = pprint.pformat(sys.argv)
    pr['BzrVersion'] = bzrlib.__version__
    pr['PythonVersion'] = bzrlib._format_version_tuple(sys.version_info)
    pr['Platform'] = platform.platform(aliased=1)
    pr['UserEncoding'] = osutils.get_user_encoding()
    pr['FileSystemEncoding'] = sys.getfilesystemencoding()
    pr['Locale'] = os.environ.get('LANG', 'C')
    pr['BzrPlugins'] = _format_plugin_list()
    pr['PythonLoadedModules'] = _format_module_list()
    pr['BzrDebugFlags'] = pprint.pformat(debug.debug_flags)

    # actually we'd rather file directly against the upstream product, but
    # apport does seem to count on there being one in there; we might need to
    # redirect it elsewhere anyhow
    pr['SourcePackage'] = 'bzr'
    pr['Package'] = 'bzr'

    # tell apport to file directly against the bzr package using 
    # <https://bugs.launchpad.net/bzr/+bug/391015>
    #
    # XXX: unfortunately apport may crash later if the crashdb definition
    # file isn't present
    pr['CrashDb'] = 'bzr'

    tb_file = StringIO()
    traceback.print_exception(exc_type, exc_object, exc_tb, file=tb_file)
    pr['Traceback'] = tb_file.getvalue()

    _attach_log_tail(pr)

    # We want to use the 'bzr' crashdb so that it gets sent directly upstream,
    # which is a reasonable default for most internal errors.  However, if we
    # set it here then apport will crash later if it doesn't know about that
    # crashdb.  Instead, we rely on the bzr package installing both a
    # source hook telling crashes to go to this crashdb, and a crashdb
    # configuration describing it.

    # these may contain some sensitive info (smtp_passwords)
    # TODO: strip that out and attach the rest
    #
    #attach_file_if_exists(report,
    #   os.path.join(dot_bzr, 'bazaar.conf', 'BzrConfig')
    #attach_file_if_exists(report,
    #   os.path.join(dot_bzr, 'locations.conf', 'BzrLocations')
    
    # strip username, hostname, etc
    pr.anonymize()

    if pr.check_ignored():
        # eg configured off in ~/.apport-ignore.xml
        return None
    else:
        crash_file_name, crash_file = _open_crash_file()
        pr.write(crash_file)
        crash_file.close()
        return crash_file_name
예제 #11
0
def _write_apport_report_to_file(exc_info):
    import traceback
    from apport.report import Report

    exc_type, exc_object, exc_tb = exc_info

    pr = Report()
    # add_proc_info sets the ExecutablePath, InterpreterPath, etc.
    pr.add_proc_info()
    # It also adds ProcMaps which for us is rarely useful and mostly noise, so
    # let's remove it.
    del pr['ProcMaps']
    pr.add_user_info()

    # Package and SourcePackage are needed so that apport will report about even
    # non-packaged versions of brz; also this reports on their packaged
    # dependencies which is useful.
    pr['SourcePackage'] = 'brz'
    pr['Package'] = 'brz'

    pr['CommandLine'] = pprint.pformat(sys.argv)
    pr['BrzVersion'] = breezy.__version__
    pr['PythonVersion'] = breezy._format_version_tuple(sys.version_info)
    pr['Platform'] = platform.platform(aliased=1)
    pr['UserEncoding'] = osutils.get_user_encoding()
    pr['FileSystemEncoding'] = sys.getfilesystemencoding()
    pr['Locale'] = os.environ.get('LANG', 'C')
    pr['BrzPlugins'] = _format_plugin_list()
    pr['PythonLoadedModules'] = _format_module_list()
    pr['BrzDebugFlags'] = pprint.pformat(debug.debug_flags)

    # actually we'd rather file directly against the upstream product, but
    # apport does seem to count on there being one in there; we might need to
    # redirect it elsewhere anyhow
    pr['SourcePackage'] = 'brz'
    pr['Package'] = 'brz'

    # tell apport to file directly against the brz package using
    # <https://bugs.launchpad.net/bzr/+bug/391015>
    #
    # XXX: unfortunately apport may crash later if the crashdb definition
    # file isn't present
    pr['CrashDb'] = 'brz'

    tb_file = StringIO()
    traceback.print_exception(exc_type, exc_object, exc_tb, file=tb_file)
    pr['Traceback'] = tb_file.getvalue()

    _attach_log_tail(pr)

    # We want to use the 'brz' crashdb so that it gets sent directly upstream,
    # which is a reasonable default for most internal errors.  However, if we
    # set it here then apport will crash later if it doesn't know about that
    # crashdb.  Instead, we rely on the brz package installing both a
    # source hook telling crashes to go to this crashdb, and a crashdb
    # configuration describing it.

    # these may contain some sensitive info (smtp_passwords)
    # TODO: strip that out and attach the rest
    #
    # attach_file_if_exists(report,
    #   os.path.join(dot_brz, 'breezy.conf', 'BrzConfig')
    # attach_file_if_exists(report,
    #   os.path.join(dot_brz, 'locations.conf', 'BrzLocations')

    # strip username, hostname, etc
    pr.anonymize()

    if pr.check_ignored():
        # eg configured off in ~/.apport-ignore.xml
        return None
    else:
        crash_file_name, crash_file = _open_crash_file()
        pr.write(crash_file)
        crash_file.close()
        return crash_file_name
        report[ident] = (open(f), )

def apport_crash(type, value, tb):
    logging.debug("running apport_crash()")
    try:
        from apport_python_hook import apport_excepthook
        from apport.report import Report
    except ImportError, e:
        logging.error("failed to import apport python module, can't report bug: %s" % e)
        return False
    # we pretend we are update-manager
    sys.argv[0] = "/usr/bin/update-manager"
    apport_excepthook(type, value, tb)
    # now add the files in /var/log/dist-upgrade/*
    if os.path.exists('/var/crash/_usr_bin_update-manager.0.crash'):
        report = Report()
        report.setdefault('Tags', 'dist-upgrade')
        report['Tags'] += ' dist-upgrade'
        _apport_append_logfiles(report)
        report.add_to_existing('/var/crash/_usr_bin_update-manager.0.crash')
    return True

def apport_pkgfailure(pkg, errormsg):
    logging.debug("running apport_pkgfailure() %s: %s", pkg, errormsg)
    LOGDIR="/var/log/dist-upgrade/"
    s = "/usr/share/apport/package_hook"

    # we do not report followup errors from earlier failures
    # dpkg messages will not be translated if DPKG_UNTRANSLATED_MESSAGES is
    # set which it is by default so check for the English message first
    if "dependency problems - leaving unconfigured" in errormsg:
예제 #13
0
import errno

def apport_crash(type, value, tb):
    logging.debug("running apport_crash()")
    try:
        from apport_python_hook import apport_excepthook
        from apport.report import Report
    except ImportError, e:
        logging.error("failed to import apport python module, can't report bug: %s" % e)
        return False
    # we pretend we are update-manager
    sys.argv[0] = "/usr/bin/update-manager"
    apport_excepthook(type, value, tb)
    # now add the files in /var/log/dist-upgrade/*
    if os.path.exists('/var/crash/_usr_bin_update-manager.0.crash'):
        report = Report()
        report.setdefault('Tags', 'dist-upgrade')
        report['Tags'] += ' dist-upgrade'
        for fname in os.listdir("/var/log/dist-upgrade/"):
            f = os.path.join("/var/log/dist-upgrade",fname)
            if not os.path.isfile(f) or os.path.getsize(f) == 0:
                continue
            report[f.replace(".","").replace("-","")] = (open(f), )
        report.add_to_existing('/var/crash/_usr_bin_update-manager.0.crash')
    return True

def apport_pkgfailure(pkg, errormsg):
    logging.debug("running apport_pkgfailure() %s: %s", pkg, errormsg)
    LOGDIR="/var/log/dist-upgrade/"
    s = "/usr/share/apport/package_hook"