Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
moreati committed Feb 5, 2025
1 parent a3768a0 commit 8572c9f
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions mitogen/parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,10 +1385,6 @@ def __repr__(self):
# with a custom argv.
# * Optimized for minimum byte count after minification & compression.
# The script preamble_size.py measures this.
# * 'CONTEXT_NAME' and 'PREAMBLE_COMPRESSED_LEN' are substituted with
# their respective values.
# * CONTEXT_NAME must be prefixed with the name of the Python binary in
# order to allow virtualenvs to detect their install prefix.
#
# macOS tweaks for Python 2.7 must be kept in sync with the the Ansible
# module test_echo_module, used by the integration tests.
Expand Down Expand Up @@ -1427,10 +1423,10 @@ def _first_stage():
if os.uname()[0]=='Darwin'and os.uname()[2][:2]<'19'and sys.executable=='/usr/bin/python':sys.executable='/usr/bin/python2.7'
if os.uname()[0]=='Darwin'and os.uname()[2][:2]in'2021'and sys.version[:3]=='2.7':os.environ['PYTHON_LAUNCHED_FROM_WRAPPER']='1'
os.environ['ARGV0']=sys.executable
os.execl(sys.executable,sys.executable+'(mitogen:CONTEXT_NAME)')
os.execl(sys.executable,'%s(mitogen:%s)'%(sys.executable,sys.argv[2]))
os.write(1,'MITO000\n'.encode())
fp=os.fdopen(0,'rb')
C=zlib.decompress(fp.read(PREAMBLE_COMPRESSED_LEN))
C=zlib.decompress(fp.read(int(sys.argv[3])))
fp.close()
fp=os.fdopen(W,'wb',0)
fp.write(C)
Expand Down Expand Up @@ -1458,10 +1454,6 @@ def get_boot_command(self):
source = inspect.getsource(self._first_stage)
source = textwrap.dedent('\n'.join(source.strip().split('\n')[2:]))
source = source.replace(' ', ' ')
source = source.replace('CONTEXT_NAME', self.options.remote_name)
preamble_compressed = self.get_preamble()
source = source.replace('PREAMBLE_COMPRESSED_LEN',
str(len(preamble_compressed)))
compressed = zlib.compress(source.encode(), 9)
encoded = binascii.b2a_base64(compressed).replace(b('\n'), b(''))

Expand All @@ -1472,7 +1464,10 @@ def get_boot_command(self):
return self.get_python_argv() + [
'-c',
'import sys;sys.path=[p for p in sys.path if p];import binascii,os,zlib;'
'exec(zlib.decompress(binascii.a2b_base64("%s")))' % (encoded.decode(),),
'exec(zlib.decompress(binascii.a2b_base64(sys.argv[1])))',
encoded.decode(),
self.options.remote_name,
str(len(self.get_preamble())),
]

def get_econtext_config(self):
Expand Down

0 comments on commit 8572c9f

Please sign in to comment.