fix ncurses termination handling
PhotoRec often corrupted the terminal when killed with Ctrl+C in ncurses mode. Users had to run reset or stty sane to restore normal terminal functionality after interrupting the program. This PR fixes that.
All functions called by end_ncurses() may not be signal-safe but it seems to work without side effect under Linux Fedora 41 with this shorted patch:
--- /home/kmaster/src/git/testdisk/src/phmain.c 2023-02-19 08:04:54.627483562 +0100 +++ ./phmain.c 2025-09-28 14:11:26.295956987 +0200 @@ -112,6 +112,9 @@ log_flush(); if(need_to_stop==1) { +#ifdef HAVE_NCURSES
- end_ncurses(); +#endif action.sa_handler=SIG_DFL; sigaction(sig,&action,NULL); kill(0, sig);
src/testdisk.c will need to get a similar patch. Under which OS have you tested this patch ?
@cgsecurity
piotr@pjoter:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04.3 LTS
Release: 24.04
Codename: noble
piotr@pjoter:~$ echo $SHELL
/bin/bash