From a6c587edad293996e4015876d7e59432d6a4e8ea Mon Sep 17 00:00:00 2001 From: antialias Date: Mon, 15 Oct 2012 12:28:54 -0400 Subject: attempts to stop exisiting instances of openvpn when discovered at start up. --- src/leap/eip/openvpnconnection.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/leap/eip/openvpnconnection.py b/src/leap/eip/openvpnconnection.py index 96df4f1d..d93bc40f 100644 --- a/src/leap/eip/openvpnconnection.py +++ b/src/leap/eip/openvpnconnection.py @@ -168,7 +168,9 @@ to be triggered for each one of them. for process in psutil.get_process_list(): if process.name == "openvpn": logger.debug('an openvpn instance is already running.') - raise eip_exceptions.OpenVPNAlreadyRunning + logger.debug('attempting to stop openvpn instance.') + if not self._stop(): + raise eip_exceptions.OpenVPNAlreadyRunning logger.debug('no openvpn instance found.') @@ -190,7 +192,34 @@ to be triggered for each one of them. logger.debug("disconnecting...") self._send_command("signal SIGTERM\n") - # + if self.subp: + return True + + #shutting openvpn failured + #try patching in old openvpn host and trying again + process = self._get_openvpn_process() + if process: + self.host = \ + process.cmdline[process.cmdline.index("--management") + 1] + self._send_command("signal SIGTERM\n") + + #make sure the process was terminated + process = self._get_openvpn_process() + if not process: + logger.debug("Exisiting OpenVPN Process Terminated") + return True + else: + logger.error("Unable to terminate exisiting OpenVPN Process.") + return False + + return True + + def _get_openvpn_process(self): + for process in psutil.get_process_list(): + if process.name == "openvpn": + return process + return None + # management methods # # XXX REVIEW-ME -- cgit v1.2.3