mirror of
https://github.com/martijnvanbrummelen/nwipe.git
synced 2026-02-21 06:22:35 +00:00
when Konsole terminal exited while nwipe is sitting at the drive selection screen. To avoid 100% CPU usage, check for a runaway condition caused by the function "keystroke = getch() that immediately returns an error condition. We check for an error condition because getch() returns a ERR value when the timeout value "timeout( 250 );" expires as well as when a real error occurs. We can't differentiate from normal operation and a failure of the getch function to block for the specified period of timeout. So here we check the while loop hasn't exceeded the number of expected iterations per second ie. a timeout(250) block value of 250ms means we should not see any more than (1000/250) = 4 iterations. We double this to 8 to allow a little tolerance. Why is this necessary? It's been found that in KDE konsole and other terminals based on the QT terminal engine exiting the terminal without first existing nwipe results in nwipe remaining running but detached from any interface which causes getch to fail and its associated timeout. So the CPU or CPU core rises to 100%. Here we detect that failure and exit nwipe gracefully with the appropriate error. This does not affect use of tmux for attaching or detaching from a running nwipe session when sitting at the selection screen. All other terminals correctly terminate nwipe when the terminal itself is exited.