From 08500cfcbb91cda09c6790b916ba97c333cf2df9 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 12 Nov 2026 20:01:47 +0000 Subject: populate: stop the ssh master also when a signal ends populate The shell doesn't run the EXIT trap when a signal ends it, so an interrupted deploy leaves the ssh master, for an hour, and populate's temporary directory. Populate traps HUP, INT, and TERM and exits, which runs the EXIT trap. The shell runs a trap once the command it waits for ends. A signal to the process group, like the one of an interrupt key, of a closed terminal, or of timeout, ends that command as well. A signal to populate alone takes effect after the step that is running. Phases of scenarios can end populate after some seconds. An edge case does so while a pipe source's command sleeps, and checks that neither the ssh master nor the temporary directory remain. --- pkgs/populate/default.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'pkgs') diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix index c8229fb..97c2c4b 100644 --- a/pkgs/populate/default.nix +++ b/pkgs/populate/default.nix @@ -1338,7 +1338,15 @@ writers.writeDash "populate.${target.host}" '' ${ssh' target} -q -O stop ${quote target.host} fi } - trap 'stop_ssh_master; rm -R "$TMPDIR"' EXIT + trap 'trap "" HUP INT TERM; stop_ssh_master; rm -R "$TMPDIR"' EXIT + # A signal ends the shell without running the trap above, unless it's + # trapped itself. The shell runs these traps once the command it waits + # for ends, which a signal to the process group, like the one of an + # interrupt key, ends as well. Further signals get ignored, so they + # don't end the trap above halfway. + trap 'trap "" HUP INT TERM; exit 129' HUP + trap 'trap "" HUP INT TERM; exit 130' INT + trap 'trap "" HUP INT TERM; exit 143' TERM ${check { inherit force target; }} set -x -- cgit v1.3.1