-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PDCurses' endwin implementation is not signal-safe #134
Comments
(Following applies to PDCurses and PDCursesMod). Your first bullet point doesn't apply to WinCon, because it already only reads I don't see any provision made for I think the only thing we need do is modify, in if( saved_screen && getenv("PDC_RESTORE_SCREEN")) to read
This both ensures that Making int signal_safe_endwin( void)
{
SP->we_are_in_a_signal_handler = TRUE;
return endwin( );
} ...basically, an The inability to call signal-unsafe functions would mean that not all memory would be freed and might have some other consequences not immediately apparent to me. Alternatively, is there a way, in either DOS or OS/2, for |
That shouldn't be done for multitude of reasons, one is that a
As noted above and also in the unix specification for
If there are other reasons then yes - a signal-safe endwin would be useful. Changing the logging state during the run is a different thing and definitely useful - maybe this can be done with a function call instead of the environment (so environment is only read during |
Ugh. You are correct. At present, in ncurses, DOS, VT, and OS/2, if you call Under VT and ncurses, the original screen will still be saved, and when you call The bit about not calling #ifdef PDCURSES
delscreen( SP);
#endif The
At present, if you turn any logging on and then shut it off, we do an |
…form-specific memory allocations. Also a start to fixing issue wmcbrine/PDCurses#134, to make endwin() signal-safe (still some work to do on that front, though.)
…gnal-safe functions, meaning (at the very least) debugging should be turned off. I think this fixes wmcbrine/PDCurses#134.
@GitMensch - this should be fixed in the PDCursesMod fork now. Give it a try and see what you think. Solution was in two (fairly easy) parts, which could also apply to PDCurses. First, those memory allocations in the DOS and OS/2 platforms are not freed in Second, we set an As noted above, the first fix also fixes a bug on DOS and OS/2 : if you called |
Obviously PCursesMod removed @Bill-Gray: could you please summarize the necessary changes / link the appropriate commits so that this may be handled correctly here, too? |
@GitMensch - can't say I wound up doing much for this (it didn't take many changes). Commit Bill-Gray/PDCursesMod@18ff2cb00c040a3 added a bit of logic to say that if we're in That was basically all I did. Details would vary in PDCurses, but the fixes would be the same. |
When an application is in curses mode either the application or curses should take care to "reset" the screen when it exits.
One of the things that a curses application may does is to register an error handler (commonly a signal handler) which calles
endwin()
. It should not calldelwin()
as the necessaryfree()
calls in there are problematic and "the application is going to exit afterwards in any case". Also: if the OS (or application) creates a coredump afterwardsdelwin()
is likely to clean some traces which may be useful to debug some issues, and also for a signal handler "faster is better".This often works fine - but the chances with PDCurses (@Bill-Gray also applies to PDCursesMod) are less good.
One of the reasons is the use of
PDC_LOG
macro which itself calls some unsafe functions, for many ports one of the reasons is also the check ofPDC_RESTORE_SCREEN
inPDC_scr_close()
as this usesgetenv()
which should not be used in a signal handler, see the manpage for signal-safety.Note: this is not a theoretic issue - I've recently debugged a bunch of memory issues in an application and if its signal handler is called because of memory issues in
free
ormalloc
, then the call toendwin()
in there currently is not unlikely to create a lock issue or re-raises a SIGSEGV (or in case of glibc checks a SIGABRT) so the rest of the signal handler is not executed. This potentially prevents generation of coredumps, too :-(My suggestions:
PDC_RESTORE_SCREEN
ininitscr()
and place the result in a static var, possibly add a function to toggle it later in the application (or implicit re-read it at other places likerefresh()
orgetch()
)endwin()
and called functions, or only do the logging depending on static variables (see suggestion forPDC_RESTORE_SCREEN
)endwin()
(and drop an implementation use about the functions to (not) use inPDC_scr_close()
Related (but does not need to be adjusted together) #133.
The text was updated successfully, but these errors were encountered: