Restore terminal if exit is called inside a TCL script at startup

If exit is called in a TCL script that is executed at startup, the libc
exit() function is called directly and we don't get a chance to reset
the terminal. We return to the shell with echo off, and have to run
"reset". A simple example:

echo exit > test.tcl
magic -noconsole -dnull  test.tcl

There are a few ways we could solve this. We could register an exit
handler using atexit(). Here I use Tcl_SetExitProc() to register a
callback with the TCL interpreter.
This commit is contained in:
Anton Blanchard 2021-02-18 11:26:02 +11:00 committed by Anton Blanchard
parent 48b04385c3
commit bdeb4bab50
1 changed files with 11 additions and 0 deletions

View File

@ -770,6 +770,12 @@ mainInitAfterArgs()
return 0;
}
void tcl_exit_hook(ClientData clientData)
{
TxResetTerminal();
exit(0);
}
/*
* ----------------------------------------------------------------------------
* mainInitFinal:
@ -794,6 +800,9 @@ mainInitFinal()
char *rname;
int result;
/* Reset terminal if exit is called inside a TCL script */
Tcl_SetExitProc(tcl_exit_hook);
#ifdef MAGIC_WRAPPER
/* Read in system pre-startup file, if it exists. */
@ -1187,6 +1196,8 @@ mainInitFinal()
UndoFlush();
TxClearPoint();
Tcl_SetExitProc(NULL);
return 0;
}