st.sh: pick free ports instead of counting QEMU instances - #325
Open
daniel-rossier wants to merge 1 commit into
Open
st.sh: pick free ports instead of counting QEMU instances#325daniel-rossier wants to merge 1 commit into
daniel-rossier wants to merge 1 commit into
Conversation
Starting a second emulator killed it on the spot:
qemu-system-arm: -netdev user,id=n1,hostfwd=tcp::2222-:22:
Could not set up host forwarding rule 'tcp::2222-:22'
The gdb port was already offset per instance, derived from a count of running
qemu-system processes, but the ssh forward stayed hardcoded at 2222. That
counter cannot work here anyway: dbuild.sh runs every command in its own
container, hence its own PID namespace, so a second container sees none of the
first one's processes and hands out the very ports it already holds — while
`docker run --network host` puts both on the same host stack.
Probe instead. free_port() walks up from a base until a TCP connect to
127.0.0.1 fails, which notices every listener on the host whichever namespace
opened it. The gdb stub and the ssh forward both go through it, and the chosen
port is printed, so attaching a debugger or an scp knows where to aim.
Validated with two emulators side by side, one on the host and one in a
container: 1234/2222 and 1235/2223, both booting to the SO3 prompt.
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.
Running two emulators at once — two trees side by side, or a leftover QEMU from
an earlier run — kills the second one at startup:
st.shalready offset the gdb port per instance, counting runningqemu-systemprocesses, but the ssh forward stayed hardcoded at 2222. And thatcounter cannot work under
dbuild.sh: each command runs in its own container,hence its own PID namespace, so a second container sees none of the first one's
processes and hands out the ports it already holds —
docker run --network hostputs both on the same host stack.This replaces the counter with a probe for the ports:
free_port()walks upfrom a base until a TCP connect to
127.0.0.1fails, which notices everylistener on the host whichever namespace opened it. Both the gdb stub and the
ssh forward go through it, and the chosen port is printed, so attaching a
debugger or an scp knows where to aim. The instance counter stays where it is
still correct: the guest MAC addresses.
Validated with two emulators side by side, one on the host and one inside a
container: 1234/2222 and 1235/2223, both booting to the SO3 prompt.