8000 application: Wait for cancellation when stdin is at EOF by JayOfTheKeyboard · Pull Request #214 · frida/frida-tools · GitHub
[go: up one dir, main page]

Skip to content

application: Wait for cancellation when stdin is at EOF - #214

Merged
oleavr merged 1 commit into
frida:mainfrom
JayOfTheKeyboard:fix-stdin-eof-wait
Nov 9, 2026
Merged

oleavr merged 1 commit into
frida:mainfrom
JayOfTheKeyboard:fix-stdin-eof-wait

Conversation

@JayOfTheKeyboard
Copy link
Copy Markdown
Contributor

When stdin is redirected from /dev/null, as it is in CI or under a script, readline() returns "" immediately. await_enter() takes that as Enter and stops the reactor before the tool's work has run, and await_ctrl_c() keeps calling it in a loop.

On main (6bbae44), Linux, local device:

$ echo hello > a.txt
$ frida-pull $PWD/a.txt $PWD/b.txt </dev/null; echo $?
0
$ ls b.txt
ls: cannot access 'b.txt': No such file or directory
  • frida-pull prints nothing, exits 0 and writes no file.
  • frida-push $PWD/a.txt $PWD/p.txt </dev/null creates p.txt empty and then hangs. The worker thread is still waiting on a reactor that has stopped, so SIGTERM doesn't end it either and it needs kill -9.
  • frida-trace -p <pid> -i nanosleep </dev/null and frida-compile -w index.js </dev/null run, but at 100% CPU: 498 CPU ticks over 5 s of steady state for frida-trace on main, 0 with this change.

With stdin kept open (sleep 10 | frida-pull ...) the pull and the push both work.

When stdin isn't a terminal, EOF means no line will ever arrive. So input_with_cancellable() now blocks on the cancellable's fd until it's cancelled, instead of returning the empty string. The Windows path already waits like this, since msvcrt.kbhit() never sees stdin's EOF. On a terminal an empty read means Ctrl-D, and that still returns as before. Enter and Ctrl-D still stop a tool that's waiting on them.

This does change one thing: frida-discover </dev/null used to stop straight away, and now it runs until it's interrupted or the target exits, the same as frida-trace. If you'd rather EOF on a pipe still meant "stop" there, I can make frida-discover keep the old behaviour.

Testing:

  • Added tests/test_application.py: a line read from a pipe is returned; at EOF on a pipe the call raises OperationCancelledError once the cancellable is cancelled; and Ctrl-D on a pty still returns "". The pipe EOF test fails on main with OperationCancelledError not raised.
  • python -m unittest discover -s tests -t .: 50 tests OK on main, 53 OK with this change. black, isort and pyflakes are clean.
  • Ran frida-pull, frida-push, frida-rm, frida-ls and frida-ps with </dev/null against the local device: they finish the same way they do with a terminal. frida-trace still exits on SIGTERM.
  • The macOS/FreeBSD branch uses the same helper, but I could only run it on Linux.

@oleavr
oleavr commented Nov 9, 2026 •
Copy link
Copy Markdown
Member

Thanks! 🙌

With stdin redirected from /dev/null, readline() returns "" right away,
so await_enter() stopped the reactor before frida-pull and frida-push
did their work, and await_ctrl_c() spun at 100% CPU.

When stdin is not a terminal, EOF means no line will ever arrive, so
block until cancelled. On a terminal an empty read is Ctrl-D, which
still returns as before.

This branch was successfully deployed

2 active deployments
testpypi — 30a3a889 Deployed Nov 9, 2026 by oleavr via Publish to TestPyPI #19
pypi — 30a3a889 Deployed Nov 9, 2026 by oleavr via Publish to PyPI #19
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

0