bash completion inhibits ability to debug login scripts

Bug #205444 reported by era
6
Affects Status Importance Assigned to Milestone
bash-completion (Ubuntu)
Fix Released
Undecided
Mika Fischer

Bug Description

Binary package hint: bash

/etc/bash_completion contains various magic which shut down all debugging output from the invoking shell.

This is a problem if you are trying to run, say, your .profile under "set -vx", for example. This is one of the few facilities we have for debugging log-in scripts. Granted, newbie users will not want to do this, but for those of us who do, this is pretty crippling.

Please see some examples below.

This is for Gutsy; sorry if this is already reported or even (gasp) fixed. I looked through open and closed bash and bash-completion bugs but the search facility isn't very helpful and there are too many bugs to go through manually.

In the following transcript, I am trying to figure out why stuff in my spanking new .bash_profile is not taking. The stuff in /etc/bash_completion.d prevents me from even seeing what happens after /etc/bash_completion is invoked from my (standard, identical to /etc/skel) .profile, which means I can't really do what I'm trying to do. (Commenting out the sourcing of .profile seems to make my .bash_profile work, unsurprisingly; but that's a lucky coincidence, unless /etc/bash_completion is also responsible for this particular problem ... which as such would not surprise me much.)

vnix$ cat .bash_profile
. $HOME/.profile

export LESS=-qMX

vnix$ . .bash_profile

vnix$ echo $LESS

vnix$ # !?

vnix$ set -vx
echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
++ echo -ne '\033]0;era@indeed: ~\007'

vnix$ . .bash_profile
. .bash_profile
+ . .bash_profile
. $HOME/.profile
++ . /home/era/.profile
# ~/.profile: executed by the command interpreter for login shells.
<...>

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi
++++ '[' -f /etc/bash_completion ']'
++++ . /etc/bash_completion
# bash_completion - programmable completion functions for bash 3.x
# http://www.caliban.org/bash/index.shtml#completion
<...>
#
# RELEASE: 20060301

[ -n "${BASH_COMPLETION_DEBUG:-}" ] && set -v || set +v
+++++ '[' -n '' ']'
+++++ set +v
++ echo -ne '\033]0;era@indeed: ~\007'

vnix$ # ...?

vnix$ BASH_COMPLETION_DEBUG=pretty_please
+ BASH_COMPLETION_DEBUG=pretty_please
++ echo -ne '\033]0;era@indeed: ~\007'

vnix$ set -vx
set -vx
+ set -vx
echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
++ echo -ne '\033]0;era@indeed: ~\007'

vnix$ . .bash_profile
<...>
# RELEASE: 20060301

[ -n "${BASH_COMPLETION_DEBUG:-}" ] && set -v || set +v
+++++ '[' -n pretty_please ']'
+++++ set -v

# Alter the following to reflect the location of this file.
#
{
  # These declarations must go within braces in order to be able to silence
  # readonly variable errors.
  BASH_COMPLETION="${BASH_COMPLETION:-/etc/bash_completion}"
  BASH_COMPLETION_DIR="${BASH_COMPLETION_DIR:=/etc/bash_completion.d}"
} 2>/dev/null || :
echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
++ echo -ne '\033]0;era@indeed: ~\007'

vnix$ # what now?

Revision history for this message
era (era) wrote :

Here's what the bash manual says about readonly assignments:

> If any of the assignments attempts to assign a value to a
> readonly variable, an error occurs, and the command exits with a non-
> zero status.

So I guess that's the root cause of this problem. I would interpret this to mean that the script simply exits at this point, not merely turns off all debugging output.

Revision history for this message
era (era) wrote :

The following quick patch attempts to solve two problems in the Gutsy /etc/bash_completion:

  * Don't "set -v" or "set +v" if it's already set
  * If BASH_COMPLETION or BASH_COMPLETION_DIR are declared readonly, don't even attempt to modify them

The latter would (if my quick analysis isn't completely up the creek) cause scripts which sourced /etc/bash_completion to exit with an error from within /etc/bash_completion instead of completing if bash_completion had already been executed previously. This includes, but is not limited to, /etc/skel/.bashrc and thus also anything which includes .bashrc, such as /etc/skel/.profile

Mika Fischer (zoop)
Changed in bash:
assignee: nobody → zoop
Revision history for this message
Mika Fischer (zoop) wrote :

Thanks for reporting this bug in Ubuntu.

The main problem with the readonly variables has already been fixed in hardy.

The issue with -v is a bit more tricky. I think the idea was that if you set -v to debug your startup script, you're probably not interested in thousands of lines of output from bash_completion.

So I propose to set -v or set +v based on the value of $BASH_COMPLETION_DEBUG, but restore the original setting at the end of the script.

This will make it possible to debug without being overwhelmed by output from bash_completion or also debug bash_completion selectively.

What do you think?

A version that does this can be found here:
http://git.zoopnet.de/bash-completion.git?a=blob_plain;f=bash_completion;hb=601bb9cdd810467b5ce2c4a2c672f68ba4b43e55

Let me know whether this works for you.

Revision history for this message
era (era) wrote : Re: [Bug 205444] Re: bash completion inhibits ability to debug login scripts

On Sun, 23 Mar 2008 12:39:37 -0000, "Mika Fischer"
<email address hidden> said:
> So I propose to set -v or set +v based on the value of
> $BASH_COMPLETION_DEBUG, but restore the original setting at the end of
> the script.
>
> This will make it possible to debug without being overwhelmed by
> output from bash_completion or also debug bash_completion selectively.
>
> What do you think?
>
> A version that does this can be found here:
> http://git.zoopnet.de/bash-completion.git?a=blob_plain;f=bash_completion;hb=601bb9cdd810467b5ce2c4a2c672f68ba4b43e55
>
> Let me know whether this works for you.

I don't run unstable code on my production system but it certainly looks
reasonable.

Perhaps you want to update the comments to indicate that this is no
longer identical to Ian's version 200603whatever, too ...

/* era */

--
If this were a real .signature, it would suck less. Well, maybe not.

Revision history for this message
Mika Fischer (zoop) wrote :

To test this bug, you could just put the script in your home directory and instead of sourcing /etc/bash_completion source ~/bash_completion.

But if you agree with the general approach I'll include this in the next upload.

Changed in bash-completion:
status: New → In Progress
Revision history for this message
era (era) wrote :

See also bug #149527 for what it's worth. I had forgotten that it existed, although I had commented on it in the past.

Revision history for this message
era (era) wrote :

If anything is pending on me, then I reaffirm that I think the fix looks good. Perhaps you should check that you're not crossing paths with the #149527 fix, though.

Revision history for this message
Mika Fischer (zoop) wrote :

OK, sourcing bash_completion twice is another problem. I'll check this in the evening and include the fix above in the next upload.

Revision history for this message
Mika Fischer (zoop) wrote :

Actually, sourcing bash_completion twice is fine, since we only try to set it if it's empty and we only mark it read-only after we've set it to something.

So I'll just add the fix for the -v issue.

Revision history for this message
Mika Fischer (zoop) wrote :

It being the BASH_COMPLETION variable...

Revision history for this message
Mika Fischer (zoop) wrote :

I've prepared an updated package in my PPA which should fix the bug you reported.

If you're using hardy I'd appreciate it if you could test it and report whether your bug is indeed fixed and also whether you experienced any other regressions.

You can get the package from here:
http://launchpadlibrarian.net/13042048/bash-completion_20060301-3ubuntu2%7Eppa2_all.deb

To install it:
wget http://launchpadlibrarian.net/13042048/bash-completion_20060301-3ubuntu2%7Eppa2_all.deb
sudo dpkg -i dpkg -i bash-completion_20060301-3ubuntu2~ppa2_all.deb

To go back to the original package, do this:
sudo aptitude install bash-completion/hardy

If I don't get reports of regressions I'll try to get this version into hardy.

Thanks for your help!

Changed in bash-completion:
status: In Progress → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package bash-completion - 20060301-3ubuntu2

---------------
bash-completion (20060301-3ubuntu2) hardy; urgency=low

  * Bugfix release:
   - Fix _get_cword more
   - Fix _command function to correctly prune the command line (LP: #103395)
   - Remove newline from options pattern for dpkg (LP: #138312)
   - Start readline-quoting arguments to compgen (LP: #123665)
   - Save and restore -v shell option (LP: #205444)
   - Prevent glob expansion in _filedir function (LP: #194419)
   - Quote glob expression in tar completion function (LP: #194419)
   - Complete AAS/SSA files for mplayer -sub (LP: #151086)
   - Disable completion of postgresql users and databases (LP: #164772)
   - Use files from UserKnownHostsFile options in addition to standard ones
     (LP: #211180)

 -- Mika Fischer <email address hidden> Sat, 05 Apr 2008 16:09:34 +0200

Changed in bash-completion:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.