Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 924723 - emerge --list-sets runs $PROMPT_COMMAND but doesn't find function it points to
Summary: emerge --list-sets runs $PROMPT_COMMAND but doesn't find function it points to
Status: RESOLVED INVALID
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core - External Interaction (show other bugs)
Hardware: AMD64 Linux
: Normal minor (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-02-16 14:14 UTC by Paul Sopka
Modified: 2024-02-16 17:54 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
bash script defining $PROMPT_COMMAND and promtColor (promt,1.16 KB, text/plain)
2024-02-16 17:18 UTC, Paul Sopka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Sopka 2024-02-16 14:14:26 UTC
When running "emerge --list-sets" or "emerge --sync" without sufficient privileges, the contents of $PROMPT_COMMAND are executed.
The same happens when autocompleting e.g. "emerge -uNDa @..." using app-shells/bash-completion-2.11, but only when pressing <tab> after entering at least "@", due to it runnging "emerge --list-sets". This was how I discovered it.
If one has set $PROMPT_COMMAND to point to a function defined in /etc/bash/bashrc.d/examplefile it won't be found when $PROMPT_COMMAND is ran by emerge.
This breaks autocompletion for sets when $PROMPT_COMMAND is set to a bash function.

Reproducible: Always

Steps to Reproduce:
1. run "emerge --list-sets"
Actual Results:  
changed-deps
changed-subslot
deprecated-live-rebuild
downgrade
golang-rebuild
installed
live-rebuild
module-rebuild
preserved-rebuild
profile
rebuilt-binaries
rust-rebuild
security
selected
selected-packages
selected-sets
system
unavailable
unavailable-binaries
world
x11-module-rebuild
bash: line 1: promtColor: command not found

Expected Results:  
changed-deps
changed-subslot
deprecated-live-rebuild
downgrade
golang-rebuild
installed
live-rebuild
module-rebuild
preserved-rebuild
profile
rebuilt-binaries
rust-rebuild
security
selected
selected-packages
selected-sets
system
unavailable
unavailable-binaries
world
x11-module-rebuild
Comment 1 Zac Medico gentoo-dev 2024-02-16 16:22:26 UTC
This suggests the shall you're calling emerge from a shell that has PROMPT_COMMAND exported but does not have promtColor exported from /etc/bash/bashrc.d/examplefile. Does the file export the function or not? If not then it's not really valid to use in an exported PROMPT_COMMAND.
Comment 2 Paul Sopka 2024-02-16 16:27:42 UTC
$PROMPT_COMMAND is set in and the function it is set to are in /etc/bash/bashrc.d/examplefile.
I suspected a bug in portage, since the issue only occurs on some emerge commands, but not on all.
Comment 3 Zac Medico gentoo-dev 2024-02-16 17:14:23 UTC
Portage only runs PROMPT_COMMAND when it calls xtermTitle and xtermTitleReset functions for some commands, not all commands, so we don't expect to see the error for every emerge command.

Can you attach your /etc/bash/bashrc.d/examplefile file? You need something like this in there:

export -f promtColor
Comment 4 Paul Sopka 2024-02-16 17:18:21 UTC
Created attachment 885160 [details]
bash script defining $PROMPT_COMMAND and promtColor
Comment 5 Zac Medico gentoo-dev 2024-02-16 17:51:13 UTC
(In reply to Paul Sopka from comment #4)
> Created attachment 885160 [details]
> bash script defining $PROMPT_COMMAND and promtColor

It looks like you just need to add this:

export -f promtColor
Comment 6 Paul Sopka 2024-02-16 17:54:38 UTC
Thank you very much, it works!
I am sorry to have bothered you with my unsuficcient understanding of bash.
Thank you for working on Portage, it is truly amazing.
Have a nice weekend
Paul