summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/vpn/process.py
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2017-06-01 02:55:05 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2017-06-01 02:55:05 +0200
commit2db7202e6c3a520a5b6fe395dd74d40d8e53c481 (patch)
treeabe64597254360a130692eaa65780990f43a12a5 /src/leap/bitmask/vpn/process.py
parent6f02e93d436f8c36f80453a042e406a041d24c4f (diff)
[refactor] hide mac/linux switch inside process module
Diffstat (limited to 'src/leap/bitmask/vpn/process.py')
-rw-r--r--src/leap/bitmask/vpn/process.py75
1 files changed, 42 insertions, 33 deletions
diff --git a/src/leap/bitmask/vpn/process.py b/src/leap/bitmask/vpn/process.py
index 429b7b75..895cd0a2 100644
--- a/src/leap/bitmask/vpn/process.py
+++ b/src/leap/bitmask/vpn/process.py
@@ -33,13 +33,14 @@ from leap.bitmask.vpn import _status
from leap.bitmask.vpn import _management
from leap.bitmask.vpn.launchers import darwin
+from leap.bitmask.vpn.constants import IS_MAC, IS_LINUX
# OpenVPN verbosity level - from flags.py
OPENVPN_VERBOSITY = 1
-class VPNProcess(protocol.ProcessProtocol, _management.VPNManagement):
+class _VPNProcess(protocol.ProcessProtocol, _management.VPNManagement):
"""
A ProcessProtocol class that can be used to spawn a process that will
@@ -233,41 +234,49 @@ class VPNProcess(protocol.ProcessProtocol, _management.VPNManagement):
self.log.debug('Process Exited Already')
-class VPNCanary(VPNProcess):
+if IS_LINUX:
- """
- Special form of the VPNProcess, for Darwin Launcher (windows might use same
- strategy).
-
- This is a Canary Process that does not run openvpn itself, but it's
- notified by the privileged process when the process dies.
+ VPNProcess = _VPNProcess
- This is a workaround to allow the state machine to be notified when openvpn
- process is spawned by the privileged helper.
- """
- def setupHelper(self):
- self.helper = darwin.HelperCommand()
-
- def connectionMade(self):
- VPNProcess.connectionMade(self)
- reactor.callLater(2, self.registerPID)
+elif IS_MAC:
- def registerPID(self):
- cmd = 'openvpn_set_watcher %s' % self.pid
- self.helper.send(cmd)
+ class _VPNCanary(_VPNProcess):
- def killProcess(self):
- cmd = 'openvpn_force_stop'
- self.helper.send(cmd)
+ """
+ Special form of _VPNProcess, for Darwin Launcher (windows might use
+ same strategy).
- def getVPNCommand(self):
- return VPNProcess.getCommand(self)
+ This is a Canary Process that does not run openvpn itself, but it's
+ notified by the privileged process when the process dies.
- def getCommand(self):
- canary = '''import sys, signal, time
-def receive_signal(signum, stack):
- sys.exit()
-signal.signal(signal.SIGTERM, receive_signal)
-while True:
- time.sleep(60)'''
- return ['python', '-c', '%s' % canary]
+ This is a workaround to allow the state machine to be notified when
+ openvpn process is spawned by the privileged helper.
+ """
+ def setupHelper(self):
+ self.helper = darwin.HelperCommand()
+
+ def connectionMade(self):
+ VPNProcess.connectionMade(self)
+ reactor.callLater(2, self.registerPID)
+
+ def registerPID(self):
+ cmd = 'openvpn_set_watcher %s' % self.pid
+ self.helper.send(cmd)
+
+ def killProcess(self):
+ cmd = 'openvpn_force_stop'
+ self.helper.send(cmd)
+
+ def getVPNCommand(self):
+ return VPNProcess.getCommand(self)
+
+ def getCommand(self):
+ canary = '''import sys, signal, time
+ def receive_signal(signum, stack):
+ sys.exit()
+ signal.signal(signal.SIGTERM, receive_signal)
+ while True:
+ time.sleep(60)'''
+ return ['python', '-c', '%s' % canary]
+
+ VPNProcess = _VPNCanary