fix(cli): fallback to TERMUX_ORIGINAL_EXE_PATH to prevent linker64 crash in Termux#27563
fix(cli): fallback to TERMUX_ORIGINAL_EXE_PATH to prevent linker64 crash in Termux#27563Gong-Mi wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical issue affecting Node.js applications running within Termux, where the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for Termux environments by checking the TERMUX_ORIGINAL_EXE_PATH environment variable when spawning child processes, falling back to process.execPath if it is not defined. The reviewer suggests trimming the TERMUX_ORIGINAL_EXE_PATH environment variable across all modified files (index.ts, processUtils.ts, and relaunch.ts) to robustly handle empty or whitespace-only strings and ensure a safe fallback.
| const execPath = process.env['TERMUX_ORIGINAL_EXE_PATH'] || process.execPath; | ||
| const child = spawn(execPath, spawnArgs, { |
There was a problem hiding this comment.
To prevent issues where the TERMUX_ORIGINAL_EXE_PATH environment variable might be set to an empty or whitespace-only string, we should trim the value before checking its truthiness. This ensures a robust fallback to process.execPath in all invalid environment configurations.
| const execPath = process.env['TERMUX_ORIGINAL_EXE_PATH'] || process.execPath; | |
| const child = spawn(execPath, spawnArgs, { | |
| const execPath = process.env['TERMUX_ORIGINAL_EXE_PATH']?.trim() || process.execPath; | |
| const child = spawn(execPath, spawnArgs, { |
References
- When using an optional string with a fallback value, trim the optional string and use the fallback if the result is empty to avoid uninformative messages from whitespace-only strings.
| // We explicitly use process.execPath to break the cycle and prevent | ||
| // compounding argument duplication on subsequent relaunches. | ||
| finalSpawnArgs.push(process.execPath, ...scriptArgs); | ||
| const execPath = process.env['TERMUX_ORIGINAL_EXE_PATH'] || process.execPath; | ||
| finalSpawnArgs.push(execPath, ...scriptArgs); |
There was a problem hiding this comment.
We should trim the TERMUX_ORIGINAL_EXE_PATH environment variable to safely handle empty or whitespace-only values. Additionally, let's update the comment to refer to the resolved executable path generally rather than hardcoding process.execPath in the description, keeping the documentation accurate.
| // We explicitly use process.execPath to break the cycle and prevent | |
| // compounding argument duplication on subsequent relaunches. | |
| finalSpawnArgs.push(process.execPath, ...scriptArgs); | |
| const execPath = process.env['TERMUX_ORIGINAL_EXE_PATH'] || process.execPath; | |
| finalSpawnArgs.push(execPath, ...scriptArgs); | |
| // We explicitly use the executable path to break the cycle and prevent | |
| // compounding argument duplication on subsequent relaunches. | |
| const execPath = process.env['TERMUX_ORIGINAL_EXE_PATH']?.trim() || process.execPath; | |
| finalSpawnArgs.push(execPath, ...scriptArgs); |
References
- When using an optional string with a fallback value, trim the optional string and use the fallback if the result is empty to avoid uninformative messages from whitespace-only strings.
| const execPath = process.env['TERMUX_ORIGINAL_EXE_PATH'] || process.execPath; | ||
| const child = spawn(execPath, spawnArgs, { |
There was a problem hiding this comment.
Trim the TERMUX_ORIGINAL_EXE_PATH environment variable to ensure that any empty or whitespace-only values correctly fall back to process.execPath and do not cause spawn failures.
| const execPath = process.env['TERMUX_ORIGINAL_EXE_PATH'] || process.execPath; | |
| const child = spawn(execPath, spawnArgs, { | |
| const execPath = process.env['TERMUX_ORIGINAL_EXE_PATH']?.trim() || process.execPath; | |
| const child = spawn(execPath, spawnArgs, { |
References
- When using an optional string with a fallback value, trim the optional string and use the fallback if the result is empty to avoid uninformative messages from whitespace-only strings.
This fixes the issue where termux-exec replaces the process.execPath with linker64, causing Node.js spawn to fail when arguments start with a dash. We now use TERMUX_ORIGINAL_EXE_PATH if available.