From 07f08e997bc794bd717bb87f10b79c65497c3243 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Mon, 7 Apr 2014 20:27:01 +0100 Subject: [PATCH 02/17] Check tar exit status when creating archive Check the exit status of the tar process and abort without cleaning up if non-zero. Signed-off-by: Bryn M. Reeves --- sos/policyredhat.py | 19 +++++++++++++------ sos/sosreport.py | 7 ++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/sos/policyredhat.py b/sos/policyredhat.py index d19b9c2..7e6b2c1 100755 --- a/sos/policyredhat.py +++ b/sos/policyredhat.py @@ -265,22 +265,29 @@ class SosPolicy: print _("Creating compressed archive...") + status = 0 + cmd = "" if os.path.isfile("/usr/bin/xz"): self.report_file_ext = "tar.xz" self.renameResults("sosreport-%s-%s.%s" % (self.reportName, time.strftime("%Y%m%d%H%M%S"), self.report_file_ext)) cmd = "/bin/tar -cf- %s | /usr/bin/xz -1 > %s" % (os.path.basename(self.cInfo['dstroot']),self.report_file) - p = Popen(cmd, shell=True, bufsize=-1) - sts = os.waitpid(p.pid, 0)[1] else: self.report_file_ext = "tar.bz2" self.renameResults("sosreport-%s-%s.%s" % (self.reportName, time.strftime("%Y%m%d%H%M%S"), self.report_file_ext)) - tarcmd = "/bin/tar -jcf %s %s" % (self.report_file, os.path.basename(self.cInfo['dstroot'])) - p = Popen(tarcmd, shell=True, stdout=PIPE, stderr=PIPE, bufsize=-1) - output = p.communicate()[0] + cmd = "/bin/tar -jcf %s %s" % (self.report_file, os.path.basename(self.cInfo['dstroot'])) + + p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, bufsize=-1) + result = p.communicate() + + if p.returncode: + try: + os.unlink(self.report_file) + except: + pass os.umask(oldmask) os.chdir(curwd) - return + return p.returncode def cleanDstroot(self): if not os.path.isdir(os.path.join(self.cInfo['dstroot'],"sos_commands")): diff --git a/sos/sosreport.py b/sos/sosreport.py index e5c496e..d24cf3f 100755 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -858,7 +858,12 @@ No changes will be made to system configuration. return GlobalVars.dstroot # package up the results for the support organization - GlobalVars.policy.packageResults() + if GlobalVars.policy.packageResults(): + print + print _("Failed to create compressed archive.") + print + print _(" sosreport build tree is located at : %s" % (GlobalVars.dstroot,)) + return GlobalVars.dstroot # delete gathered files GlobalVars.policy.cleanDstroot() -- 1.9.3