Open FulecoRafa opened 1 year ago
I think we could create an exit function with all the code that must be executed before the program exits, and we can bind the exit signals to it, this could solve the problem and create an API in case it is necessary to add new functions along with the exit.
do you know any mechanism for binding the exit signals to a function call? if you give me the direction I may try to correct this today
This is compiler dependent. For the gnu compiler, which is what I believe to be the default for this project, that would be a quit
or an exit
named function. Do not remember the name from the top of my head, but I'm certain it exists.
I have replicated the bug with the exit(1) call, but still have doubts on how to handle so uncaught errors are directed to the terminate function.
Then curses library should have an unit function that prepares the library. On this function, it changes the terminal mode. It should also have a terminate function, which stops the library and reverts the terminal mode. This function should be called whether the program terminates or crashes.
https://stackoverflow.com/questions/11753909/clean-up-ncurses-mess-in-terminal-after-a-crash I think this question describes exactly what we need. Apparently one possible solution is to use curses signal handling to handle SIGTERM. I will try out this and open a PR for further tests if it is any good.
It seems like we are mixing up different concepts.
sigset/signal/sigaction
. exit(1)
requires us to register atexit/on_exit
functions.There's already some work done related to signal handling, so for exits here's a brief guide.
These handlers can be simple wrappers that call a code defined finalize_game
or ncurses' endwin
directly.
As of now, the ncurses library is not properly deactivated in case the program panics during runtime. This presents a problem because as soon is the program exits with the panic, the user terminal stays in a mode which breaks output and is really annoying.
Steps to replicate the issue
exit(1)
What should happen
exit(1)