]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bpipe.c
Add new hash table class
[bacula/bacula] / bacula / src / lib / bpipe.c
index 7b284c9ce9dce17587c5769a33cf1ec00fc55a8a..0a00caf73cc53c2bc2799b16e2192239d24b6ec1 100644 (file)
@@ -57,7 +57,7 @@ BPIPE *open_bpipe(char *prog, int wait, char *mode)
    /* Build arguments for running program. */
    tprog = get_pool_memory(PM_FNAME);
    pm_strcpy(&tprog, prog);
-   build_argc_argv(tprog, &bargc, bargv, MAX_ARGV);
+   build_argc_argv(mp_chr(tprog), &bargc, bargv, MAX_ARGV);
 #ifdef xxxxxx
    printf("argc=%d\n", bargc);
    int i;
@@ -78,7 +78,7 @@ BPIPE *open_bpipe(char *prog, int wait, char *mode)
    }
    /* Start worker process */
    switch (bpipe->worker_pid = fork()) {
-   case -1:
+   case -1:                          /* error */
       free(bpipe);
       return NULL;
 
@@ -158,12 +158,17 @@ int close_bpipe(BPIPE *bpipe)
 
    /* wait for worker child to exit */
    for ( ;; ) {
+      Dmsg2(200, "Wait for %d opt=%d\n", bpipe->worker_pid, wait_option);
       wpid = waitpid(bpipe->worker_pid, &chldstatus, wait_option);
       if (wpid == bpipe->worker_pid || (wpid == -1 && errno != EINTR)) {
+         Dmsg3(200, "Got break wpid=%d status=%d ERR=%s\n", wpid, chldstatus,
+            wpid==-1?strerror(errno):"none");
         break;
       }
+      Dmsg3(200, "Got wpid=%d status=%d ERR=%s\n", wpid, chldstatus,
+            wpid==-1?strerror(errno):"none");
       if (remaining_wait > 0) {
-        sleep(1);                    /* wait one second */
+        bmicrosleep(1, 0);            /* wait one second */
         remaining_wait--;
       } else {
         stat = 1;                    /* set error status */
@@ -175,8 +180,10 @@ int close_bpipe(BPIPE *bpipe)
    if (wpid > 0) {
       if (WIFEXITED(chldstatus)) {          /* process exit()ed */
         stat = WEXITSTATUS(chldstatus);
+          Dmsg1(200, "status =%d\n", stat);
       } else if (WIFSIGNALED(chldstatus)) {  /* process died */
         stat = 1;
+         Dmsg0(200, "Signaled\n");
       }
       if (stat != 0) {
         errno = ECHILD;              /* set child errno */
@@ -186,9 +193,7 @@ int close_bpipe(BPIPE *bpipe)
       stop_child_timer(bpipe->timer_id);
    }
    free(bpipe);
-#ifdef HAVE_FREEBSD_OS
-   stat = 0;  /* kludge because FreeBSD doesn't seem to return valid status */
-#endif
+   Dmsg1(200, "returning stat = %d\n", stat);
    return stat;
 }
 
@@ -215,8 +220,8 @@ int run_program(char *prog, int wait, POOLMEM *results)
       return 0;
    }
    if (results) {
-      results[0] = 0;
-      stat1 = fgets(results, sizeof_pool_memory(results), bpipe->rfd) == NULL;
+      mp_chr(results)[0] = 0;
+      stat1 = fgets(mp_chr(results), sizeof_pool_memory(results), bpipe->rfd) == NULL;
    } else {
       stat1 = 0;
    }