]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bpipe.c
19July06
[bacula/bacula] / bacula / src / lib / bpipe.c
index ca8291366355dbb0fca49dceb68612df423ed147..12a5d8b925397c591c0a329e84314ff79d0165ee 100644 (file)
@@ -6,7 +6,7 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2002-2005 Kern Sibbald
+   Copyright (C) 2002-2006 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
 #include "bacula.h"
 #include "jcr.h"
 
-int execvp_errors[] = {EACCES, ENOEXEC, EFAULT, EINTR, E2BIG,
-                     ENAMETOOLONG, ENOMEM, ETXTBSY, ENOENT};
+int execvp_errors[] = {
+        EACCES,
+        ENOEXEC,
+        EFAULT,
+        EINTR,
+        E2BIG,
+        ENAMETOOLONG,
+        ENOMEM,
+#ifndef HAVE_WIN32
+        ETXTBSY,
+#endif
+        ENOENT
+};
 int num_execvp_errors = (int)(sizeof(execvp_errors)/sizeof(int));
 
 
@@ -62,13 +73,13 @@ BPIPE *open_bpipe(char *prog, int wait, const char *mode)
       printf("argc=%d argv=%s:\n", i, bargv[i]);
    }
 #endif
-   free_pool_memory(tprog);
 
    /* Each pipe is one way, write one end, read the other, so we need two */
    if (mode_write && pipe(writep) == -1) {
       save_errno = errno;
       free(bpipe);
       errno = save_errno;
+      free_pool_memory(tprog);
       return NULL;
    }
    if (mode_read && pipe(readp) == -1) {
@@ -79,6 +90,7 @@ BPIPE *open_bpipe(char *prog, int wait, const char *mode)
       }
       free(bpipe);
       errno = save_errno;
+      free_pool_memory(tprog);
       return NULL;
    }
    /* Start worker process */
@@ -95,6 +107,7 @@ BPIPE *open_bpipe(char *prog, int wait, const char *mode)
       }
       free(bpipe);
       errno = save_errno;
+      free_pool_memory(tprog);
       return NULL;
 
    case 0:                            /* child */
@@ -120,11 +133,10 @@ BPIPE *open_bpipe(char *prog, int wait, const char *mode)
       }
       exit(255);                      /* unknown errno */
 
-
-
    default:                           /* parent */
       break;
    }
+   free_pool_memory(tprog);
    if (mode_read) {
       close(readp[1]);                /* close unused parent fds */
       bpipe->rfd = fdopen(readp[0], "r"); /* open file descriptor */
@@ -220,8 +232,12 @@ int close_bpipe(BPIPE *bpipe)
          }
          Dmsg1(800, "child status=%d\n", stat & ~b_errno_exit);
       } else if (WIFSIGNALED(chldstatus)) {  /* process died */
+#ifndef HAVE_WIN32
          stat = WTERMSIG(chldstatus);
-         Dmsg1(800, "Child died from signale %d\n", stat);
+#else
+#warning "WTERMSIG undefined in Win32 !!!"
+#endif
+         Dmsg1(800, "Child died from signal %d\n", stat);
          stat |= b_errno_signal;      /* exit signal returned */
       }
    }