]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Keep dead console from killing asterisk (bug #3331)
authorRussell Bryant <russell@russellbryant.com>
Sat, 15 Jan 2005 19:58:41 +0000 (19:58 +0000)
committerRussell Bryant <russell@russellbryant.com>
Sat, 15 Jan 2005 19:58:41 +0000 (19:58 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/v1-0@4802 65c4cc65-6c06-0410-ace0-fbb531ad65f3

asterisk.c

index 909abc853bba49c1766035e933f34c123e7e2250..113e5a17254290336d72de09b34c20f04c92d1c2 100755 (executable)
@@ -1581,6 +1581,7 @@ int main(int argc, char *argv[])
        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 @@ int main(int argc, char *argv[])
 
                                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;
 }