1.1 --- a/OpenSecurity/bin/cygwin.py Fri Feb 21 11:04:04 2014 +0100
1.2 +++ b/OpenSecurity/bin/cygwin.py Wed Feb 26 17:27:07 2014 +0100
1.3 @@ -123,35 +123,47 @@
1.4 #executes command on host system
1.5 @staticmethod
1.6 def execute(program, arguments, wait_return=True, window = False):
1.7 - if Cygwin.executeLock.acquire(True):
1.8 - _startupinfo = STARTUPINFO()
1.9 - if not window:
1.10 - _startupinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW
1.11 - _startupinfo.wShowWindow = _subprocess.SW_HIDE
1.12 + _startupinfo = STARTUPINFO()
1.13 + if not window:
1.14 + _startupinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW
1.15 + _startupinfo.wShowWindow = _subprocess.SW_HIDE
1.16
1.17 - #logger.debug('trying to launch: ' + program + ' ' + ''.join(arguments))
1.18 - try:
1.19 - process = Popen(executable=program, args=' ' + arguments, startupinfo = _startupinfo, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell = False)
1.20 - logger.debug('Launched: ' + program + ' ' + ''.join(arguments))
1.21 - if not wait_return:
1.22 - return [0, 'working in background', '']
1.23 - result = process.wait()
1.24 - res_stdout = process.stdout.read();
1.25 - res_stderr = process.stderr.read();
1.26 - #if res_stdout != "":
1.27 - # logger.debug(res_stdout)
1.28 - #if res_stderr != "":
1.29 - # logger.debug(res_stderr)
1.30 - except:
1.31 - logger.error('Failed to execute cygwin command.\n\tcommand=' + program + ' ' + ''.join(arguments) + '\n')
1.32 - #TODO: throw exception
1.33 -
1.34 - Cygwin.executeLock.release()
1.35 + #logger.debug('trying to launch: ' + program + ' ' + ''.join(arguments))
1.36 + res_stderr = None
1.37 + try:
1.38 + process = Popen(executable=program, args=' ' + arguments, startupinfo = _startupinfo, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell = False)
1.39 + logger.debug('Launched: ' + program + ' ' + ''.join(arguments))
1.40 + if not wait_return:
1.41 + return [0, 'working in background', '']
1.42 + result = process.wait()
1.43 + res_stdout = process.stdout.read();
1.44 + res_stderr = process.stderr.read();
1.45 +
1.46 + except Exception as ex:
1.47 + res_stderr = ''.join(ex.args)
1.48 + result = -1
1.49 +
1.50 + if result != 0:
1.51 + logger.error('Failed to execute cygwin command.\n\tcommand=' + program + ' ' + ''.join(arguments) + '\n' + res_stderr)
1.52 + raise OpenSecurityException('Failed to execute cygwin command.\n\tcommand=' + program + ' ' + ''.join(arguments) + '\n' + res_stderr)
1.53 +
1.54 return result, res_stdout, res_stderr
1.55
1.56 @staticmethod
1.57 def vboxExecute(command, wait_return=True, window = False, bash_opts=''):
1.58 - return Cygwin.execute(Cygwin.vbox_man, command, wait_return, window)
1.59 + if Cygwin.executeLock.acquire(True):
1.60 + retry = 0
1.61 + while retry < 3:
1.62 + try:
1.63 + result = Cygwin.execute(Cygwin.vbox_man, command, wait_return, window)
1.64 + Cygwin.executeLock.release()
1.65 + return result
1.66 + except OpenSecurityException as inst:
1.67 + retry+=1
1.68 + Cygwin.executeLock.release()
1.69 + raise inst
1.70 + return result
1.71 +
1.72
1.73 @staticmethod
1.74 def bashExecute(command, wait_return=True, window = False, bash_opts=''):