CPT: Fix Problems with exceptions

Failure in an exec_subprocess call will trigger cleanup,
but cleanup calls exec_subprocess, resulting in recursion.

Possible uninitialized variable in exec_subprocess_check_output.

Signed-off-by: Vassil Vassilev <vvasilev@cern.ch>
This commit is contained in:
Roman Zulak 2016-08-15 00:01:50 -04:00 committed by sftnight
parent eb624b555e
commit a7276f0df0

View File

@ -87,6 +87,7 @@ def exec_subprocess_call(cmd, cwd):
def exec_subprocess_check_output(cmd, cwd):
cmd = _convert_subprocess_cmd(cmd)
out = ''
try:
out = subprocess.check_output(cmd, cwd=cwd, shell=False,
stdin=subprocess.PIPE, stderr=subprocess.STDOUT).decode('utf-8')
@ -490,8 +491,14 @@ def tarball():
tar.add(prefix, arcname=os.path.basename(prefix))
tar.close()
gInCleanup = False
def cleanup():
global gInCleanup
if gInCleanup:
print('Failure in cleanup lead to recursion\n')
return
gInCleanup = True
print('\n')
if args['skip_cleanup']:
box_draw("Skipping cleanup")
@ -540,6 +547,7 @@ def cleanup():
if os.path.isdir(os.path.join(workdir, 'Install')):
print('Remove directory: ' + os.path.join(workdir, 'Install'))
shutil.rmtree(os.path.join(workdir, 'Install'))
gInCleanup = False
###############################################################################