Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[crmsh-4.6] Fix: sh: pass env to child process explicitly (bsc#1205925) #1356

Merged

Conversation

nicholasyang2022
Copy link
Collaborator

A bug in python stardard library, python/cpython#100516, make
environment variables, COLUMNS and ROWS to be added at fork. These
environment variables may make some of the commands called by crmsh to
truncate its output even if those commands are not writing to the
terminal.

Passing argument env explicitly is a workaround for the python bug.

A bug in python stardard library, python/cpython#100516, make
environment variables, `COLUMNS` and `ROWS` to be added at fork. These
environment variables may make some of the commands called by crmsh to
truncate its output even if those commands are not writing to the
terminal.

Passing argument `env` explicitly is a workaround for the python bug.
Copy link

codecov bot commented Mar 13, 2024

Codecov Report

Attention: Patch coverage is 57.14286% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 52.81%. Comparing base (24df92a) to head (1ceec36).
Report is 2 commits behind head on crmsh-4.6.

Files Patch % Lines
crmsh/term.py 33.33% 4 Missing ⚠️
crmsh/utils.py 33.33% 4 Missing ⚠️
crmsh/ui_node.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           crmsh-4.6    #1356      +/-   ##
=============================================
- Coverage      52.82%   52.81%   -0.01%     
=============================================
  Files             79       79              
  Lines          24002    24011       +9     
=============================================
+ Hits           12678    12682       +4     
- Misses         11324    11329       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

A bug in python stardard library, python/cpython#100516, make
environment variables, `COLUMNS` and `ROWS` to be added at fork. These
environment variables may make some of the commands called by crmsh to
truncate its output even if those commands are not writing to the
terminal.

These variables is set when bash enables its `checkwinsize` option. As
crmsh is able to read terminal size with curses, these variables are
unneeded and may be out of sync with actual terminal size.
A bug in python stardard library, python/cpython#100516, make
environment variables, `COLUMNS` and `ROWS` to be added at fork. These
environment variables may make some of the commands called by crmsh to
truncate its output even if those commands are not writing to the
terminal.

Passing argument `env` explicitly is a workaround for the python bug.
`os.environ` is captured once from libc on python process startup (when
module `os` is imported from `site.py`) and is the only one interface
able to enumerate environment variables. Changing environment variables
with other interfaces (including `os.putenv`, `os.unsetenv`, or call
libc interface in some CPython modules) makes `os.environ` out of sync
and should be avoided.
@nicholasyang2022 nicholasyang2022 marked this pull request as ready for review March 13, 2024 11:21
Copy link
Collaborator

@liangxin1300 liangxin1300 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!
Please backport to master

@nicholasyang2022
Copy link
Collaborator Author

Further experiment shows that the behavior of modifying environ COLUMNS and ROWS exists in libreadline, instead of the python wrapper.

@nicholasyang2022
Copy link
Collaborator Author

@nicholasyang2022
Copy link
Collaborator Author

nicholasyang2022 commented Mar 14, 2024

The backtrace shows that COLUMNS is set when rl_initialize() is called from import readline. I had believed the environ is set at fork. However, this is not true. I use /proc/$pid/environ to determine whether COLUMNS is set. This is also unreliable as it is not updated instantly when setenv(3) is called.

From proc_pid_environ(5):

this file contains the initial environment that was set when the
currently executing program was started via execve(2)

If, after an execve(2), the process modifies its environment
(e.g., by calling functions such as putenv(3) or modifying the
environ(7) variable directly), this file will not reflect those
changes.

@nicholasyang2022 nicholasyang2022 deleted the bsc_1205925_20240313 branch March 15, 2024 05:53
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.

2 participants