]> git.sur5r.net Git - bacula/bacula/commitdiff
Use bpipe for shell expansion
authorKern Sibbald <kern@sibbald.com>
Fri, 8 Aug 2003 14:45:18 +0000 (14:45 +0000)
committerKern Sibbald <kern@sibbald.com>
Fri, 8 Aug 2003 14:45:18 +0000 (14:45 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@664 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/ua_status.c
bacula/src/lib/util.c
bacula/src/version.h

index 32472f5bd946703dc3ec522854feb1f98b51b900..77a2fa55be1e0911eef1a8d3ba826a5fcc15b87c 100644 (file)
@@ -261,7 +261,7 @@ static void do_director_status(UAContext *ua, char *cmd)
             msg = _("is waiting on max Job jobs");
            break;
         case JS_WaitPriority:
-            msg = _("is waiting on for higher priority jobs to finish");
+            msg = _("is waiting for higher priority jobs to finish");
            break;
         case JS_WaitMaxJobs:
             msg = _("is waiting on max total jobs");
index 0ef5a59c29f8f552ebf47d0005448416694a388d..0692003c97b1cc0b5c7bba675479855607c2f7ec 100644 (file)
@@ -300,113 +300,45 @@ char *encode_mode(mode_t mode, char *buf)
 
 int do_shell_expansion(char *name, int name_len)
 {
-/*  ****FIXME***** this should work for Win32 too */
-#define UNIX
-#ifdef UNIX
-#ifndef PATH_MAX
-#define PATH_MAX 512
-#endif
-
-   int pid, wpid, stat;
-   int waitstatus;
-   char *shellcmd;
-   int i;
-   char echout[PATH_MAX + 256];
-   int pfd[2];
    static char meta[] = "~\\$[]*?`'<>\"";
-   int found = FALSE;
-   int len;
+   bool found = false;
+   int len, i, stat;
+   POOLMEM *cmd;
+   BPIPE *bpipe;
+   char line[MAXSTRING];
+   char *shellcmd;
 
    /* Check if any meta characters are present */
    len = strlen(meta);
    for (i = 0; i < len; i++) {
       if (strchr(name, meta[i])) {
-        found = TRUE;
+        found = true;
         break;
       }
    }
-   stat = 0;
    if (found) {
-#ifdef nt
-       /* If the filename appears to be a DOS filename,
-          convert all backward slashes \ to Unix path
-          separators / and insert a \ infront of spaces. */
-       len = strlen(name);
-       if (len >= 3 && name[1] == ':' && name[2] == '\\') {
-         for (i=2; i<len; i++)
-             if (name[i] == '\\')
-                name[i] = '/';
-       }
-#else
-       /* Pass string off to the shell for interpretation */
-       if (pipe(pfd) == -1)
-         return 0;
-       switch(pid = fork()) {
-       case -1:
-         break;
-
-       case 0:                           /* child */
-         /* look for shell */
-          if ((shellcmd = getenv("SHELL")) == NULL) {
-             shellcmd = "/bin/sh";
-         }
-         close(pfd[0]);                  /* close stdin */
-         dup2(pfd[1], 1);                /* attach to stdout */
-         dup2(pfd[1], 2);                /* and stderr */
-          strcpy(echout, "echo ");        /* form echo command */
-         bstrncat(echout, name, sizeof(echout));
-          execl(shellcmd, shellcmd, "-c", echout, NULL); /* give to shell */
-          exit(127);                      /* shouldn't get here */
-
-       default:                          /* parent */
-         /* read output from child */
-         echout[0] = 0;
-         do {
-            i = read(pfd[0], echout, sizeof echout);
-         } while (i == -1 && errno == EINTR); 
-
-         if (i > 0) {
-            echout[--i] = 0;                /* set end of string */
-            /* look for first line. */
-            while (--i >= 0) {
-                if (echout[i] == '\n') {
-                  echout[i] = 0;            /* keep only first one */
-               }
-            }
-         }
-         /* wait for child to exit */
-         while ((wpid = wait(&waitstatus)) != pid && wpid != -1)
-            { ; }
-         strip_trailing_junk(echout);
-         if (strlen(echout) > 0) {
-            bstrncpy(name, echout, name_len);
-         }
-         stat = 1;
-         break;
-       }
-       close(pfd[0]);                    /* close pipe */
-       close(pfd[1]);
-#endif /* nt */
-   }
-   return stat;
-
-#endif /* UNIX */
-
-#if  MSC | MSDOS | __WATCOMC__
-
-   char prefix[100], *env, *getenv();
-
-   /* Home directory reference? */
-   if (*name == '~' && (env=getenv("HOME"))) {
-      strcpy(prefix, env);           /* copy HOME directory name */
-      name++;                        /* skip over ~ in name */
-      strcat(prefix, name);
-      name--;                        /* get back to beginning */
-      strcpy(name, prefix);          /* move back into name */
+      cmd =  get_pool_memory(PM_FNAME);
+      /* look for shell */
+      if ((shellcmd = getenv("SHELL")) == NULL) {
+         shellcmd = "/bin/sh";
+      }
+      pm_strcpy(&cmd, shellcmd);
+      pm_strcat(&cmd, " -c \"echo ");
+      pm_strcat(&cmd, name);
+      pm_strcat(&cmd, "\"");
+      Dmsg1(400, "Send: %s\n", cmd);
+      bpipe = open_bpipe(cmd, 0, "r");
+      *line = 0;
+      fgets(line, sizeof(line), bpipe->rfd);
+      strip_trailing_junk(line);
+      stat = close_bpipe(bpipe);
+      Dmsg2(400, "stat=%d got: %s\n", stat, line);
+      free_pool_memory(cmd);
+      if (stat == 0) {
+        bstrncpy(name, line, name_len);
+      }
    }
    return 1;
-#endif
-
 }
 
 
index e1efc7f45b2b823179c65fab4ec79fea2ef26bc5..d7fe9dad08ea5c59fd8179ad5bb3a31ff1ae0946 100644 (file)
@@ -1,8 +1,8 @@
 /* */
-#define VERSION "1.31b"
+#define VERSION "1.32"
 #define VSTRING "1"
-#define BDATE   "03 Aug 2003"
-#define LSMDATE "03Aug03"
+#define BDATE   "08 Aug 2003"
+#define LSMDATE "08Aug03"
 
 /* Debug flags */
 #define DEBUG 1