~ubuntu-branches/ubuntu/saucy/mountall/saucy

« back to all changes in this revision

Viewing changes to apport/mountall.py

  • Committer: Steve Langasek
  • Date: 2013-04-05 06:44:42 UTC
  • Revision ID: steve.langasek@canonical.com-20130405064442-bo1bye05s7fh6yde
apport/mountall.py: add a mountall apport hook.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
'''
 
3
Mountall apport hook.
 
4
'''
 
5
 
 
6
import os
 
7
from apport.hookutils import *
 
8
import apport.packaging
 
9
import glob
 
10
 
 
11
msg = \
 
12
"""
 
13
The contents of your /etc/fstab file and relevant log files may help
 
14
developers diagnose your bug more quickly. However, if you have modified
 
15
/etc/fstab, these files may contain sensitive information.
 
16
 
 
17
Do you want to include the files in your bug report? (you will be able
 
18
to review the data before it is sent)
 
19
"""
 
20
 
 
21
def add_root_file(map, file):
 
22
    """
 
23
    Add @file to @map such that @map can be passed to
 
24
    attach_root_command_outputs() to have @file attached to the report
 
25
    event if it is unreadable by the current user.
 
26
    """
 
27
    if not os.path.exists(file):
 
28
        return
 
29
 
 
30
    key = path_to_key(file)
 
31
 
 
32
    map[key] = 'cat %s' % file
 
33
 
 
34
 
 
35
def add_info(report, ui):
 
36
    attach_files = False
 
37
 
 
38
    # files that are not readable by current user
 
39
    unreadable_files = {}
 
40
 
 
41
    problem_type = report.get('ProblemType', '')
 
42
 
 
43
    if problem_type == 'Bug' and ui:
 
44
        if ui.yesno(msg) == None:
 
45
            raise StopIteration
 
46
        attach_files = True
 
47
    elif problem_type == 'Crash':
 
48
        # crash bugs are private by default
 
49
        attach_files = True
 
50
 
 
51
    if attach_files == False:
 
52
        return
 
53
 
 
54
    attach_file(report, '/etc/fstab')
 
55
    attach_file(report, '/etc/mtab')
 
56
    attach_file(report, '/proc/cmdline', 'ProcKernelCmdline')
 
57
    attach_file(report, '/proc/mounts', 'ProcMounts')
 
58
    attach_file(report, '/proc/self/mountinfo', 'ProcSelfMountinfo')
 
59
    attach_file_if_exists(report, '/run/mount/utab')
 
60
 
 
61
    report['Mounts'] = apport.hookutils.command_output(['mount'])
 
62
 
 
63
    # mountall logs to the console so until Upstart can log to both the
 
64
    # console and a file, grab the plymouth log which captures the
 
65
    # console.
 
66
    add_root_file(unreadable_files, '/var/log/boot.log')
 
67
 
 
68
    # in case admin changed the console stanza
 
69
    add_root_file(unreadable_files, '/var/log/upstart/mountall.log')
 
70
 
 
71
    attach_root_command_outputs(report, unreadable_files)