From 2d7543e8c3828a8a0ab7b77b1c3a492c7ff28ed7 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 22 Aug 2017 23:15:38 -0400 Subject: [refactor] move terminate_or_kill to linux launcher --- src/leap/bitmask/vpn/process.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/leap/bitmask/vpn/process.py') diff --git a/src/leap/bitmask/vpn/process.py b/src/leap/bitmask/vpn/process.py index 0ba4b85a..48d3f1ad 100644 --- a/src/leap/bitmask/vpn/process.py +++ b/src/leap/bitmask/vpn/process.py @@ -22,11 +22,10 @@ A custom processProtocol launches the VPNProcess and connects to its management interface. """ +import os import shutil import sys -import psutil - from twisted.internet import protocol, reactor, defer from twisted.internet import error as internet_error from twisted.internet.endpoints import clientFromString, connectProtocol @@ -53,7 +52,8 @@ class _VPNProcess(protocol.ProcessProtocol): log = Logger() # HACK - reactor is expected to set this up when the process is spawned. - # should try to get it from within this class. + # should try to get it from the management protocol instead. + # XXX or, at least, we can check if they match. pid = None # TODO do we really need the vpnconfig/providerconfig objects in here??? @@ -82,6 +82,7 @@ class _VPNProcess(protocol.ProcessProtocol): reactor, b"unix:path=%s" % socket_host) else: raise ValueError('tcp endpoint not configured') + self._vpnconfig = vpnconfig self._providerconfig = providerconfig self._launcher = get_vpn_launcher() @@ -115,7 +116,6 @@ class _VPNProcess(protocol.ProcessProtocol): self._d.addErrback(self.log.error) def connectionMade(self): - self.aborted = False # TODO cut this wait time when retries are done reactor.callLater(0.5, self._connect_to_management) @@ -135,6 +135,9 @@ class _VPNProcess(protocol.ProcessProtocol): # TODO: need to exit properly! status, errmsg = 'off', None + # TODO ---- propagate this status upwards!! + # XXX do something with status + def processEnded(self, reason): """ Called when the child process exits and all file descriptors associated @@ -226,6 +229,11 @@ class _VPNProcess(protocol.ProcessProtocol): except internet_error.ProcessExitedAlready: self.log.debug('Process Exited Already') + def terminate_or_kill(self): + # XXX this returns a deferred + return self._launcher.terminate_or_kill( + self.terminate, self.kill, self) + if IS_LINUX: -- cgit v1.2.3