diff options
| author | Mark Mielke <mark.mielke@gmail.com> | 2018-08-13 23:54:34 -0400 | 
|---|---|---|
| committer | Amar Tumballi <amarts@redhat.com> | 2018-08-15 05:44:34 +0000 | 
| commit | 89545e745e4075845c18078be67a31dea93a4e88 (patch) | |
| tree | ed2ac2e23ff2152434e48bc925fd6e8e4bb8e9a2 /extras | |
| parent | 1f3bfe7b5d437ae3ecd202e0e224a62dbc98b133 (diff) | |
Bash integration script should namespace variables
In the original submitted script, it looks like there was effort
put into namespacing all global variables. However a few mistakes
remained.
GLUSTER_TOP_SUBOPTIONSx were defined, but TOP_SUBOPTIONSx were
referenced. This was likely an unrecognized defect in the
original code submission? These are now corrected to refer to
GLUSTER_TOP_SUBOPTIONSx.
FINAL_LIST, LIST, and TOP were leaked into all Bash shells and
used by the command completion functions. The most problematic
of these was TOP, which was declared with "-i" making it an
integer. This cause other code which used TOP to define a path
to fail like this:
    $ bash
    $ TOP=/abc
    bash: /abc: syntax error: operand expected (error token is "/abc")
These are now qualified as GLUSTER_FINAL_LIST, GLUSTER_LIST, and
GLUSTER_TOP to reduce impact on scripts that might choose to use
these extremely common variable names.
Change-Id: Ic96eda8efd1f3238bbade6c6ddb69118e8d82158
Fixes: bz#1425325
Signed-off-by: Mark Mielke <mark.mielke@gmail.com>
Diffstat (limited to 'extras')
| -rw-r--r-- | extras/command-completion/gluster.bash | 40 | 
1 files changed, 20 insertions, 20 deletions
diff --git a/extras/command-completion/gluster.bash b/extras/command-completion/gluster.bash index 680ecd964d5..73d16098875 100644 --- a/extras/command-completion/gluster.bash +++ b/extras/command-completion/gluster.bash @@ -26,28 +26,28 @@ GLUSTER_TOP_SUBOPTIONS2="  "  GLUSTER_TOP_OPTIONS="          {open -                [ $TOP_SUBOPTIONS1 ] +                [ $GLUSTER_TOP_SUBOPTIONS1 ]          },          {read -                [ $TOP_SUBOPTIONS1 ] +                [ $GLUSTER_TOP_SUBOPTIONS1 ]          },          {write -                [ $TOP_SUBOPTIONS1 ] +                [ $GLUSTER_TOP_SUBOPTIONS1 ]          },          {opendir -                [ $TOP_SUBOPTIONS1 ] +                [ $GLUSTER_TOP_SUBOPTIONS1 ]          },          {readdir -                [ $TOP_SUBOPTIONS1 ] +                [ $GLUSTER_TOP_SUBOPTIONS1 ]          },          {clear -                [ $TOP_SUBOPTIONS1 ] +                [ $GLUSTER_TOP_SUBOPTIONS1 ]          },          {read-perf -                [ $TOP_SUBOPTIONS2 ] +                [ $GLUSTER_TOP_SUBOPTIONS2 ]          },          {write-perf -                [ $TOP_SUBOPTIONS2 ] +                [ $GLUSTER_TOP_SUBOPTIONS2 ]          }  " @@ -282,16 +282,16 @@ _gluster_throw () {          exit  } -declare FINAL_LIST='' -declare LIST='' -declare -i TOP=0 +declare GLUSTER_FINAL_LIST='' +declare GLUSTER_LIST='' +declare -i GLUSTER_TOP=0  _gluster_push () { -        TOP=$((TOP + 1)) -        return $TOP +        GLUSTER_TOP=$((GLUSTER_TOP + 1)) +        return $GLUSTER_TOP  }  _gluster_pop () { -        TOP=$((TOP - 1)) -        return $TOP +        GLUSTER_TOP=$((GLUSTER_TOP - 1)) +        return $GLUSTER_TOP  }  _gluster_goto_end () @@ -333,7 +333,7 @@ _gluster_form_list ()                  top=$?                  read -r key                  if [ "X$cur_word" == "X" -o "${cur_word:0:1}" == "${key:0:1}" -o "${key:0:1}" == "_" ]; then -                        LIST="$LIST $key" +                        GLUSTER_LIST="$GLUSTER_LIST $key"                  fi                  _gluster_goto_end $top @@ -452,10 +452,10 @@ _gluster_parse ()          elif [ "$token" == '{' ]; then                  read -r tmp_token -                LIST="$tmp_token" +                GLUSTER_LIST="$tmp_token"          fi -        echo $LIST +        echo $GLUSTER_LIST  }  _gluster_handle_list () @@ -479,12 +479,12 @@ _gluster_handle_list ()  _gluster_completion ()  { -        FINAL_LIST=`echo $GLUSTER_COMMAND_TREE |                              \ +        GLUSTER_FINAL_LIST=`echo $GLUSTER_COMMAND_TREE |                      \                  egrep -ao --color=never "([A-Za-z0-9_.-]+)|[[:space:]]+|." |  \                          egrep -v --color=never "^[[:space:]]*$" |             \                                  _gluster_parse` -        ARG="FINAL_LIST" +        ARG="GLUSTER_FINAL_LIST"          _gluster_handle_list $ARG ${COMP_WORDS[COMP_CWORD]}          return  }  | 
