fix(environments): insert -- between setsid and bash to fix Termux (closes #37124)#37240
Closed
alaamohanad169-ship-it wants to merge 1 commit into
Closed
Conversation
Collaborator
13 tasks
f11c829 to
9ed97af
Compare
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.
Closes #37124
Root cause
GatewayRunnerbuilds an argv list for the detached restart and updatesubprocesses as
[setsid_bin, "bash", "-lc"|"-c", <command>]. POSIXrequires
--to terminate option parsing for the parent so that theflags destined for the child are not interpreted by the parent.
On Termux (util-linux
setsid2.41.3) thesetsidbinary advertises-c, --cttyand several other single-letter options. When invoked assetsid bash -lc <cmd>those flags can be swallowed bysetsiditself rather than forwarded to
bash, causing the spawned shellcommand to fail silently (no error message, just no execution).
The same hazard exists for the
/updatepath, which usessetsid bash -c <update_cmd>.Fix
Insert
--between thesetsidpath andbashin both call sitesin
gateway/run.py:gateway/run.py:3985— detached restart command (setsid bash -lc ...)gateway/run.py:14845— detached update command (setsid bash -c ...)After the change the argv is
[setsid_bin, "--", "bash", "-lc", <cmd>],which is POSIX-conformant and prevents the parent from consuming the
child's option flags on any conforming
setsidimplementation.Tests
tests/gateway/test_restart_drain.py::test_launch_detached_restart_command_uses_setsidto assert
cmd[:3] == ["/usr/bin/setsid", "--", "bash"].tests/gateway/test_update_command.py::TestHandleUpdateCommand::test_spawns_setsidto assert that index 1 of the argv is
"--"and index 2 is"bash".test_launch_detached_restart_command_inserts_double_dash_separator— a dedicated regression test that locates the setsid path in the
argv and asserts that
--,bash, and-lcfollow it in order.TestHandleUpdateCommand::test_spawns_setsid_with_double_dash_separator— same dedicated regression test for the
/updatepath (asserts--,bash, and-cfollow the setsid path).Test run (relevant file scope only):
Targeted regression tests (new and modified):
Manual verification (on Termux)
Ran a side-by-side subprocess test against this host's
/data/data/com.termux/files/usr/bin/setsid(util-linux 2.41.3).On this particular util-linux build
getopt_longstops at the firstnon-option (
bash) so the simpleechocases worked without--too,but the
--form is still required by POSIX and prevents the silentfailure mode on stricter / future
setsidimplementations. The newtests pin the correct argv shape so any regression will be caught.
Notes
upstream/main(merge-base verified == upstream/main HEAD).fork(alaamohanad169-ship-it/hermes-agent); PR openedagainst
NousResearch/hermes-agent:main.fix-flowpipeline (fix agent).