[asterisk-commits] tilghman: branch 1.4 r163383 - /branches/1.4/main/asterisk.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Dec 11 17:35:55 CST 2008


Author: tilghman
Date: Thu Dec 11 17:35:55 2008
New Revision: 163383

URL: http://svn.digium.com/view/asterisk?view=rev&rev=163383
Log:
When a Ctrl-C or Ctrl-D ends a remote console, on certain shells, the terminal
is messed up.  By intercepting those events with a signal handler in the remote
console, we can avoid those issues.
(closes issue #13464)
 Reported by: tzafrir
 Patches: 
       20081110__bug13464.diff.txt uploaded by Corydon76 (license 14)
 Tested by: blitzrage

Modified:
    branches/1.4/main/asterisk.c

Modified: branches/1.4/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/asterisk.c?view=diff&rev=163383&r1=163382&r2=163383
==============================================================================
--- branches/1.4/main/asterisk.c (original)
+++ branches/1.4/main/asterisk.c Thu Dec 11 17:35:55 2008
@@ -1361,6 +1361,11 @@
 	}
 	/* There is no need to restore the signal handler here, since the app
 	 * is going to exit */
+}
+
+static void __remote_quit_handler(int num)
+{
+	sig_flags.need_quit = 1;
 }
 
 static const char *fix_header(char *outbuf, int maxout, const char *s, char *cmp)
@@ -2306,6 +2311,11 @@
 	char *ebuf;
 	int num = 0;
 
+	memset(&sig_flags, 0, sizeof(sig_flags));
+	signal(SIGINT, __remote_quit_handler);
+	signal(SIGTERM, __remote_quit_handler);
+	signal(SIGHUP, __remote_quit_handler);
+
 	if (read(ast_consock, buf, sizeof(buf)) < 0) {
 		ast_log(LOG_ERROR, "read() failed: %s\n", strerror(errno));
 		return;
@@ -2313,6 +2323,9 @@
 	if (data) {
 		if (write(ast_consock, data, strlen(data) + 1) < 0) {
 			ast_log(LOG_ERROR, "write() failed: %s\n", strerror(errno));
+			if (sig_flags.need_quit == 1) {
+				return;
+			}
 		}
 	}
 	stringp = buf;
@@ -2358,6 +2371,10 @@
 			char buf[512] = "", *curline = buf, *nextline;
 			int not_written = 1;
 
+			if (sig_flags.need_quit == 1) {
+				break;
+			}
+
 			if (read(ast_consock, buf, sizeof(buf) - 1) <= 0) {
 				break;
 			}
@@ -2388,6 +2405,10 @@
 	}
 	for (;;) {
 		ebuf = (char *)el_gets(el, &num);
+
+		if (sig_flags.need_quit == 1) {
+			break;
+		}
 
 		if (!ebuf && write(1, "", 1) < 0)
 			break;




More information about the asterisk-commits mailing list