From 9305daa2e1c172292454275ccea5901620f5e2c8 Mon Sep 17 00:00:00 2001 From: Ryan Caloras Date: Sun, 24 Jul 2016 20:29:50 -0400 Subject: [PATCH] Issue #32 disable subshells by default in bash-preexec - This is causing newer versions of bash to exit under some conditions. Believe this is caused by a bug in bash's debug trap and functrace that is being exposred by bash-preexec. --- bashhub/shell/bashhub.sh | 3 +++ bashhub/shell/deps/bash-preexec.sh | 20 ++++++++++++++------ bashhub/shell/deps/lib-bashhub.sh | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/bashhub/shell/bashhub.sh b/bashhub/shell/bashhub.sh index deee9d8..9ec7f4a 100644 --- a/bashhub/shell/bashhub.sh +++ b/bashhub/shell/bashhub.sh @@ -25,6 +25,9 @@ __bh_setup_bashhub() { # Pull in our libs source "$BH_DEPS_DIRECTORY/lib-bashhub.sh" + + # Disable subshells in bash-preexec + export __bp_disable_subshells="true" source "$BH_DEPS_DIRECTORY/bash-preexec.sh" # Hook bashhub into preexec and precmd. diff --git a/bashhub/shell/deps/bash-preexec.sh b/bashhub/shell/deps/bash-preexec.sh index e4ddbc6..13db194 100644 --- a/bashhub/shell/deps/bash-preexec.sh +++ b/bashhub/shell/deps/bash-preexec.sh @@ -11,7 +11,7 @@ # Author: Ryan Caloras (ryan@bashhub.com) # Forked from Original Author: Glyph Lefkowitz # -# V0.3.0 +# V0.3.1 # # General Usage: @@ -42,7 +42,7 @@ __bp_imported="defined" # Should be available to each precmd and preexec # functions, should they want it. -__bp_last_command_ret_value="$?" +__bp_last_ret_value="$?" # Command to set our preexec trap. It's invoked once via # PROMPT_COMMAND and then removed. @@ -87,7 +87,7 @@ __bp_interactive_mode() { # It will invoke any functions defined in the precmd_functions array. __bp_precmd_invoke_cmd() { - # Should be available to each precmd function, should it want it. + # Save the returned value from our last command __bp_last_ret_value="$?" # For every function defined in our function array. Invoke it. @@ -234,9 +234,17 @@ __bp_install() { # Adjust our HISTCONTROL Variable if needed. __bp_adjust_histcontrol - # Set so debug trap will work be invoked in subshells. - set -o functrace > /dev/null 2>&1 - shopt -s extdebug > /dev/null 2>&1 + + # Issue #25. Setting debug trap for subshells causes sessions to exit for + # backgrounded subshell commands (e.g. (pwd)& ). Believe this is a bug in Bash. + # + # This option allows you to disable subshells. + if [[ -z "$__bp_disable_subshells" ]]; then + + # Set so debug trap will work be invoked in subshells. + set -o functrace > /dev/null 2>&1 + shopt -s extdebug > /dev/null 2>&1 + fi; local existing_prompt_command diff --git a/bashhub/shell/deps/lib-bashhub.sh b/bashhub/shell/deps/lib-bashhub.sh index 73090b6..37aa1e6 100644 --- a/bashhub/shell/deps/lib-bashhub.sh +++ b/bashhub/shell/deps/lib-bashhub.sh @@ -113,7 +113,7 @@ __bh_process_command() { __bh_check_bashhub_installation() { local ret ret=0 - if [[ -n "$BASH_VERSION" && "$(trap)" != *"__bp_preexec_invoke_exec"* ]]; then + if [[ -n "$BASH_VERSION" && -z "$__bp_disable_subshells" && "$(trap)" != *"__bp_preexec_invoke_exec"* ]]; then echo "Bashhub's preexec hook is being overriden and is not saving commands. Please resolve what may be holding the DEBUG trap." ret=1 elif [[ ! -f "$BH_HOME_DIRECTORY/config" ]]; then