-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
Describe the bug
While improving the west rtt command, I ran into an issue where everything worked successfully, but when I pressed Ctrl+C (which sends SIGINT / KeyboardInterrupt), nc, openocd, ninja, cmake and other processes were not terminated correctly.
I traced this to netcat (nc) which ignores SIGINT, (at least under Ubuntu 22.04).
- What target platform are you using? Any
- What have you tried to diagnose or workaround this issue? traced the problem to
run_telnet_client() - Is this a regression? unsure
To Reproduce
Steps to reproduce the behavior:
- use
west rtt - press
Ctrl+C - See error (shown in "logs and console output")
Expected behavior
Child processes of west (including nc) would be terminated
Impact
It's kind of a showstopper, since attempting to run more than 1 invocation of west rtt will fail until the user manually terminates all of the lingering processes from the previous run. Note: this isn't a problem with west rtt, but with run_telnet_client().
Logs and console output
Successfully running west rtt (for openocd, with fixes from #81195)
$ west build -p -S rtt-console -b nucleo_l496zg -t rtt samples/hello_world/
...
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080008a4 msp: 0x20001640
Start address 0x080008a4, load size 17250
Transfer rate: 18 KB/sec, 1725 bytes/write.
Info : Unable to match requested speed 500 kHz, using 480 kHz
Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
Unable to match requested speed 500 kHz, using 480 kHz
Info : rtt: Searching for control block 'SEGGER RTT'
rtt: Searching for control block 'SEGGER RTT'
Info : rtt: Control block found at 0x20000410
rtt: Control block found at 0x20000410
Info : Listening on port 5555 for rtt connections
Listening on port 5555 for rtt connections
Detaching from program: /home/cfriedt/zephyrproject/zephyr/build/zephyr/zephyr.elf, Remote target
[Inferior 1 (Remote target) detached]
Debugger detaching: resuming execution
Warn : target not halted
Error executing event gdb-detach on target stm32l4x.cpu:
Info : dropped 'gdb' connection
Info : accepting 'rtt' connection on tcp/5555
*** Booting Zephyr OS build v4.0.0-rc3-3-gfba2b206c8ae ***
Hello World! nucleo_l496zg/stm32l496xxLeftover processes after running west rtt and terminating it with Ctrl+C
$ ps -Afw | grep "nc\|telnet\|openocd\|rtt"
...
cfriedt 61034 1 0 09:39 pts/7 00:00:00 /usr/bin/cmake --build /home/cfriedt/zephyrproject/zephyr/build --target rtt
cfriedt 61035 61034 0 09:39 pts/7 00:00:00 /usr/bin/ninja rtt
cfriedt 61036 61035 0 09:39 pts/7 00:00:00 /usr/bin/cmake -E env /opt/zephyr/.venv/bin/python3 -m west rtt
cfriedt 61039 61036 1 09:39 pts/7 00:00:00 /opt/zephyr/.venv/bin/python3 -m west rtt
cfriedt 61484 61039 2 09:39 ? 00:00:00 /opt/zephyr/zephyr-sdk-0.17.0/sysroots/x86_64-pokysdk-linux/usr/bin/openocd -s /home/cfriedt/zephyrproject/zephyr/boards/st/nucleo_l496zg/support -s /opt/zephyr/zephyr-sdk-0.17.0/sysroots/x86_64-pokysdk-linux/usr/share/openocd/scripts -f /home/cfriedt/zephyrproject/zephyr/boards/st/nucleo_l496zg/support/openocd.cfg -c tcl_port 6333 -c telnet_port 4444 -c gdb_port 3333 -c init -c targets -c halt
cfriedt 61634 61039 0 09:39 pts/7 00:00:00 nc localhost 5555
...Also a problem with the current JLink runner
> ps -Afw | grep -i "jlink\|rtt"
cfriedt 969192 1 1 16:09 pts/4 00:00:00 JLinkRTTLogger -Device NRF52833_XXAA -If SWD -Speed 4000 -RTTChannel 0 -USB 000801006876 /tmp/rtt_output.log
cfriedt 969198 969192 0 16:09 pts/4 00:00:00 [JLinkGUIServerE] <defunct>
cfriedt 969245 958956 0 16:09 pts/4 00:00:00 grep --color=auto -i jlink\|rttEnvironment (please complete the following information):
- OS: Ubuntu 22.04 (and likely others)
- Toolchain: Zephyr SDK
- Commit SHA: c50777a (
v4.0.0-rc3)
Additional context
Discovered while working on #81156