Flush the write to shm explicitly

This commit is contained in:
Kovid Goyal 2022-03-10 15:01:58 +05:30
parent 4013544efb
commit f67009f554
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 2 deletions

View File

@ -129,7 +129,7 @@ def make_tarfile(ssh_opts: SSHOptions, base_env: Dict[str, str], compression: st
if ksi:
arcname = 'home/' + rd + '/shell-integration'
tf.add(shell_integration_dir, arcname=arcname, filter=filter_from_globs(
f'{arcname}/ssh/bootstrap.*', # bootstrap files are sent as command line args
f'{arcname}/ssh/*', # bootstrap files are sent as command line args
f'{arcname}/zsh/kitty.zsh', # present for legacy compat not needed by ssh kitten
))
tf.add(terminfo_dir, arcname='home/.terminfo', filter=normalize_tarinfo)
@ -234,6 +234,7 @@ def bootstrap_script(
with SharedMemory(size=len(db) + len(sz), mode=stat.S_IREAD, prefix=f'kssh-{os.getpid()}-') as shm:
shm.write(sz)
shm.write(db)
shm.flush()
atexit.register(shm.unlink)
replacements = {
'DATA_PASSWORD': pw, 'PASSWORD_FILENAME': shm.name, 'EXEC_CMD': exec_cmd, 'TEST_SCRIPT': test_script,

View File

@ -46,8 +46,9 @@ class SharedMemory:
def __init__(
self, name: str = '', size: int = 0, readonly: bool = False,
mode: int = stat.S_IREAD | stat.S_IWRITE,
prefix: str = 'kitty-'
prefix: str = 'kitty-', unlink_on_exit: bool = False
):
self.unlink_on_exit = unlink_on_exit
if size < 0:
raise TypeError("'size' must be a non-negative integer")
if size and name:
@ -100,6 +101,9 @@ class SharedMemory:
def seek(self, pos: int, whence: int = os.SEEK_SET) -> None:
self.mmap.seek(pos, whence)
def flush(self) -> None:
self.mmap.flush()
def __del__(self) -> None:
try:
self.close()
@ -111,6 +115,8 @@ class SharedMemory:
def __exit__(self, *a: object) -> None:
self.close()
if self.unlink_on_exit:
self.unlink()
@property
def size(self) -> int: