Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 139383

Summary: emerge produces error if $PROMPT_COMMAND ends with a newline
Product: Portage Development Reporter: Tom Schumm <gentoo>
Component: CoreAssignee: Portage team <dev-portage>
Status: RESOLVED FIXED    
Severity: minor Keywords: InVCS
Priority: High    
Version: 2.1   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 181949, 187293    
Attachments: use os.system() instead of commands.getoutput()

Description Tom Schumm 2006-07-05 19:01:09 UTC
Example:

phong@poecilotheria:/home/phong $ emerge --version
Portage 2.1-r1 (default-linux/amd64/2005.1, gcc-3.4.6, glibc-2.3.6-r4, 2.6.16-gentoo-r7 x86_64)
sh: -c: line 4: syntax error near unexpected token `;'
sh: -c: line 4: `; } 2>&1'

I've traced it back to resetXtermTitle() in output.py.  Perhaps this should be considered a bug in Python's commands.getoutput/getstatusoutut?

emerge --info
Portage 2.1-r1 (default-linux/amd64/2005.1, gcc-3.4.6, glibc-2.3.6-r4, 2.6.16-gentoo-r7 x86_64)
=================================================================
System uname: 2.6.16-gentoo-r7 x86_64 AMD Athlon(tm) 64 Processor 3200+
Gentoo Base System version 1.6.14
ccache version 2.3 [disabled]
dev-lang/python:     2.3.5-r2, 2.4.2
dev-python/pycrypto: 2.0.1-r5
dev-util/ccache:     2.3
dev-util/confcache:  [Not Present]
sys-apps/sandbox:    1.2.17
sys-devel/autoconf:  2.13, 2.59-r7
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2
sys-devel/binutils:  2.16.1-r3
sys-devel/gcc-config: 1.3.13-r2
sys-devel/libtool:   1.5.22
virtual/os-headers:  2.6.11-r2
ACCEPT_KEYWORDS="amd64"
AUTOCLEAN="yes"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=athlon64 -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.4/env /usr/kde/3.4/share/config /usr/kde/3.4/shutdown /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/X11/xkb /usr/share/config"
CONFIG_PROTECT_MASK="/etc/env.d /etc/gconf /etc/revdep-rebuild /etc/terminfo"
CXXFLAGS="-march=athlon64 -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoconfig distlocks metadata-transfer sandbox sfperms strict"
GENTOO_MIRRORS="http://mirror.datapipe.net/gentoo ftp://130.207.108.136/pub/gentoo ftp://pandemonium.tiscali.de/pub/gentoo/ http://194.117.143.72 http://194.117.143.69 ftp://194.117.143.70/mirrors/gentoo ftp://194.117.143.71/mirrors/gentoo http://194.117.143.70 ftp://ftp.snt.utwente.nl/pub/os/linux/gentoo ftp://gentoo.mirrors.tds.net/gentoo"
LANG="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --delete-after --stats --timeout=180 --exclude='/distfiles' --exclude='/local' --exclude='/packages'"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://rsync.namerica.gentoo.org/gentoo-portage"
USE="amd64 X a52 aac alsa aotuv arts avi berkdb bitmap-fonts bootsplash browserplugin cdda cddb cdparanoia cdr cjk cli crypt dlloader dri dts dvd dvdread eds emboss encode ffmpeg flac foomaticdb fortran gif gpm gstreamer gtk gtk2 imlib ipv6 isdnlog jpeg kde lzw lzw-tiff mad mozilla moznocompose moznoirc moznomail mozsvg mp3 mpeg mpeg2 ncurses nethack nls nsplugin nvidia ogg opengl pam pcre pdflib perl png postgres pppd python qt qt3 qt4 quicktime readline reflection sdl session spell spl ssl stream tcpd tiff truetype truetype-fonts type1-fonts unicode usb userlocales vorbis wxwindows xorg xpm xv zlib elibc_glibc input_devices_keyboard input_devices_mouse kernel_linux userland_GNU video_cards_vga video_cards_vesa video_cards_nvidia video_cards_nv"
Unset:  CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LDFLAGS, LINGUAS, MAKEOPTS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Marius Mauch (RETIRED) gentoo-dev 2007-06-05 19:00:32 UTC
Python people, can you take a look at this?
Comment 2 Zac Medico gentoo-dev 2007-06-06 04:39:58 UTC
The commands.getoutput() behavior seems to behave like one might expect according to the docs where it says cmd is actually run as { cmd ; } 2>&1:

http://docs.python.org/lib/module-commands.html

Why would $PROMPT_COMMAND to end with a newline anyway?  I suppose we can simply strip whitespace from it before we pass it to commands.getoutput().
Comment 3 Tom Schumm 2007-06-06 22:56:50 UTC
OK, I guess since I'm the original reporter, I should elaborate.

PROMPT_COMMAND is typically used to set the xterm title, and that's how it's used in a default Gentoo installation (i.e. a single echo command with some escape sequences in it.)  But it is actually allowed to contain an arbitrary bash script, which can be used for fancier behavior (I've seen little scripts that do things like put a clock in the upper right hand corner of the screen, or some such).  I have mine set up to set up some variables to add fancier coloring to my prompt based on things like load average in addition to setting the xterm title.  So in my .bashrc, I have something like:

PROMPT_COMMAND="
    command1
    command2
    command3
"

So command.getoutput() might not actually be the right thing to be calling here, since it isn't necessarily a single command, but could be anything.  The reason PROMPT_COMMAND is being run this way is just to set the xterm title, but that's based on the assumption that the user is actually using it for that purpose, when in fact, it could be used for anything.

I'll admit that I'm likely the only person in the whole world who would be affected by this bug, and there is a simple workaround (for me to remove the newline at the end of my PROMPT_COMMAND), and the bug is purely cosmetic, and it might really be considered a bug in the implementation of Python's command.getoutput()...  So, it's probably not really an important bug.  But the aforementioned assumption about PROMPT_COMMAND might bear revisiting.

Also, xtermTitle just uses an arbitrary list of terminals and a hard-coded escape sequence when setting the terminal title instead of using terminfo, which might be considered a separate bug, but also probably not an important one.
Comment 4 Zac Medico gentoo-dev 2007-06-06 23:31:42 UTC
(In reply to comment #3)
> So command.getoutput() might not actually be the right thing to be calling
> here, since it isn't necessarily a single command, but could be anything.

Yeah, it seems like the current code assumes too much about PROMPT_COMMAND.  Perhaps we should simply execute it using whatever shell is currently stored in the SHELL environment variable.

> Also, xtermTitle just uses an arbitrary list of terminals and a hard-coded
> escape sequence when setting the terminal title instead of using terminfo,
> which might be considered a separate bug, but also probably not an important
> one.

I'd like to remove the hard-coded stuff.  Perhaps we can try to use python's ncurses module and fall back to hard-coded escape sequences if it's not available.
Comment 5 Zac Medico gentoo-dev 2007-06-08 23:12:37 UTC
Created attachment 121532 [details, diff]
use os.system() instead of commands.getoutput()

This patch seems to correct the problem.
Comment 6 Zac Medico gentoo-dev 2007-06-09 05:27:52 UTC
This has been released in 2.1.2.10.