Repository navigation
[core] Fix shell detection with multiline commands - #23747
Open
jinchuntan wants to merge 1 commit into
Open
jinchuntan wants to merge 1 commit into
jinchuntan wants to merge 1 commit into
Conversation
A newline in a shell argument makes cut return text from later lines. This can select the wrong setup path and leave ROOTSYS unset. Read the first line after converting the NUL separators to newlines. Keep reading the stream so long commands also work with pipefail. Add regression coverage for bash and zsh. Fixes root-project#23746 Assisted-by: codex:gpt-6
Test Results 24 files 24 suites 4d 1h 10m 10s ⏱️ For more details on these failures, see this check. Results for commit 8f8c0e7. |
| # Determine the shell executable filename. | ||
| if [ -r "/proc/$$/cmdline" ]; then | ||
| trueExe=$(cut -d '' -f1 /proc/$$/cmdline 2>/dev/null) || trueExe=$(xargs -0 -n 1 < /proc/$$/cmdline | head -n 1) || return 1 | ||
| trueExe=$(tr '\0' '\n' < /proc/$$/cmdline 2>/dev/null | sed -n '1p') || trueExe=$(xargs -0 -n 1 < /proc/$$/cmdline | head -n 1) || return 1 |
Collaborator
There was a problem hiding this comment.
Would it also work to do instead:
head -n 1 /proc/$$/cmdline 2>/dev/null | cut -d '' -f1
or does that file with long commands also?
as suggested by mkelement0 in https://stackoverflow.com/a/23011530/7471760
and what about basename -- "$(readlink /proc/$$/exe)"
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request
Changes or fixes
Fixes #23746.
A newline in a shell argument makes
cutinclude text from later lines. This can sendthisroot.shthrough the wrong setup branch and leaveROOTSYSunset.This follows the approach suggested in the issue. It converts the NUL separators to newlines and prints the first line. Using
sedkeeps the input flowing so long commands also work withpipefailenabled.The regression test covers bash and zsh with single line commands and multiline commands. It also checks a long command with
pipefailenabled.Checklist
The original version failed the multiline cases. The
headversion failed the long command cases. The final change passed all six cases.The workspace reports process IDs that differ from its
/procentries. The temporary fixtures were adapted to read the real process ID. The committed test has no such adaptation. A full ROOT build and a run on a normal Linux system are still unverified.Codex with GPT 6 helped prepare the patch and tests.