Previously os.listdir on inaccessible dump_dir resulted
in exception. This replaces insufficient os.path.exists check
(which is already handled in abrt-vmcore.service file) with
os.access call which checks for dir readability.
Also adding proper error handling for shutil calls later on.
Signed-off-by: Richard Marko <rmarko(a)redhat.com>
---
src/hooks/abrt_harvest_vmcore.py.in | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/src/hooks/abrt_harvest_vmcore.py.in b/src/hooks/abrt_harvest_vmcore.py.in
index 3951307..894dd47 100644
--- a/src/hooks/abrt_harvest_vmcore.py.in
+++ b/src/hooks/abrt_harvest_vmcore.py.in
@@ -186,8 +186,10 @@ def harvest_vmcore():
dump_dir = parse_kdump()
- if not os.path.exists(dump_dir):
- sys.exit(0)
+ if not os.access(dump_dir, os.R_OK):
+ sys.stderr.write("Dump directory '%s' not accessible. "
+ "Exiting.\n" % dump_dir)
+ sys.exit(1)
# Wait for abrtd to start. Give it at least 1 second to initialize.
for i in xrange(10):
@@ -219,8 +221,15 @@ def harvest_vmcore():
except ConfigParser.NoOptionError:
abrtdumpdir = '@DEFAULT_DUMP_LOCATION@'
+ try:
+ filelist = os.listdir(dump_dir)
+ except OSError:
+ sys.stderr.write("Dump directory '%s' not accessible. "
+ "Exiting.\n" % dump_dir)
+ sys.exit(1)
+
# Go through all directories in core dump directory
- for cfile in os.listdir(dump_dir):
+ for cfile in filelist:
f_full = os.path.join(dump_dir, cfile)
if not os.path.isdir(f_full):
continue
@@ -239,9 +248,22 @@ def harvest_vmcore():
# Copy/move vmcore directory to abrt spool dir.
# We use .new suffix - we must make sure abrtd doesn't try
# to process partially-copied directory.
- shutil.copytree(f_full, destdirnew)
+
+ try:
+ shutil.copytree(f_full, destdirnew)
+ except (OSError, shutil.Error):
+ sys.stderr.write("Unable to copy '%s' to '%s'.
Skipping"
+ % (f_full, destdirnew))
+
+ # delete .new dir so we don't create mess
+ shutil.rmtree(destdirnew)
+ continue
+
if copyvmcore == 'no':
- shutil.rmtree(f_full)
+ try:
+ shutil.rmtree(f_full)
+ except OSError:
+ sys.stderr.write("Unable to delete '%s'. Ignoring" %
f_full)
# Let abrtd know what type of problem it is:
create_abrtd_info(destdirnew)
--
1.8.3.1