Commit c7ebe964 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

portredir: Raise exception if socat executable is not found

parent d030388c
......@@ -10,13 +10,6 @@ from zope import interface
logger = logging.getLogger(__name__)
def which(exename):
for path in os.environ["PATH"].split(os.pathsep):
full_path = os.path.join(path, exename)
if os.path.exists(full_path):
return full_path
return None
class Manager(object):
interface.implements(IManager)
......
......@@ -16,6 +16,7 @@ def _format_ip_addr(ip_addr):
return str(ip_addr)
def which(exename):
# BBB: In Python 3, shutil.which must be used
for path in os.environ["PATH"].split(os.pathsep):
full_path = os.path.join(path, exename)
if os.path.exists(full_path):
......@@ -127,7 +128,10 @@ class Manager(object):
logger.warning('Bad source address provided', exc_info=True)
continue
command = [which('socat')]
socat_path = which('socat')
if not socat_path:
raise OSError("Path to socat executable does not exist")
command = [socat_path]
socat_source_version = source_addr.version if source_addr is not None else 4
socat_source_type = '{rtype}{version}-LISTEN'.format(rtype=redir_type.upper(), version=socat_source_version)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment