From 3f54dfa4755613dbd3098814a9ab07cb977ca347 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Sat, 2 Jul 2022 12:51:12 +0200 Subject: treewide: fix bash exit handlers Transform exit handlers of the form trap cleanup EXIT [INT] [TERM] [QUIT] [HUP] [ERR] (where cleanup is idempotent) to trap cleanup EXIT This fixes a common bash antipattern. Each of the above signals causes the script to exit. For each signal, bash first handles the signal by running `cleanup` and then runs `cleanup` again when handling EXIT. (Exception: `vscode/*` prevents the second run of `cleanup` by removing the trap in cleanup`). Simplify the cleanup logic by just trapping exit, which is always run when the script exits due to any of the above signals. Note: In case of borgbackup, the exit handler is not idempotent, but just trapping EXIT guarantees that it's only run once. --- .../editors/vscode/extensions/_maintainers/update-bin-srcs-lib.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'pkgs/applications/editors/vscode/extensions/_maintainers') diff --git a/pkgs/applications/editors/vscode/extensions/_maintainers/update-bin-srcs-lib.sh b/pkgs/applications/editors/vscode/extensions/_maintainers/update-bin-srcs-lib.sh index 6a8968024c886..4b0ca54da3620 100755 --- a/pkgs/applications/editors/vscode/extensions/_maintainers/update-bin-srcs-lib.sh +++ b/pkgs/applications/editors/vscode/extensions/_maintainers/update-bin-srcs-lib.sh @@ -39,11 +39,10 @@ prefetchExtensionUnpacked() { function rm_tmpdir() { 1>&2 printf "rm -rf %q\n" "$tmpDir" rm -rf "$tmpDir" - trap - INT TERM HUP EXIT } function make_trapped_tmpdir() { tmpDir=$(mktemp -d) - trap rm_tmpdir INT TERM HUP EXIT + trap rm_tmpdir EXIT } 1>&2 echo -- cgit 1.4.1