iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.36k stars 3.86k forks source link

tools/bashreadline: Fix bashreadline #4903

Closed sancppp closed 7 months ago

sancppp commented 8 months ago

This Pull Request fixes the issue where the bashreadline tool would lose the first bash command upon startup.

At runtime, bash blocks at the readline function in bash::readline.c. Upon receiving the Enter key signal, it calls the readline_internal_teardown function to retrieve the user's input. Therefore, changing the hook function from readline to readline_internal_teardown resolves the issue of losing the first bash command after startup of bashreadline.

The specific approach is to open the symbol table of bash and check if there is a symbol for readline_internal_teardown function. If not, continue to use the readline function as the hook position.

yonghong-song commented 7 months ago

Could you give more details about how to reproduce lose the first bash command upon startup? That is, give a sequence of commands where the result will be different with vs. without your patch.

sancppp commented 7 months ago

Could you give more details about how to reproduce lose the first bash command upon startup? That is, give a sequence of commands where the result will be different with vs. without your patch.

https://github.com/iovisor/bcc/assets/67474179/5330ffd7-d873-4918-997f-388541452871

https://github.com/iovisor/bcc/assets/67474179/3b675585-43d9-4980-8525-21d69a8c3dc8