]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/job.c
More cleanup
[bacula/bacula] / bacula / src / filed / job.c
index 4be69bdbb5dab19693533eeb043d3da857adbfd0..1efc8b930e5fe82fab565a63a1b4fb247bc03dce 100644 (file)
@@ -91,6 +91,7 @@ static char jobcmd[]     = "JobId=%d Job=%127s SDid=%d SDtime=%d Authorization=%
 static char storaddr[]   = "storage address=%s port=%d\n";
 static char sessioncmd[] = "session %s %ld %ld %ld %ld %ld %ld\n";
 static char restorecmd[] = "restore replace=%c where=%s\n";
+static char restorecmd1[] = "restore replace=%c where=\n";
 static char verifycmd[]  = "verify level=%20s\n";
 
 /* Responses sent to Director */
@@ -158,8 +159,9 @@ void *handle_client_request(void *dirp)
    jcr->ff = init_find_files();
    jcr->start_time = time(NULL);
    jcr->last_fname = get_pool_memory(PM_FNAME);
+   jcr->last_fname[0] = 0;
    jcr->client_name = get_memory(strlen(my_name) + 1);
-   strcpy(jcr->client_name, my_name);
+   pm_strcpy(&jcr->client_name, my_name);
    dir->jcr = (void *)jcr;
 
    /**********FIXME******* add command handler error code */
@@ -194,7 +196,7 @@ void *handle_client_request(void *dirp)
       }
    }
    Dmsg0(100, "Calling term_find_files\n");
-   term_find_files(jcr->ff);
+   term_find_files((FF_PKT *)jcr->ff);
    Dmsg0(100, "Done with term_find_files\n");
    free_jcr(jcr);                    /* destroy JCR record */
    Dmsg0(100, "Done with free_jcr\n");
@@ -229,7 +231,7 @@ static int cancel_cmd(JCR *jcr)
       if (!(cjcr=get_jcr_by_full_name(Job))) {
          bnet_fsend(dir, "2901 Job %s not found.\n", Job);
       } else {
-        cjcr->JobStatus = JS_Cancelled;
+        set_jcr_job_status(cjcr, JS_Cancelled);
         free_jcr(cjcr);
          bnet_fsend(dir, "2001 Job %s marked to be cancelled.\n", Job);
       }
@@ -302,8 +304,8 @@ static int include_cmd(JCR *jcr)
    while (bnet_recv(dir) >= 0) {
        dir->msg[dir->msglen] = 0;
        strip_trailing_junk(dir->msg);
-       Dmsg1(110, "filed<dird: include file %s\n", dir->msg);
-       add_fname_to_include_list(jcr->ff, 1, dir->msg);
+       Dmsg1(010, "include file: %s\n", dir->msg);
+       add_fname_to_include_list((FF_PKT *)jcr->ff, 1, dir->msg);
    }
 
    return bnet_fsend(dir, OKinc);
@@ -327,7 +329,7 @@ static int exclude_cmd(JCR *jcr)
        /* Skip spaces */
        for ( ; *p && *p == ' '; p++)
          { }
-       add_fname_to_exclude_list(jcr->ff, p);
+       add_fname_to_exclude_list((FF_PKT *)jcr->ff, p);
        Dmsg1(110, "<dird: exclude file %s\n", dir->msg);
    }
 
@@ -355,6 +357,7 @@ static int bootstrap_cmd(JCR *jcr)
         jcr->RestoreBootstrap, strerror(errno));
       free_pool_memory(jcr->RestoreBootstrap);
       jcr->RestoreBootstrap = NULL;
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       return 0;
    }
 
@@ -490,13 +493,13 @@ static int backup_cmd(JCR *jcr)
    int ok = 0;
    int SDJobStatus;
 
-   jcr->JobStatus = JS_Blocked;
+   set_jcr_job_status(jcr, JS_Blocked);
    jcr->JobType = JT_BACKUP;
-   Dmsg1(100, "begin backup ff=%p\n", jcr->ff);
+   Dmsg1(100, "begin backup ff=%p\n", (FF_PKT *)jcr->ff);
 
    if (sd == NULL) {
       Jmsg(jcr, M_FATAL, 0, _("Cannot contact Storage daemon\n"));
-      jcr->JobStatus = JS_ErrorTerminated;
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       goto cleanup;
    }
 
@@ -515,13 +518,13 @@ static int backup_cmd(JCR *jcr)
       Dmsg1(110, "<stored: %s", sd->msg);
       if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
          Jmsg(jcr, M_FATAL, 0, _("Bad response to append open: %s\n"), sd->msg);
-        jcr->JobStatus = JS_ErrorTerminated;
+        set_jcr_job_status(jcr, JS_ErrorTerminated);
         goto cleanup;
       }
       Dmsg1(110, "Got Ticket=%d\n", jcr->Ticket);
    } else {
       Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to open command\n"));
-      jcr->JobStatus = JS_ErrorTerminated;
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       goto cleanup;
    }
 
@@ -536,23 +539,28 @@ static int backup_cmd(JCR *jcr)
     */
    Dmsg1(110, "<stored: %s", sd->msg);
    if (!response(jcr, sd, OK_data, "Append Data")) {
-      jcr->JobStatus = JS_ErrorTerminated;
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       goto cleanup;
    }
       
    /*
     * Send Files to Storage daemon
     */
-   Dmsg1(110, "begin blast ff=%p\n", jcr->ff);
+   Dmsg1(110, "begin blast ff=%p\n", (FF_PKT *)jcr->ff);
    if (!blast_data_to_storage_daemon(jcr, NULL)) {
-      jcr->JobStatus = JS_ErrorTerminated;
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
+      bnet_suppress_error_messages(sd, 1);
    } else {
-      jcr->JobStatus = JS_Terminated;
+      set_jcr_job_status(jcr, JS_Terminated);
+      if (jcr->JobStatus != JS_Terminated) {
+        bnet_suppress_error_messages(sd, 1);
+        goto cleanup;                /* bail out now */
+      }
       /* 
        * Expect to get response to append_data from Storage daemon
        */
       if (!response(jcr, sd, OK_append, "Append Data")) {
-        jcr->JobStatus = JS_ErrorTerminated;
+        set_jcr_job_status(jcr, JS_ErrorTerminated);
         goto cleanup;
       }
      
@@ -562,7 +570,7 @@ static int backup_cmd(JCR *jcr)
       bnet_fsend(sd, append_end, jcr->Ticket);
       /* Get end OK */
       if (!response(jcr, sd, OK_end, "Append End")) {
-        jcr->JobStatus = JS_ErrorTerminated;
+        set_jcr_job_status(jcr, JS_ErrorTerminated);
         goto cleanup;
       }
 
@@ -578,13 +586,13 @@ static int backup_cmd(JCR *jcr)
       }
       if (!ok) {
          Jmsg(jcr, M_FATAL, 0, _("Append Close with SD failed.\n"));
-        jcr->JobStatus = JS_ErrorTerminated;
+        set_jcr_job_status(jcr, JS_ErrorTerminated);
         goto cleanup;
       }
       if (SDJobStatus != JS_Terminated) {
          Jmsg(jcr, M_FATAL, 0, _("Bad status %d returned from Storage Daemon.\n"),
            SDJobStatus);
-        jcr->JobStatus = JS_ErrorTerminated;
+        set_jcr_job_status(jcr, JS_ErrorTerminated);
       }
    }
 
@@ -686,8 +694,15 @@ static int restore_cmd(JCR *jcr)
    *where = 0;
 
    if (sscanf(dir->msg, restorecmd, &replace, where) != 2) {
-      Jmsg(jcr, M_FATAL, 0, _("Bad replace command.\n"));
-      return 0;
+      if (sscanf(dir->msg, restorecmd1, &replace) != 1) {
+         Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), dir->msg);
+        return 0;
+      }
+      *where = 0;
+   }
+   /* Turn / into nothing */
+   if (where[0] == '/' && where[1] == 0) {
+      where[0] = 0;
    }
       
    Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
@@ -699,36 +714,46 @@ static int restore_cmd(JCR *jcr)
    Dmsg1(110, "bfiled>dird: %s", dir->msg);
 
    jcr->JobType = JT_RESTORE;
-   jcr->JobStatus = JS_Blocked;
 
+   set_jcr_job_status(jcr, JS_Blocked);
    if (!open_sd_read_session(jcr)) {
-      return 0;
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
+      goto bail_out;
    }
 
+   set_jcr_job_status(jcr, JS_Running);
+
    /* 
     * Do restore of files and data
     */
    do_restore(jcr);
 
+   set_jcr_job_status(jcr, JS_Terminated);
+   if (jcr->JobStatus != JS_Terminated) {
+      bnet_suppress_error_messages(sd, 1);
+   }
+
    /* 
     * Send Close session command to Storage daemon
     */
    bnet_fsend(sd, read_close, jcr->Ticket);
    Dmsg1(130, "bfiled>stored: %s", sd->msg);
 
-   /* ****FIXME**** check response */
    bnet_recv(sd);                    /* get OK */
 
    /* Inform Storage daemon that we are done */
    bnet_sig(sd, BNET_TERMINATE);
 
-   bnet_fsend(dir, EndRestore, jcr->JobStatus, jcr->num_files_examined, jcr->JobBytes);
+bail_out:
+   /* Send termination status back to Dir */
+   bnet_fsend(dir, EndRestore, jcr->JobStatus, jcr->num_files_examined, 
+             jcr->JobBytes);
 
    /* Inform Director that we are done */
    bnet_sig(dir, BNET_TERMINATE);
 
    Dmsg0(130, "Done in job.c\n");
-   return 1;
+   return !job_cancelled(jcr);
 }
 
 static int open_sd_read_session(JCR *jcr)
@@ -851,7 +876,7 @@ static int send_bootstrap_file(JCR *jcr)
    if (!bs) {
       Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"), 
         jcr->RestoreBootstrap, strerror(errno));
-      jcr->JobStatus = JS_ErrorTerminated;
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       return 0;
    }
    strcpy(sd->msg, bootstrap); 
@@ -864,7 +889,7 @@ static int send_bootstrap_file(JCR *jcr)
    bnet_sig(sd, BNET_EOD);
    fclose(bs);
    if (!response(jcr, sd, OKSDbootstrap, "Bootstrap")) {
-      jcr->JobStatus = JS_ErrorTerminated;
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       return 0;
    }
    return 1;