|
From: <st...@us...> - 2007-10-09 11:44:29
|
Revision: 548
http://safekeep.svn.sourceforge.net/safekeep/?rev=548&view=rev
Author: stelian
Date: 2007-10-09 04:44:27 -0700 (Tue, 09 Oct 2007)
Log Message:
-----------
Better error handling and logging in spawn()
Modified Paths:
--------------
safekeep/trunk/safekeep
Modified: safekeep/trunk/safekeep
===================================================================
--- safekeep/trunk/safekeep 2007-10-09 11:43:58 UTC (rev 547)
+++ safekeep/trunk/safekeep 2007-10-09 11:44:27 UTC (rev 548)
@@ -78,13 +78,30 @@
def spawn(args):
if isinstance(args, str) or isinstance(args, unicode):
debug('Run [' + args + ']')
+ cmd = args.split(' ')[0]
else:
debug('Run [' + ' '.join(args) + ']')
- (cout, cin) = popen2.popen4(args)
- cin.close()
- for line in cout:
+ cmd = args[0]
+ proc = popen2.Popen4(args)
+ proc.tochild.close()
+ for line in proc.fromchild:
info(line.rstrip())
- cout.close()
+ proc.fromchild.close()
+ rc = proc.wait()
+ if os.WIFEXITED(rc):
+ if os.WEXITSTATUS(rc) == 0:
+ ret = None
+ else:
+ ret = 'exited with non zero status: %d' % os.WEXITSTATUS(rc)
+ elif os.WIFSIGNALED(rc):
+ ret = 'killed by signal: %d' % os.WTERMSIG(rc)
+ elif os.WCOREDUMP(rc):
+ ret = 'coredumped'
+ else:
+ ret = 'unknown exit status: %d' + rc
+ if ret:
+ error('%s failed: %s' % (cmd, ret));
+ return ret
def send_notification(email, smtp):
info('Sending email to %s via %s' % (','.join(email), smtp))
@@ -394,7 +411,7 @@
continue
ret = spawn(['umount', snapmnt])
if ret:
- warn('umount %s returned %s' % (snapmnt, ret))
+ warn('Can not umount the snapshot: %s' % snapmnt)
ret = spawn(['lvremove', '--force', snapdev])
if ret:
warn('Can not tear down snapshot: ' + device)
@@ -427,7 +444,7 @@
bdir = tempfile.mkdtemp("-rbind", "safekeep-", "/mnt")
ret = spawn(['mount', '--rbind', '/', bdir])
if ret:
- warn('mount --rbind failed with %d, snapshotting will be disabled' % ret)
+ warn('mount --rbind failed, snapshotting will be disabled')
try:
os.rmdir(bdir)
except Exception, e:
@@ -537,7 +554,7 @@
args.extend([userhost + '::' + bdir, cfg['dir']])
ret = spawn(args)
if ret:
- raise Exception('rdiff-backup returned %d' % ret)
+ raise Exception('Failed to run rdiff-backup')
def do_server_data_cleanup(cfg):
args = ['rdiff-backup', '--force', '--remove-older-than', cfg['retention'], cfg['dir']]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|