[ABRT PATCH] adds a kdump.conf parser to get the correct dump dir location, closes #640
Richard Marko
rmarko at redhat.com
Thu Aug 29 09:52:52 UTC 2013
Pushed. Thanks!
On 08/26/2013 03:27 PM, Petr Kubat wrote:
> Signed-off-by: Petr Kubat <pkubat at redhat.com>
> ---
> src/hooks/abrt_harvest_vmcore.py.in | 93 +++++++++++++++++++++++++++++++++----
> 1 file changed, 83 insertions(+), 10 deletions(-)
>
> diff --git a/src/hooks/abrt_harvest_vmcore.py.in b/src/hooks/abrt_harvest_vmcore.py.in
> index 22dad07..4f2e1d0 100644
> --- a/src/hooks/abrt_harvest_vmcore.py.in
> +++ b/src/hooks/abrt_harvest_vmcore.py.in
> @@ -1,22 +1,92 @@
> #!/usr/bin/python
> """
> This script is meant to be run once at system startup after abrtd is up
> - and running. It moves all vmcore directories in /var/crash
> + and running. It moves all vmcore directories in kdump's dump directory
> (which are presumably created by kdump) to abrtd spool directory.
>
> The goal is to let abrtd notice and process them as new problem data dirs.
> """
>
> import os
> +import sys
> import ConfigParser
> import StringIO
> import shutil
> import time
> import hashlib
> +import re
> +
> import problem
>
> -# Path to the vmcore directories
> -CORE_DIR = '/var/crash'
> +
> +def get_mount_point(part_id, filesystem):
> + """
> + A function used to look up a mount point in mtab using
> + the provided identifier.
> +
> + part_id - device node, label or uuid
> + filesystem - filesystem type of the mounted partition
> + """
> +
> + # look up the identifier in /etc/fstab
> + with open('/etc/mtab') as fs_table_file:
> + fs_table = fs_table_file.read()
> + regexp = re.compile(part_id + r'\s+(.*)\s+' + filesystem)
> + result = regexp.search(fs_table)
> + if result:
> + return result.group(1).strip()
> + else:
> + # identifier not in the table
> + sys.stderr.write("Error: Cannot access partition '" + part_id +
> + "', mount point not found! \n")
> + sys.exit(1)
> +
> +
> +def parse_kdump():
> + """
> + This function parses /etc/kdump.conf to get a path to kdump's
> + dump directory.
> + """
> +
> + # filesystem types that can be used by kdump for dumping
> + fs_types = ['ext4', 'ext3', 'ext2', 'minix', 'btrfs', 'xfs']
> +
> + with open('/etc/kdump.conf') as conf_file:
> + kdump_conf = conf_file.read()
> +
> + # first uncommented path instruction
> + regexp = re.compile('^(?<!#)path (.*)$', flags=8) # MULTILINE
> + result = regexp.search(kdump_conf)
> + if result:
> + dump_path = result.group(1).strip()
> + else:
> + # default
> + dump_path = '/var/crash'
> +
> + # default
> + partition = None
> + # first uncommented fs_type partition instruction
> + for fs_type in fs_types:
> + regexp = re.compile('^(?<!#)' + fs_type + ' (.*)$', flags=8)
> + result = regexp.search(kdump_conf)
> + if result:
> + partition = result.group(1)
> + filesystem = fs_type
> + break
> +
> + if partition:
> + if os.path.isabs(dump_path):
> + # path is absolute
> + sys.stderr.write("Path '" + dump_path + "' cannot be an absolute"
> + " path when mounting a dump partition.\n")
> + sys.exit(1)
> + mount_point = get_mount_point(partition, filesystem)
> + path = os.path.join(mount_point, dump_path)
> + else:
> + path = dump_path
> +
> + # full path to the dump directory
> + return path
>
>
> def write_to_file(path, content):
> @@ -102,20 +172,23 @@ def create_abrtd_info(dest):
>
> def harvest_vmcore():
> """
> - This function moves vmcore directories from /var/crash to a dump dir.
> + This function moves vmcore directories from kdump's dump dir
> + to abrt's dump dir and notifies abrt.
>
> The script also creates additional files used to tell abrt what kind of
> problem it is and creates an uuid from the vmcore using a sha1 hash
> function.
> """
>
> - if not os.path.exists('/etc/os-release'):
> - exit(0)
> + dump_dir = parse_kdump()
> +
> + if not os.path.exists(dump_dir):
> + sys.exit(0)
>
> # Wait for abrtd to start. Give it at least 1 second to initialize.
> for i in xrange(10):
> if i is 9:
> - exit(1)
> + sys.exit(1)
> elif os.system('pidof abrtd >/dev/null'):
> time.sleep(1)
> else:
> @@ -142,9 +215,9 @@ def harvest_vmcore():
> except ConfigParser.NoOptionError:
> abrtdumpdir = '@DEFAULT_DUMP_LOCATION@'
>
> - # Go through all directories in /var/crash
> - for cfile in os.listdir(CORE_DIR):
> - f_full = os.path.join(CORE_DIR, cfile)
> + # Go through all directories in core dump directory
> + for cfile in os.listdir(dump_dir):
> + f_full = os.path.join(dump_dir, cfile)
> if not os.path.isdir(f_full):
> continue
> files = [ff for ff in os.listdir(f_full)
--
Richard Marko
More information about the Crash-catcher
mailing list