]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/message.c
Final changes
[bacula/bacula] / bacula / src / lib / message.c
index 4fc1447aacf3801ed2a73eb6459972db8c85bf48..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++) {
@@ -423,7 +440,7 @@ void close_msg(JCR *jcr)
            }
            
            if (!(bpipe=open_mail_pipe(jcr, &cmd, d))) {
-               Dmsg0(000, "open mail pipe failed.\n");
+               Pmsg0(000, "open mail pipe failed.\n");
               goto rem_temp_file;
            }
             Dmsg0(150, "Opened mail pipe\n");
@@ -434,7 +451,7 @@ void close_msg(JCR *jcr)
               fputs(line, bpipe->wfd);
            }
            if (!close_wpipe(bpipe)) {       /* close write pipe sending mail */
-               Dmsg1(000, "close error: ERR=%s\n", strerror(errno));
+               Pmsg1(000, "close error: ERR=%s\n", strerror(errno));
            }
 
            /*