Bug 620408

Summary: Text might be put in the terminal title instead of the terminal itself
Product: Red Hat Enterprise Linux 6 Reporter: Tomas Smetana <tsmetana>
Component: setupAssignee: Ondrej Vasik <ovasik>
Status: CLOSED ERRATA QA Contact: qe-baseos-daemons
Severity: medium Docs Contact:
Priority: medium    
Version: 6.0CC: alex, asersen, azelinka, fnadge, rrakus
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: setup-2.8.14-11.el6 Doc Type: Bug Fix
Doc Text:
Bash provides the environment variable, PROMPT_COMMAND, containing a command that is called when a prompt is displayed. Previously, the PROMPT_COMMAND command used two separate echo commands. Consequently, if a background process returned text, the text might have displayed in the X terminal title rather than the terminal itself. In this updated package, the PROMPT_COMMAND command uses a single printf statement rather than two echo commands, ensuring returned text displays in the shell.
Story Points: ---
Clone Of:
: 620435 620443 (view as bug list) Environment:
Last Closed: 2011-05-19 11:54:34 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 620443    

Description Tomas Smetana 2010-08-02 13:22:22 UTC
Description of problem:
Due to the fix of bug #142125 the default PROMPT_COMMAND has been set to a list of two commands.  This causes strange behaviour when the output of a background process might get flushed after the output of the first PROMPT_COMMAND echo and hence appear between the escape sequences which mark the X terminal title.  It also means the text doesn't appear in the terminal itself.

Version-Release number of selected component (if applicable):
bash-4.1.2-2.el6.x86_64

How reproducible:
Sometimes

Steps to Reproduce:
1. In xterm/gnome-terminal/Terminal run: yes &
2. while 'yes' is running: cat /var/log/yum.log (or whatever application which prints out something on the terminal and takes some time)
3. Look at the terminal title -- it would read something like "tsmetana@localhost:~/bash_testy y y y y y"
4. if not GOTO 2.
  
Actual results:
The text printed in the terminal title was not printed in the terminal window (this can be verified by running something else than 'yes' -- e.g. a simple c-program which outputs a number sequence)

Expected results:
The output of PROMPT_COMMAND shouldn't get mixed with the other text that goes to the terminal.

Additional info:
There is a simple way to check the more commands in PROMPT_COMMAND can have unusual consequence -- try to add sleep between the two commands:

export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; sleep 1; echo -ne "\007"'

Now just press enter and some random keys on the keyboard, then look at the xterm title -- it would contain the keys you pressed.  Note that the sleep only increases the chance for this to happen.

I'm not actually sure how to solve the problem properly: maybe the bug #142125 has to be fixed some other way and PROMPT_COMMAND should be reverted to the old value with just one echo command.

Comment 1 Roman Rakus 2010-08-02 13:42:28 UTC
I guess we should use `printf' instead of `echo'.

Comment 2 Roman Rakus 2010-08-02 14:08:23 UTC
PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#HOME/~}"'

works for me. Reassigning to setup.

Comment 3 Tomas Smetana 2010-08-18 08:23:24 UTC
Hello,
  just a small correction: It looks like there is a $ sign missing before HOME. The correct value should look like this:

PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'

Comment 7 Florian Nadge 2011-03-02 18:18:14 UTC
Please be so kind and add a few key words to the technical note of this
bugzilla entry using the following structure:

Cause:

Consequence:

Fix:

Result:


For details, see:
https://bugzilla.redhat.com/page.cgi?id=fields.html#cf_release_notes

Thanks

Comment 8 Florian Nadge 2011-03-02 18:18:15 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
Cause
    What actions or circumstances induced the feature request.
Consequence
    What action was inhibited by the feature’s absence.
Change
    What was done to implement the feature.
    Note: backported from upstream is not an explanation.
Result
    What now happens when the actions or circumstances above occur.
    Note: this is not the same as the feature request was fulfilled.

Comment 9 Ondrej Vasik 2011-03-03 09:05:52 UTC
These are already present in errata description text ... but ok, adding to technotes field.

Comment 10 Ondrej Vasik 2011-03-03 09:05:52 UTC
    Technical note updated. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    Diffed Contents:
@@ -1,10 +1 @@
-Cause
+Under some circumstances (running background process displaying some text), PROMPT_COMMAND environmental variable could cause that the text is shown in the X terminal title, instead of the terminal itself. This was caused by bad design of the PROMPT_COMMAND. Design was improved and single printf was used instead of two separate echo commands, thus preventing the issue.-    What actions or circumstances induced the feature request.
-Consequence
-    What action was inhibited by the feature’s absence.
-Change
-    What was done to implement the feature.
-    Note: backported from upstream is not an explanation.
-Result
-    What now happens when the actions or circumstances above occur.
-    Note: this is not the same as the feature request was fulfilled.

Comment 12 Ryan Lerch 2011-04-19 23:24:12 UTC
    Technical note updated. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    Diffed Contents:
@@ -1 +1 @@
-Under some circumstances (running background process displaying some text), PROMPT_COMMAND environmental variable could cause that the text is shown in the X terminal title, instead of the terminal itself. This was caused by bad design of the PROMPT_COMMAND. Design was improved and single printf was used instead of two separate echo commands, thus preventing the issue.+Bash provides the environment variable, PROMPT_COMMAND, containing a command that is called when a prompt is displayed. Previously, the PROMPT_COMMAND command used two separate echo commands. Consequently, if a background process returned text, the text might have displayed in the X terminal title rather than the terminal itself. In this updated package, the PROMPT_COMMAND command uses a single printf statement rather than two echo commands, ensuring returned text displays in the shell.

Comment 15 Roman Rakus 2011-05-18 13:51:36 UTC
*** Bug 705669 has been marked as a duplicate of this bug. ***

Comment 16 errata-xmlrpc 2011-05-19 11:54:34 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0524.html