Merge pull request #27 from Herringway/master

Exit gracefully when piped stdout becomes invalid
This commit is contained in:
Kevin Lange 2013-12-15 20:11:26 -08:00
commit 837cd32902

View File

@ -185,6 +185,14 @@ void SIGALRM_handler(int sig) {
/* Unreachable */ /* Unreachable */
} }
/*
* Handle the loss of stdout, as would be the case when
* in telnet mode and the client disconnects
*/
void SIGPIPE_handler(int sig) {
finish();
}
/* /*
* Telnet requires us to send a specific sequence * Telnet requires us to send a specific sequence
* for a line break (\r\000\n), so let's make it happy. * for a line break (\r\000\n), so let's make it happy.
@ -563,6 +571,9 @@ int main(int argc, char ** argv) {
int always_escape = 0; /* Used for text mode */ int always_escape = 0; /* Used for text mode */
/* Accept ^C -> restore cursor */ /* Accept ^C -> restore cursor */
signal(SIGINT, SIGINT_handler); signal(SIGINT, SIGINT_handler);
/* Handle loss of stdout */
signal(SIGPIPE, SIGPIPE_handler);
switch (ttype) { switch (ttype) {
case 1: case 1:
colors[','] = "\033[48;5;17m"; /* Blue background */ colors[','] = "\033[48;5;17m"; /* Blue background */