Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 572582 - app-shells/bash: Color detection in /etc/bash/bashrc broken by sys-apps/coreutils-8.25
Summary: app-shells/bash: Color detection in /etc/bash/bashrc broken by sys-apps/coreu...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal with 2 votes (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords: PATCH
: 573196 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-01-22 08:43 UTC by Bernd Feige
Modified: 2016-06-23 07:40 UTC (History)
20 users (show)

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


Attachments
Patch to fix color detection (bashrc_color_detection.patch,1.47 KB, patch)
2016-01-22 09:21 UTC, Bernd Feige
Details | Diff
Patch to fix color detection (bashrc_color_detection.patch,1.65 KB, patch)
2016-01-22 09:27 UTC, Bernd Feige
Details | Diff
Patch to fix color detection (bashrc_color_detection.patch,2.19 KB, patch)
2016-01-23 20:39 UTC, Bernd Feige
Details | Diff
Patch to fix color detection (bashrc_color_detection.patch,1.64 KB, patch)
2016-01-23 20:46 UTC, Bernd Feige
Details | Diff
Patch to fix color detection (bashrc_color_detection.patch,1.68 KB, patch)
2016-02-02 10:33 UTC, Bernd Feige
Details | Diff
Patch to fix color detection (against bashrc in portage tree) (dircolors_new.patch,1.66 KB, patch)
2016-02-02 16:05 UTC, Tiago Batista
Details | Diff
Patch to fix color detection (bashrc_color_detection.patch,1.66 KB, patch)
2016-02-02 19:15 UTC, Bernd Feige
Details | Diff
bashrc rewritish (bashrc,3.90 KB, text/plain)
2016-02-02 22:27 UTC, SpanKY
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bernd Feige 2016-01-22 08:43:48 UTC
In sys-apps/coreutils-8.25, TERM entries in /etc/DIR_COLORS have been changed to use glob patterns. Thus, the simplistic check of "safe_term" against the contents of DIR_COLORS used in /etc/bash/bashrc fails e.g. for gnome-terminal (TERM being "xterm-256color", safe_term being "xterm?256color").

This results in the prompt having no color, and the color settings for other commands not being set.

Reproducible: Always
Comment 1 Bernd Feige 2016-01-22 09:21:44 UTC
Created attachment 423578 [details, diff]
Patch to fix color detection

I now attached a patch for /etc/bash/bashrc. The main idea is to let dircolors itself figure out whether the terminal has color. Re-implementing parsing of the dircolors database in bashrc is bound to introduce breakage like this.
It's also more efficient since it avoids duplicating the parsing, as dircolors is called anyway to setup the colors.
Comment 2 Bernd Feige 2016-01-22 09:27:51 UTC
Created attachment 423580 [details, diff]
Patch to fix color detection

Oops, small fixes of variable handling...
Comment 3 keeperofdakeys 2016-01-22 12:15:06 UTC
I have also found this problem after updating to coreutils-8.25, and have verified that the patch resolves the problem.

Based on the history of the gentoo bashrc file (https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-shells/bash/files/bashrc?view=log), the colour code has gone through a long evolution of changes. Is there a correct behaviour that should be applied here, and does this patch now give us that behaviour?

Regarding the patch, wouldn't the the $LS_COLORS test be best written as [[ -n "$LS_COLORS" ]] (test for non-zero length string).
Comment 4 Bernd Feige 2016-01-23 20:39:12 UTC
Created attachment 423724 [details, diff]
Patch to fix color detection

(In reply to keeperofdakeys from comment #3)

> Regarding the patch, wouldn't the the $LS_COLORS test be best written as [[
> -n "$LS_COLORS" ]] (test for non-zero length string).

Yes, that's right... Better than the old kludge. Now included as suggested.
Comment 5 Bernd Feige 2016-01-23 20:46:59 UTC
Created attachment 423726 [details, diff]
Patch to fix color detection

Oops, now with the correct diff...
Comment 6 SpanKY gentoo-dev 2016-01-25 01:36:10 UTC
the only reason for using bash like this was to avoid execing programs entirely.  the pattern match was straight forward with loading the file content.

however, the way the code is written, we always run dircolors when the TERM is color enabled.  which means it's just saving interactive shells that load profile/bashrc code under a TERM that lacks color support from running dircolors.  for non-interactive shells, this file wouldn't generally load in the first place.  so practically speaking, that's a minority, so always running dircolors is probably fine.
Comment 7 Oleh 2016-01-27 04:36:44 UTC
this is kind of murky explanation. downgrading to 8.24 meanwhile. not a good experience getting TERMS breakage by such updates without testing first.
Comment 8 konsolebox 2016-01-27 06:27:27 UTC
I guess this is a good opportunity to ask this: why do we not properly quote the argumenta in "eval $(dircolors -b ~/.dir_colors)" and "eval $(dircolors -b /etc/DIR_COLORS)"?  It makes it subject to uncalled word splitting and further pathname expansions, no?  I had an issue once because of it, and quoting fixed it: eval "$(dircolors -b ~/.dir_colors)", eval "$(dircolors -b /etc/DIR_COLORS)".  Might as well to take the opportunity to include it in the patch.
Comment 9 SpanKY gentoo-dev 2016-01-28 01:04:14 UTC
(In reply to Oleg from comment #7)

really no idea what you're trying to say.  if you don't have anything useful to contribute, then just refrain from posting.

(In reply to konsolebox from comment #8)

because no one filed a bug pointing it out before.
Comment 10 Lars Wendler (Polynomial-C) (RETIRED) gentoo-dev 2016-01-28 12:42:11 UTC
*** Bug 573196 has been marked as a duplicate of this bug. ***
Comment 11 Bernd Feige 2016-02-02 10:33:42 UTC
Created attachment 424454 [details, diff]
Patch to fix color detection

Updated patch:
- For completeness, if neither ~/.dir_colors nor /etc/DIR_COLORS are available, use the data base compiled into dircolors
- Quote the argument of eval as suggested by konsolebox, https://bugs.gentoo.org/show_bug.cgi?id=572582#c8
Comment 12 Tiago Batista 2016-02-02 16:05:51 UTC
Created attachment 424486 [details, diff]
Patch to fix color detection (against bashrc in portage tree)

(In reply to Bernd Feige from comment #11)
> Created attachment 424454 [details, diff] [details, diff]
> Patch to fix color detection
> 
> Updated patch:
> - For completeness, if neither ~/.dir_colors nor /etc/DIR_COLORS are
> available, use the data base compiled into dircolors
> - Quote the argument of eval as suggested by konsolebox,
> https://bugs.gentoo.org/show_bug.cgi?id=572582#c8

I just applied this patch to the bashrc in portage (/usr/portage/app-shells/bash/files/bashrc), the second chunk failed to apply, but after some manual cleanup I would say that the problem is solved in my environment.

Is this to be applied against a version of bashrc other than the one in portage right now? I did not override the other patch because I am not sure of that.

md5sum /usr/portage/app-shells/bash/files/bashrc 
62b2fbca4ba4576fe4c4a1c13f5233d5  /usr/portage/app-shells/bash/files/bashrc

I attached a corrected patch that applies to the bashrc currently in portage if it helps.
Comment 13 klaus818 2016-02-02 16:19:00 UTC
(In reply to Tiago Batista from comment #12)
> Created attachment 424486 [details, diff] [details, diff]
> Patch to fix color detection (against bashrc in portage tree)
> 
> (In reply to Bernd Feige from comment #11)
> > Created attachment 424454 [details, diff] [details, diff] [details, diff]
> > Patch to fix color detection
> > 
> > Updated patch:
> > - For completeness, if neither ~/.dir_colors nor /etc/DIR_COLORS are
> > available, use the data base compiled into dircolors
> > - Quote the argument of eval as suggested by konsolebox,
> > https://bugs.gentoo.org/show_bug.cgi?id=572582#c8
> 
> I just applied this patch to the bashrc in portage
> (/usr/portage/app-shells/bash/files/bashrc), the second chunk failed to
> apply, but after some manual cleanup I would say that the problem is solved
> in my environment.
> 
> Is this to be applied against a version of bashrc other than the one in
> portage right now? I did not override the other patch because I am not sure
> of that.
> 
> md5sum /usr/portage/app-shells/bash/files/bashrc 
> 62b2fbca4ba4576fe4c4a1c13f5233d5  /usr/portage/app-shells/bash/files/bashrc
> 
> I attached a corrected patch that applies to the bashrc currently in portage
> if it helps.

Ok, with this patch no chunk failed. But the problem was fixed for me with the previous patch too. No difference for me.
Comment 14 Bernd Feige 2016-02-02 19:15:17 UTC
Created attachment 424490 [details, diff]
Patch to fix color detection

Okay, thanks, updated patch should now be compatible for all, and the third dircolors uses the -b flag as should be...
Comment 15 SpanKY gentoo-dev 2016-02-02 22:27:51 UTC
Created attachment 424510 [details]
bashrc rewritish

give this one a try.  it's actually a stack of fixes i have pending locally.
Comment 16 Bernd Feige 2016-02-03 08:45:40 UTC
(In reply to SpanKY from comment #15)
> Created attachment 424510 [details]
> bashrc rewritish
> 
> give this one a try.  it's actually a stack of fixes i have pending locally.

Works for me, thanks!
Comment 17 SpanKY gentoo-dev 2016-02-03 18:53:38 UTC
ok, i've pushed that now.  i think i incorporated everyone's suggestions.

quote dircolors output:
https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=485b78806bf288e68eae9988e2e9342df8d74959

always run dircolors:
https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=747857408315deb4b6a0ddd2a34484ca8e5ec2ff

and there's a few other commits in there if people are interested
Comment 18 Matt Whitlock 2016-02-25 05:38:21 UTC
@SpanKY: Shouldn't you also unset the temporary ls_colors variable so it doesn't leak into the shell's variable namespace? (You unset used_default_dircolors but not ls_colors.)
Comment 19 SpanKY gentoo-dev 2016-06-23 05:32:01 UTC
(In reply to Matt Whitlock from comment #18)

thanks, fixed here:
https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=becfc11732db43397071f873487813165c0bdd85