From a40f05260af1e3e722b55caa7ab9c24fc82b0e96 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 9 May 2024 08:42:41 +0000 Subject: [PATCH] unl0kr: simplify the crash edge-case handling --- hosts/common/programs/unl0kr/default.nix | 12 +----------- hosts/common/programs/unl0kr/redirect-tty | 11 +---------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/hosts/common/programs/unl0kr/default.nix b/hosts/common/programs/unl0kr/default.nix index 522c8894e..f908cfd9a 100644 --- a/hosts/common/programs/unl0kr/default.nix +++ b/hosts/common/programs/unl0kr/default.nix @@ -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} ''; }; diff --git a/hosts/common/programs/unl0kr/redirect-tty b/hosts/common/programs/unl0kr/redirect-tty index ecba19b9b..2b1b612bd 100755 --- a/hosts/common/programs/unl0kr/redirect-tty +++ b/hosts/common/programs/unl0kr/redirect-tty @@ -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__":