]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bpipe.c
Doc + fix automount on files
[bacula/bacula] / bacula / src / lib / bpipe.c
index fdb3f634fad2376710dfa497ebeadce3409d6fec..975c5f6896f5efbec918dbbc07091f58a9f6c8f7 100644 (file)
@@ -58,7 +58,7 @@ BPIPE *open_bpipe(char *prog, int wait, char *mode)
    tprog = get_pool_memory(PM_FNAME);
    pm_strcpy(&tprog, prog);
    build_argc_argv(tprog, &bargc, bargv, MAX_ARGV);
-#ifdef xxxxxx
+#ifdef xxxxxx
    printf("argc=%d\n", bargc);
    int i;
    for (i=0; i<bargc; i++) {
@@ -163,17 +163,25 @@ int close_bpipe(BPIPE *bpipe)
         break;
       }
       if (remaining_wait > 0) {
-        sleep(1);                    /* wait one second */
+        bmicrosleep(1, 0);            /* wait one second */
         remaining_wait--;
       } else {
-        stat = ETIME;                /* set timeout, if no other status */
+        stat = 1;                    /* set error status */
+        errno = ETIME;               /* set timed out */
         wpid = -1;
          break;                       /* don't wait any longer */
       }
    }
-   if (wpid != -1 && WIFEXITED(chldstatus)) {
-      stat = WEXITSTATUS(chldstatus);
-   }
+   if (wpid > 0) {
+      if (WIFEXITED(chldstatus)) {          /* process exit()ed */
+        stat = WEXITSTATUS(chldstatus);
+      } else if (WIFSIGNALED(chldstatus)) {  /* process died */
+        stat = 1;
+      }
+      if (stat != 0) {
+        errno = ECHILD;              /* set child errno */
+      }
+   }  
    if (bpipe->timer_id) {
       stop_child_timer(bpipe->timer_id);
    }
@@ -189,6 +197,11 @@ int close_bpipe(BPIPE *bpipe)
  * Run an external program. Optionally wait a specified number
  *   of seconds. Program killed if wait exceeded. Optionally
  *   return the output from the program (normally a single line).
+ *
+ * Contrary to my normal calling conventions, this program 
+ *
+ *  Returns: 0 on success
+ *          non-zero on error
  */
 int run_program(char *prog, int wait, POOLMEM *results)
 {
@@ -203,12 +216,12 @@ int run_program(char *prog, int wait, POOLMEM *results)
    }
    if (results) {
       results[0] = 0;
-      stat1 = fgets(results, sizeof_pool_memory(results), bpipe->rfd) != NULL;
+      stat1 = fgets(results, sizeof_pool_memory(results), bpipe->rfd) == NULL;
    } else {
-      stat1 = 1;
+      stat1 = 0;
    }
    stat2 = close_bpipe(bpipe);
-   return stat1 && stat2;
+   return stat2 != 0 ? stat2 : stat1; 
 }
 
 
@@ -217,8 +230,8 @@ int run_program(char *prog, int wait, POOLMEM *results)
  */
 static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_argv)
 {
-   int i, quote;
-   char *p, *q;
+   int i;      
+   char *p, *q, quote;
    int argc = 0;
 
    argc = 0;
@@ -229,15 +242,15 @@ static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_argv)
    quote = 0;
    while  (*p && (*p == ' ' || *p == '\t'))
       p++;
-   if (*p == '\"') {
-      quote = 1;
+   if (*p == '\"' || *p == '\'') {
+      quote = *p;
       p++;
    }
    if (*p) {
       while (*p && argc < MAX_ARGV) {
         q = p;
         if (quote) {
-            while (*q && *q != '\"')
+           while (*q && *q != quote)
            q++;
            quote = 0;
         } else {
@@ -250,8 +263,8 @@ static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_argv)
         p = q;
          while (*p && (*p == ' ' || *p == '\t'))
            p++;
-         if (*p == '\"') {
-           quote = 1;
+         if (*p == '\"' || *p == '\'') {
+           quote = *p;
            p++;
         }
       }