def _killAllVBoxProcesses(self): """ Kills all virtual box related processes we find in the system. """ for iIteration in range(22): # Gather processes to kill. aoTodo = []; for oProcess in utils.processListAll(): sBase = oProcess.getBaseImageNameNoExeSuff(); if sBase is None: continue; sBase = sBase.lower(); if sBase in [ 'vboxsvc', 'virtualbox', 'virtualboxvm', 'vboxheadless', 'vboxmanage', 'vboxsdl', 'vboxwebsrv', 'vboxautostart', 'vboxballoonctrl', 'vboxbfe', 'vboxextpackhelperapp', 'vboxnetdhcp', 'vboxnetadpctl', 'vboxtestogl', 'vboxtunctl', 'vboxvmmpreload', 'vboxxpcomipcd', 'vmCreator', ]: aoTodo.append(oProcess); if sBase.startswith('virtualbox-') and sBase.endswith('-multiarch.exe'): aoTodo.append(oProcess); if iIteration in [0, 21] and sBase in [ 'windbg', 'gdb', 'gdb-i386-apple-darwin', ]: reporter.log('Warning: debugger running: %s (%s)' % (oProcess.iPid, sBase,)); if not aoTodo: return True; # Kill. for oProcess in aoTodo: reporter.log('Loop #%d - Killing %s (%s, uid=%s)' % ( iIteration, oProcess.iPid, oProcess.sImage if oProcess.sName is None else oProcess.sName, oProcess.iUid, )); utils.processKill(oProcess.iPid); # No mercy. # Check if they're all dead like they should be. time.sleep(0.1); for oProcess in aoTodo: if utils.processExists(oProcess.iPid): time.sleep(2); break; return False;
def _killAllVBoxProcesses(self): """ Kills all virtual box related processes we find in the system. """ sHostOs = utils.getHostOs() asDebuggers = [ 'cdb', 'windbg', ] if sHostOs == 'windows' else [ 'gdb', 'gdb-i386-apple-darwin', 'lldb' ] for iIteration in range(22): # Gather processes to kill. aoTodo = [] aoDebuggers = [] for oProcess in utils.processListAll(): sBase = oProcess.getBaseImageNameNoExeSuff() if sBase is None: continue sBase = sBase.lower() if sBase in [ 'vboxsvc', 'vboxsds', 'virtualbox', 'virtualboxvm', 'vboxheadless', 'vboxmanage', 'vboxsdl', 'vboxwebsrv', 'vboxautostart', 'vboxballoonctrl', 'vboxbfe', 'vboxextpackhelperapp', 'vboxnetdhcp', 'vboxnetnat', 'vboxnetadpctl', 'vboxtestogl', 'vboxtunctl', 'vboxvmmpreload', 'vboxxpcomipcd', ]: aoTodo.append(oProcess) if sBase.startswith('virtualbox-') and sBase.endswith( '-multiarch.exe'): aoTodo.append(oProcess) if sBase in asDebuggers: aoDebuggers.append(oProcess) if iIteration in [0, 21]: reporter.log('Warning: debugger running: %s (%s %s)' % (oProcess.iPid, sBase, oProcess.asArgs)) if not aoTodo: return True # Are any of the debugger processes hooked up to a VBox process? if sHostOs == 'windows': # On demand debugging windows: windbg -p <decimal-pid> -e <decimal-event> -g for oDebugger in aoDebuggers: for oProcess in aoTodo: # The whole command line is asArgs[0] here. Fix if that changes. if oDebugger.asArgs and oDebugger.asArgs[0].find( '-p %s ' % (oProcess.iPid, )) >= 0: aoTodo.append(oDebugger) break else: for oDebugger in aoDebuggers: for oProcess in aoTodo: # Simplistic approach: Just check for argument equaling our pid. if oDebugger.asArgs and ( '%s' % oProcess.iPid) in oDebugger.asArgs: aoTodo.append(oDebugger) break # Kill. for oProcess in aoTodo: reporter.log('Loop #%d - Killing %s (%s, uid=%s)' % ( iIteration, oProcess.iPid, oProcess.sImage if oProcess.sName is None else oProcess.sName, oProcess.iUid, )) if not utils.processKill(oProcess.iPid) \ and sHostOs != 'windows' \ and utils.processExists(oProcess.iPid): # Many of the vbox processes are initially set-uid-to-root and associated debuggers are running # via sudo, so we might not be able to kill them unless we sudo and use /bin/kill. try: utils.sudoProcessCall( ['/bin/kill', '-9', '%s' % (oProcess.iPid, )]) except: reporter.logXcpt() # Check if they're all dead like they should be. time.sleep(0.1) for oProcess in aoTodo: if utils.processExists(oProcess.iPid): time.sleep(2) break return False