]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bpipe.c
Restructure tree.c + misc
[bacula/bacula] / bacula / src / lib / bpipe.c
index 50d81e596e4952b484fccd0f0f32da3d009811ef..6955aa650e0899838401f1d6b02be79fbec2687a 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2002-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -72,12 +72,24 @@ BPIPE *open_bpipe(char *prog, int wait, const char *mode)
       return NULL;
    }
    if (mode_read && pipe(readp) == -1) {
+      if (mode_write) {
+        close(writep[0]);
+        close(writep[1]);
+      }
       free(bpipe);
       return NULL;
    }
    /* Start worker process */
    switch (bpipe->worker_pid = fork()) {
    case -1:                          /* error */
+      if (mode_write) {
+        close(writep[0]);
+        close(writep[1]);
+      }
+      if (mode_read) {
+        close(readp[0]);
+        close(readp[1]);
+      }
       free(bpipe);
       return NULL;
 
@@ -91,7 +103,8 @@ BPIPE *open_bpipe(char *prog, int wait, const char *mode)
         dup2(readp[1], 1);           /* dup our read to his stdout */
         dup2(readp[1], 2);           /*   and his stderr */
       }
-      for (i=3; i<=32; i++) {    /* close any open file descriptors */
+      closelog();                    /* close syslog if open */
+      for (i=3; i<=32; i++) {        /* close any open file descriptors */
         close(i);
       }
       execvp(bargv[0], bargv);       /* call the program */
@@ -189,6 +202,7 @@ int close_bpipe(BPIPE *bpipe)
       if (WIFEXITED(chldstatus)) {          /* process exit()ed */
         stat = WEXITSTATUS(chldstatus);
         if (stat != 0) {
+            Dmsg1(100, "Non-zero status %s returned from child.\n", stat);
            stat = ECHILD;
         }
          Dmsg1(200, "child status=%d\n", stat);