From 114a598fb4316c8e6ef60c3b6300ecdb6f35aa5d Mon Sep 17 00:00:00 2001 From: Nick Gravgaard Date: Tue, 1 Jul 2014 15:09:23 +0000 Subject: [PATCH] Get stderr when running clamdscan Previously, when clamdscan's had an error we haven't had any information about what went wrong. This should address that. --- backdrop/admin/scanned_file.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backdrop/admin/scanned_file.py b/backdrop/admin/scanned_file.py index 68b0af2d..32bf30e0 100644 --- a/backdrop/admin/scanned_file.py +++ b/backdrop/admin/scanned_file.py @@ -1,6 +1,6 @@ import hashlib -import subprocess import os +from subprocess import Popen, PIPE class VirusSignatureError(StandardError): @@ -30,7 +30,10 @@ def _scan_file(self): self._clamscan(self._file_path)) def _clamscan(self, filename): - retcode = subprocess.call(["clamdscan", filename]) + args = ['clamdscan', filename] + proc = Popen(args, stdout=PIPE, stderr=PIPE) + _, stderrdata = proc.communicate() + retcode = proc.returncode # 0 : No virus found. # 1 : Virus(es) found. # 2 : An error occured. @@ -39,7 +42,8 @@ def _clamscan(self, filename): elif retcode == 1: return True elif retcode == 2: - raise SystemError('Error running the clamdscan virus scanner') + raise SystemError('Error running the clamdscan virus scanner. ' + 'Stderr was "{}"'.format(stderrdata)) def _clean_up(self): # Remove temporary file