From 052d16aa49bc7353256eb363786703cff7066a8b Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 5 Jul 2023 11:40:00 -0400 Subject: [PATCH] Avoid modifying PYTHONPATH Since there's a possibility of cross-python invocation, avoid modifying PYTHONPATH --- confluent_server/confluent/networking/macmap.py | 5 ++++- confluent_server/confluent/osimage.py | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/confluent_server/confluent/networking/macmap.py b/confluent_server/confluent/networking/macmap.py index c760dcda..a9c6b86a 100644 --- a/confluent_server/confluent/networking/macmap.py +++ b/confluent_server/confluent/networking/macmap.py @@ -208,7 +208,6 @@ def _offload_map_switch(switch, password, user): def _start_offloader(): global _offloader - os.environ['PYTHONPATH'] = ':'.join(sys.path) _offloader = subprocess.Popen( [sys.executable, __file__, '-o'], bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE) @@ -691,6 +690,10 @@ def rescan(cfg): if __name__ == '__main__': + path = os.path.dirname(os.path.realpath(__file__)) + path = os.path.realpath(os.path.join(path, '..', 'lib', 'python')) + if path.startswith('/opt'): + sys.path.append(path) if len(sys.argv) > 1 and sys.argv[1] == '-o': try: upacker = msgpack.Unpacker(encoding='utf8') diff --git a/confluent_server/confluent/osimage.py b/confluent_server/confluent/osimage.py index 22e26562..c6454235 100644 --- a/confluent_server/confluent/osimage.py +++ b/confluent_server/confluent/osimage.py @@ -861,7 +861,6 @@ class MediaImporter(object): return {'phase': self.phase, 'progress': self.percent, 'profiles': self.profiles, 'error': self.error} def importmedia(self): - os.environ['PYTHONPATH'] = ':'.join(sys.path) if self.medfile: os.environ['CONFLUENT_MEDIAFD'] = '{0}'.format(self.medfile.fileno()) with open(os.devnull, 'w') as devnull: @@ -931,8 +930,13 @@ def get_importing_status(importkey): if __name__ == '__main__': os.umask(0o022) + path = os.path.dirname(os.path.realpath(__file__)) + path = os.path.realpath(os.path.join(path, '..', 'lib', 'python')) + if path.startswith('/opt'): + sys.path.append(path) if len(sys.argv) > 2: mfd = os.environ.get('CONFLUENT_MEDIAFD', None) sys.exit(import_image(sys.argv[1], callback=printit, backend=True, mfd=mfd)) else: sys.exit(import_image(sys.argv[1], callback=printit)) +