unl0kr: simplify the crash edge-case handling

This commit is contained in:
2024-05-09 08:42:41 +00:00
parent 2b539fafcd
commit a40f05260a
2 changed files with 2 additions and 21 deletions

View File

@@ -25,17 +25,7 @@ let
# but modified to not leak pword to CLI
# - implement some sort of watchdog (e.g. detect spawned children?)
# - set a timeout at the outer scope (which gets canceled upon successful login)
# eval 'redirect-tty "/dev/${tty}" unl0kr ; sleep 5 ; redirect-tty "/dev/${tty}" echo ""' &
# redirect-tty "/dev/${tty}" unl0kr &
# unl0kr_pid=$!
# # login -p: preserve environment
# login -p ${cfg.config.user} &
# login_pid=$!
# # wait for unl0kr, and if it succeeds then hand control fully to `login`.
# # otherwise, exit, implicitly killing `login` and probably restarting the service
# wait "$unl0kr_pid" && wait "$login_pid"
redirect-tty "/dev/${tty}" unl0kr &
bash -c 'redirect-tty "/dev/${tty}" unl0kr ; sleep 2 ; redirect-tty "/dev/${tty}" echo ""' &
login -p ${cfg.config.user}
'';
};

View File

@@ -13,7 +13,6 @@ import fcntl
import subprocess
import sys
import termios
import time
def write_to(text: bytes, dest_path: str) -> None:
with open(dest_path, "w") as f:
@@ -24,15 +23,7 @@ def main(argv: list[str]):
dest_path = argv[1]
cmd = argv[2:]
try:
cmd_output = subprocess.check_output(cmd)
except Exception as e:
# command failed, somehow.
# sleep, to ensure `login` has some time to start
# then send it an empty newline to force it to fail
time.sleep(1)
write_to(b"\n", dest_path)
raise
cmd_output = subprocess.check_output(cmd)
write_to(cmd_output, dest_path)
if __name__ == "__main__":