[Asterisk-cvs] asterisk asterisk.c,1.125.2.4,1.125.2.5

russell at lists.digium.com russell at lists.digium.com
Sat Jan 15 13:55:11 CST 2005


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv4096

Modified Files:
      Tag: v1-0
	asterisk.c 
Log Message:
Keep dead console from killing asterisk (bug #3331)


Index: asterisk.c
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.c,v
retrieving revision 1.125.2.4
retrieving revision 1.125.2.5
diff -u -d -r1.125.2.4 -r1.125.2.5
--- asterisk.c	30 Dec 2004 21:16:25 -0000	1.125.2.4
+++ asterisk.c	15 Jan 2005 19:58:41 -0000	1.125.2.5
@@ -1581,6 +1581,7 @@
 	int num;
 	char *buf;
 	char *runuser=NULL, *rungroup=NULL;
+	struct pollfd silly_macos[1];	
 
 	/* Remember original args for restart */
 	if (argc > sizeof(_argv) / sizeof(_argv[0]) - 1) {
@@ -1907,16 +1908,24 @@
 
 				consolehandler((char *)buf);
 			} else {
-				if (option_remote)
-					ast_cli(STDOUT_FILENO, "\nUse EXIT or QUIT to exit the asterisk console\n");
+				if (write(STDOUT_FILENO, "\nUse EXIT or QUIT to exit the asterisk console\n",
+								  strlen("\nUse EXIT or QUIT to exit the asterisk console\n")) < 0) {
+					/* Whoa, stdout disappeared from under us... Make /dev/null's */
+					int fd;
+					fd = open("/dev/null", O_RDWR);
+					if (fd > -1) {
+						dup2(fd, STDOUT_FILENO);
+						dup2(fd, STDIN_FILENO);
+					} else
+						ast_log(LOG_WARNING, "Failed to open /dev/null to recover from dead console.  Bad things will happen!\n");
+					break;
+				}
 			}
 		}
 
-	} else {
-		struct pollfd silly_macos[1];	
-		/* Do nothing */
-		for(;;) 
-			poll(silly_macos,0, -1);
 	}
+	/* Do nothing */
+	for(;;) 
+		poll(silly_macos,0, -1);
 	return 0;
 }




More information about the svn-commits mailing list