From eab825a40d0fb20b067b2043b4d72a0f1d5058b3 Mon Sep 17 00:00:00 2001 From: illiliti Date: Sun, 1 Mar 2020 16:25:52 +0300 Subject: [PATCH] fix trap signals --- tinyramfs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tinyramfs b/tinyramfs index 26ccdb1..9571ec3 100755 --- a/tinyramfs +++ b/tinyramfs @@ -439,14 +439,20 @@ create_initramfs() { parse_args "$@" parse_conf -# remove workdir on exit -trap remove_workdir EXIT +# remove workdir on signals +# we are doing unset EXIT signal to avoid endless loop +# because afterwards we execute 'exit' command. +# also some shells (dash,mksh,etc) doesn't exit on INT +# signal. as workaround we manually execute exit command. +# tested bash,dash,mksh,busybox sh +# TODO fix zsh, ref https://www.zsh.org/mla/users/2015/msg00436.html +trap "remove_workdir && trap - EXIT && exit" EXIT INT TERM HUP [ "$debug" = 1 ] && { # debug shell commands set -x # don't remove anything - trap - EXIT + trap - EXIT INT TERM HUP } create_workdir