From 46b2c0ee646577601d11fd94ecefd395ebaa78fb Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 3 Jul 2024 09:22:27 +0200 Subject: [PATCH] AppRun: restore TIO with sighandler Restore TIO always - the firejail doesn't always let UG exit gracefully (seems like there is some timeout), so restore this with the wrapping script. --- data/scripts/Linux-AppImage/AppRun | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/data/scripts/Linux-AppImage/AppRun b/data/scripts/Linux-AppImage/AppRun index a9dae8d85..9b3a5e6bf 100755 --- a/data/scripts/Linux-AppImage/AppRun +++ b/data/scripts/Linux-AppImage/AppRun @@ -303,14 +303,37 @@ expr,kill,ps,sed,seq,sh,tput,tr,tty,uname" fi } +# run only if Firejail is used to workaround not restored TIO by UG if FJ kills +# the UG process prematurelly; otherwise not needed (exec is used) +fj_sigaction() { + trap '' TERM # inhibit following signal to ourselves + if ps -o cmd >/dev/null 2>&1; then + pgid=$(ps -o pgid= -p $$ | tr -d ' ') + else # MSW dowsn't have "ps -o" + pgid=$$ + fi + if [ $$ -eq "$pgid" ]; then + kill -- -$$ + else + echo "pgid $pgid not pid of the script ($$), not sending kill" \ + >&2 + fi + trap - INT TERM + wait + stty "$stty_orig" + echo "Restored TIO" >&2 +} + run() { tool=$1 shift setup_firejail "$tool" export LD_LIBRARY_PATH="$n_ld_library_path" if [ -n "${fj_opt_file-}" ] && [ "$tool" != uv-qt ]; then + stty_orig=$(stty -g) + trap fj_sigaction INT TERM # shellcheck disable=SC2046 # intentional - eval exec $(cat "$fj_opt_file"; rm "$fj_opt_file") "$DIR/usr/bin/$tool" '"$@"' + eval $(cat "$fj_opt_file"; rm "$fj_opt_file") "$DIR/usr/bin/$tool" '"$@"' else exec "$DIR/usr/bin/$tool" "$@" fi