Skip to content

env: trace environment changes with -v - #14263

Open
wtcpython wants to merge 1 commit into
uutils:mainfrom
wtcpython:env-verbose-trace
Open

env: trace environment changes with -v#14263
wtcpython wants to merge 1 commit into
uutils:mainfrom
wtcpython:env-verbose-trace

Conversation

@wtcpython

Copy link
Copy Markdown
Contributor

Fixes #14171.

GNU traces each environment change in verbose mode, and -vv is just -v
repeated. We printed nothing for -v and dumped the input args for -vv.

Print the same trace lines as GNU (cleaning environ, setenv, unset,
chdir) and drop the argument dump. Add tests for the traced output and for
-vv matching -v.

@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 152.18 MB (+1004 KB, +0.65%)

Significant per-binary changes:
  comm     1.12 MB ->    2.33 MB  (+1.21 MB, +107.29%)

@github-actions

github-actions Bot commented Aug 30, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/retry (fails in this run but passes in the 'main' branch)

Comment thread src/uu/env/src/env.rs Outdated
));
}
// GNU traces only the unsets that remove something
if opts.debug && env::var_os(name).is_some() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GNU prints unset: unconditionally, even for a variable that isn't set or an invalid name

Comment thread tests/by-util/test_env.rs
assert_eq!(result.stderr_str(), "unset: ENV_VERBOSE_UNSET_ME\n");

// unsetting a variable that does not exist is not traced
let result = new_ucmd!()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GNU does trace it. Should expect unset: ENV_VERBOSE_NOT_SET

Comment thread src/uu/env/src/env.rs
);
continue;
}
if opts.debug {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_string_lossy() mangles non-UTF-8 args - GNU passes the raw bytes through. Write the OsStr bytes to stderr instead. Same at line 1065.

@wtcpython
wtcpython force-pushed the env-verbose-trace branch 2 times, most recently from 450d95a to 85d29c9 Compare August 31, 2026 01:45
Copilot AI lite review requested due to automatic review settings September 7, 2026 03:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@wtcpython

Copy link
Copy Markdown
Contributor Author

@sylvestre ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

env: -v / -vv don't trace environment changes

3 participants