Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 189257 - revdep-rebuild silently fails if GREP_OPTIONS is set
Summary: revdep-rebuild silently fails if GREP_OPTIONS is set
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Tools (show other bugs)
Hardware: All Linux
: High minor (vote)
Assignee: Portage Tools Team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks: 170220
  Show dependency tree
 
Reported: 2007-08-17 17:05 UTC by Matteo Sasso
Modified: 2008-02-21 01:52 UTC (History)
1 user (show)

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


Attachments
Proposed patch (revdep-rebuild.patch,374 bytes, patch)
2007-08-17 17:11 UTC, Matteo Sasso
Details | Diff
Proposed patch v2 (revdep-rebuild.patch,370 bytes, patch)
2007-08-18 14:16 UTC, Matteo Sasso
Details | Diff
revdep-rebuild_r453_unset_GREP_OPTIONS.patch (revdep-rebuild_r453_unset_GREP_OPTIONS.patch,343 bytes, patch)
2008-01-22 22:24 UTC, michael@smith-li.com
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matteo Sasso 2007-08-17 17:05:16 UTC
Using environment variables to personalize the output of common utilities, like grep and du, often breaks clueless scripts.

My GREP_OPTIONS is set to "--color=auto --directories=recurse -E" and this causes problems with revdep-rebuild: it correctly finds many broken binaries (and their packages) but it later quits, saying there's nothing to do (e.g. "There are no dynamic links to libexpat.so.0... All done.").

I'm posting a trivial patch that fixes the problem.
Comment 1 Matteo Sasso 2007-08-17 17:11:04 UTC
Created attachment 128415 [details, diff]
Proposed patch
Comment 2 Arfrever Frehtes Taifersar Arahesis (RETIRED) gentoo-dev 2007-08-17 21:51:18 UTC
Maybe:
unset GREP_OPTIONS
Comment 3 Matteo Sasso 2007-08-17 22:18:20 UTC
Yep, that's cleaner.
Comment 4 Matteo Sasso 2007-08-18 14:16:05 UTC
Created attachment 128481 [details, diff]
Proposed patch v2

Cleaner line by Arfrever.
Comment 5 michael@smith-li.com 2007-08-23 19:55:01 UTC
I don't think this is a valid fix. If users want to break revdep-rebuild by setting unusual environment variables, there's nothing we can do to stop it. We could start wrapping coreutils like this:
grep() { /bin/env - /bin/grep "$@"; }, but even after we do that for every tool, someone will find another way to break it. GREP_OPTIONS isn't the only environment variable that can be set to affect GNU utilities.

In my opinion it would just be a good idea to have a sane environment before running bash scripts.
Comment 6 Matteo Sasso 2007-08-23 23:59:29 UTC
Hi Michael,
I wanted to point out that this fix wasn't made to prevent users from breaking scripts. After all, if they really want to, they can modify the scripts themselves and see what happens. So this is not about "security" or "perfect robustness".

My fix just tries to avoid some frustration for those few users that actually read manpages and discover that some well documented environment variables can be used to modify default behavior for some commands. I really don't know how unusual this is, but I think you will agree that this is not completely unreasonable. Some users don't understand the subtleties of shell programming and would probably expect scripts to work anyway (maybe protecting themselves somehow). And the problem is: 90% of them will! (They either don't use grep or they use it in a way that doesn't involve those specific GREP_OPTIONS). For this reason, problems could arise a long time after a user made this modification to the environment (and has probably forgotten about it).
Yes, expert users will expect some breakage and be on guard. Unfortunately, not everybody is an expert.

What this fix tries to accomplish is to save developers' time (i.e. people that think revdep-rebuild doesn't work anymore and file bug reports) and/or some headache of said users. I think it does its job.

I agree with you on the fact that it is not a complete fix: there are many tools that rely on environment variables and make other assuptions. Your solutions would solve the general case in an elegant way. Another solution would be to use "env" to give a clean environment to the shell process that runs the script. Unfortunately that requires to identify all variables that are actually useful for the script (e.g. PATH) and a lot of testing.

Of the many solutions that could solve the general problem, none of them is probably worth the effort. My solution is trivial (doesn't break anything) and catches a common case. After all, grep is probably one of the most used utilities, especially as far as scripts are concerned.

It's useful for me and maybe will be for someone else too.
Comment 7 michael@smith-li.com 2008-01-22 22:24:19 UTC
Created attachment 141615 [details, diff]
revdep-rebuild_r453_unset_GREP_OPTIONS.patch

Patch against r453 in SVN -- I've registered my reservations against patching every esoteric GNU extension. Clearing the entire environment isn't an option either.
Comment 8 Paul Varner (RETIRED) gentoo-dev 2008-02-18 18:09:58 UTC
$ svn commit -m "unset GREP_OPTIONS to prevent problems with grep. (Bug 189257)"
Sending        revdep-rebuild/revdep-rebuild
Transmitting file data .
Committed revision 464.
Comment 9 Paul Varner (RETIRED) gentoo-dev 2008-02-21 01:52:05 UTC
Released in gentoolkit-0.2.4_rc2