Dont need atexit anymore since cleanup only closes tty_fd
This commit is contained in:
parent
e1504c4775
commit
434ef97952
@ -2,7 +2,6 @@
|
|||||||
# License: GPLv3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
import atexit
|
|
||||||
import base64
|
import base64
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
@ -49,7 +48,7 @@ def write_all(fd, data) -> None:
|
|||||||
data = data[n:]
|
data = data[n:]
|
||||||
|
|
||||||
|
|
||||||
def dcs_to_kitty(type, payload):
|
def dcs_to_kitty(payload, type='ssh'):
|
||||||
if isinstance(payload, str):
|
if isinstance(payload, str):
|
||||||
payload = payload.encode('utf-8')
|
payload = payload.encode('utf-8')
|
||||||
payload = base64.standard_b64encode(payload)
|
payload = base64.standard_b64encode(payload)
|
||||||
@ -57,12 +56,11 @@ def dcs_to_kitty(type, payload):
|
|||||||
|
|
||||||
|
|
||||||
def send_data_request():
|
def send_data_request():
|
||||||
write_all(tty_fd, dcs_to_kitty(
|
write_all(tty_fd, dcs_to_kitty('id=REQUEST_ID:pwfile=PASSWORD_FILENAME:pw=DATA_PASSWORD'))
|
||||||
'ssh', 'id=REQUEST_ID:pwfile=PASSWORD_FILENAME:pw=DATA_PASSWORD'))
|
|
||||||
|
|
||||||
|
|
||||||
def debug(msg):
|
def debug(msg):
|
||||||
data = dcs_to_kitty('print', 'debug: {}'.format(msg))
|
data = dcs_to_kitty('debug: {}'.format(msg), 'print')
|
||||||
if tty_fd == -1:
|
if tty_fd == -1:
|
||||||
with open(os.ctermid(), 'wb') as fl:
|
with open(os.ctermid(), 'wb') as fl:
|
||||||
write_all(fl.fileno(), data)
|
write_all(fl.fileno(), data)
|
||||||
@ -217,6 +215,7 @@ def main():
|
|||||||
global tty_fd, login_shell
|
global tty_fd, login_shell
|
||||||
tty_fd = os.open(os.ctermid(), os.O_RDWR | os.O_CLOEXEC)
|
tty_fd = os.open(os.ctermid(), os.O_RDWR | os.O_CLOEXEC)
|
||||||
try:
|
try:
|
||||||
|
if request_data:
|
||||||
send_data_request()
|
send_data_request()
|
||||||
get_data()
|
get_data()
|
||||||
finally:
|
finally:
|
||||||
@ -236,5 +235,4 @@ def main():
|
|||||||
os.execlp(login_shell, '-' + os.path.basename(login_shell))
|
os.execlp(login_shell, '-' + os.path.basename(login_shell))
|
||||||
|
|
||||||
|
|
||||||
atexit.register(cleanup)
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user