]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/message.c
Final changes
[bacula/bacula] / bacula / src / lib / message.c
index dc7c4723ff7fc8897c6199a84035c89734ffb685..98c03a86b5ea74c4903f4b66502839dbea80a0be 100755 (executable)
@@ -158,12 +158,29 @@ void
 init_msg(JCR *jcr, MSGS *msg)
 {
    DEST *d, *dnew, *temp_chain = NULL;
+   int i, fd;
+
+   /*
+    * Make sure we have fd's 0, 1, 2 open
+    *  If we don't do this one of our sockets may open
+    *  there and if we then use stdout, it could
+    *  send total garbage to our socket.
+    *
+    */
+   fd = open("/dev/null", O_RDONLY, 0644);
+   if (fd > 2) {
+      close(fd);
+   } else {
+      for(i=1; fd + i <= 2; i++) {
+        dup2(fd, fd+i);
+      }
+   }
+
 
    /*
     * If msg is NULL, initialize global chain for STDOUT and syslog
     */
    if (msg == NULL) {
-      int i;
       daemon_msgs = (MSGS *)malloc(sizeof(MSGS));
       memset(daemon_msgs, 0, sizeof(MSGS));
       for (i=1; i<=M_MAX; i++) {