December 2012

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829
3031     

Style Credit

Expand Cut Tags

No cut tags

December 16th, 2012

paxed: It's a Hand! (Default)
Sunday, December 16th, 2012 08:14 pm
Whoa, has it been this long already? Anyway...

Assume you have an ncurses program that is used remotely (either via telnet or ssh) and it resides in a chroot. The program (of course) needs terminfo files inside the chroot.

Usually, ncurses mode is started with:

initscr();


But what happens when user uses some strange terminal (for which you have no terminfo file for) to connect? The program will show a black screen or quit, because initscr fails.

Use newterm instead:

if (newterm(NULL, stdout, stdin) == NULL) {
if (newterm(DEFAULT_TERM, stdout, stdin) == NULL) {
/* Die! */
}
setenv("TERM", DEFAULT_TERM, 1);
}


Just #define DEFAULT_TERM "xterm" or whatever you want to use and have terminfo file for. The setenv is optional, but good if you plan on exec'ing other programs.