]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/job.c
- Add .status [current|last] command to filed and stored
[bacula/bacula] / bacula / src / filed / job.c
index dadea8b1421ae51ca2d3a3f1f019223b0540f8b9..86bdfab4bc818c0b10b265bf8877f414b537a5cb 100644 (file)
@@ -34,7 +34,8 @@ extern CLIENT *me;                  /* our client resource */
                        
 /* Imported functions */
 extern int status_cmd(JCR *jcr);
-                                  
+extern int qstatus_cmd(JCR *jcr);
+
 /* Forward referenced functions */
 static int backup_cmd(JCR *jcr);
 static int bootstrap_cmd(JCR *jcr);
@@ -85,6 +86,7 @@ static struct s_cmds cmds[] = {
    {"restore",      restore_cmd},
    {"session",      session_cmd},
    {"status",       status_cmd},
+   {".status",      qstatus_cmd},
    {"storage ",     storage_cmd},
    {"verify",       verify_cmd},
    {"bootstrap",    bootstrap_cmd},
@@ -226,15 +228,24 @@ void *handle_client_request(void *dirp)
    FF_PKT *ff = (FF_PKT *)jcr->ff;
    findFILESET *fileset = ff->fileset;
    if (fileset) {
-      int i, j;
+      int i, j, k;
       /* Delete FileSet Include lists */
       for (i=0; i<fileset->include_list.size(); i++) {
         findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
         for (j=0; j<incexe->opts_list.size(); j++) {
            findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
+           for (k=0; k<fo->regex.size(); k++) {
+              regfree((regex_t *)fo->regex.get(k));
+           }
            fo->regex.destroy();
            fo->wild.destroy();
            fo->base.destroy();
+           if (fo->reader) {
+              free(fo->reader);
+           }
+           if (fo->writer) {
+              free(fo->writer);
+           }
         }
         incexe->opts_list.destroy();
         incexe->name_list.destroy();
@@ -520,8 +531,9 @@ static void add_fname_to_list(JCR *jcr, char *fname, int list)
    case '<':
       p++;                     /* skip over < */
       if ((ffd = fopen(p, "r")) == NULL) {
+        berrno be;
          Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
-            list==INC_LIST?"included":"excluded", p, strerror(errno));
+            list==INC_LIST?"included":"excluded", p, be.strerror());
         return;
       }
       /* Copy File options */
@@ -651,8 +663,9 @@ static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *filese
    case '<':
       p++;                     /* skip over < */
       if ((ffd = fopen(p, "r")) == NULL) {
+        berrno be;
          Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"),
-           p, strerror(errno));
+           p, be.strerror());
         return;
       }
       while (fgets(buf, sizeof(buf), ffd)) {
@@ -711,7 +724,20 @@ static void add_fileset(JCR *jcr, const char *item)
       break;
    case 'R':
       current_opts = start_options(ff);
-      current_opts->regex.append(bstrdup(item));
+      regex_t *preg;
+      int rc;
+      char prbuf[500];
+      preg = (regex_t *)malloc(sizeof(regex_t));
+      rc = regcomp(preg, item, REG_EXTENDED);
+      if (rc != 0) {
+        regerror(rc, preg, prbuf, sizeof(prbuf));
+        regfree(preg);
+        free(preg);
+         Jmsg(jcr, M_FATAL, 0, "REGEX %s compile error. ERR=%s\n", item, prbuf);
+        state = state_error;
+        break;
+      }
+      current_opts->regex.append(preg);
       state = state_options;
       break;
    case 'B':
@@ -729,6 +755,16 @@ static void add_fileset(JCR *jcr, const char *item)
       set_options(current_opts, item);
       state = state_options;
       break;
+   case 'D':
+      current_opts = start_options(ff);
+      current_opts->reader = bstrdup(item);
+      state = state_options;
+      break;
+   case 'T':
+      current_opts = start_options(ff);
+      current_opts->writer = bstrdup(item);
+      state = state_options;
+      break;
    default:
       Jmsg(jcr, M_FATAL, 0, "Invalid FileSet command: %s\n", item);
       state = state_error;
@@ -757,6 +793,12 @@ static bool term_fileset(JCR *jcr)
         for (k=0; k<fo->base.size(); k++) {
             Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
         }
+        if (fo->reader) {
+            Dmsg1(400, "D %s\n", fo->reader);
+        }
+        if (fo->writer) {
+            Dmsg1(400, "T %s\n", fo->writer);
+        }
       }
       for (j=0; j<incexe->name_list.size(); j++) {
          Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
@@ -910,12 +952,13 @@ static int bootstrap_cmd(JCR *jcr)
       unlink(jcr->RestoreBootstrap);
       free_pool_memory(jcr->RestoreBootstrap);
    }
-   Mmsg(&fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
+   Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
       jcr->Job);
    Dmsg1(400, "bootstrap=%s\n", fname);
    jcr->RestoreBootstrap = fname;
    bs = fopen(fname, "a+");           /* create file */
    if (!bs) {
+      berrno be;
       /* 
        * Suck up what he is sending to us so that he will then
        *   read our error message.
@@ -924,7 +967,7 @@ static int bootstrap_cmd(JCR *jcr)
        {  }
 
       Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"),
-        jcr->RestoreBootstrap, strerror(errno));
+        jcr->RestoreBootstrap, be.strerror());
       free_pool_memory(jcr->RestoreBootstrap);
       jcr->RestoreBootstrap = NULL;
       set_jcr_job_status(jcr, JS_ErrorTerminated);
@@ -1096,7 +1139,6 @@ static int storage_cmd(JCR *jcr)
    /* Try to connect for 1 hour at 10 second intervals */
    sd = bnet_connect(jcr, 10, (int)me->SDConnectTimeout, _("Storage daemon"), 
                     jcr->stored_addr, NULL, stored_port, 1);
-   Dmsg0(110, "Connection OK to SD.\n");
    if (sd == NULL) {
       Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"),
          jcr->stored_addr, stored_port);
@@ -1104,6 +1146,7 @@ static int storage_cmd(JCR *jcr)
          jcr->stored_addr, stored_port);
       return 0;
    }
+   Dmsg0(110, "Connection OK to SD.\n");
 
    jcr->store_bsock = sd;
 
@@ -1532,8 +1575,9 @@ static int send_bootstrap_file(JCR *jcr)
    }
    bs = fopen(jcr->RestoreBootstrap, "r");
    if (!bs) {
+      berrno be;
       Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"), 
-        jcr->RestoreBootstrap, strerror(errno));
+        jcr->RestoreBootstrap, be.strerror());
       set_jcr_job_status(jcr, JS_ErrorTerminated);
       goto bail_out;
    }
@@ -1541,7 +1585,7 @@ static int send_bootstrap_file(JCR *jcr)
    sd->msglen = strlen(sd->msg);
    bnet_send(sd);
    while (fgets(buf, sizeof(buf), bs)) {
-      sd->msglen = Mmsg(&sd->msg, "%s", buf);
+      sd->msglen = Mmsg(sd->msg, "%s", buf);
       bnet_send(sd);      
    }
    bnet_sig(sd, BNET_EOD);