]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/fd_cmds.c
Update doc, default working directory bscan
[bacula/bacula] / bacula / src / stored / fd_cmds.c
index 5424b89a6f7bf62814ae899581b117a0e1d58152..226355beb4982ef091c44f7ed4d8f851d217a91d 100644 (file)
@@ -83,7 +83,7 @@ static char read_open[]       = "read open session = %s %ld %ld %ld %ld %ld %ld\
 static char NO_open[]         = "3901 Error session already open\n";
 static char NOT_opened[]      = "3902 Error session not opened\n";
 static char OK_end[]          = "3000 OK end\n";
-static char OK_close[]        = "3000 OK close Volumes = %d\n";
+static char OK_close[]        = "3000 OK close Status = %d\n";
 static char OK_open[]         = "3000 OK open ticket = %d\n";
 static char OK_append[]       = "3000 OK append data\n";
 static char ERROR_append[]    = "3903 Error append data\n";
@@ -111,19 +111,26 @@ void run_job(JCR *jcr)
    char ec1[30];
 
 
-   Dmsg1(20, "Start run Job=%s\n", jcr->Job);
+   fd->jcr = (void *)jcr;
+   dir->jcr = (void *)jcr;
+   Dmsg1(120, "Start run Job=%s\n", jcr->Job);
    bnet_fsend(dir, Job_start, jcr->Job); 
-   time(&jcr->start_time);
+   jcr->start_time = time(NULL);
    jcr->run_time = jcr->start_time;
    jcr->JobStatus = JS_Running;
    dir_send_job_status(jcr);         /* update director */
    for (quit=0; !quit;) {
+      int stat;
 
       /* Read command coming from the File daemon */
-      if (bnet_recv(fd) <= 0) {
+      stat = bnet_recv(fd);
+      if (is_bnet_stop(fd)) {        /* hardeof or error */
         break;                       /* connection terminated */
       }
-      Dmsg1(10, "<filed: %s", fd->msg);
+      if (stat <= 0) {
+        continue;                    /* ignore signals and zero length msgs */
+      }
+      Dmsg1(110, "<filed: %s", fd->msg);
       found = 0;
       for (i=0; fd_cmds[i].cmd; i++) {
         if (strncmp(fd_cmds[i].cmd, fd->msg, strlen(fd_cmds[i].cmd)) == 0) {
@@ -136,12 +143,13 @@ void run_job(JCR *jcr)
         }
       }
       if (!found) {                  /* command not found */
-         Dmsg1(10, "<filed: Command not found: %s\n", fd->msg);
+         Dmsg1(110, "<filed: Command not found: %s\n", fd->msg);
         bnet_fsend(fd, ferrmsg);
         break;
       }
    }
-   time(&jcr->end_time);
+   bnet_sig(fd, BNET_TERMINATE);      /* signal to FD job is done */
+   jcr->end_time = time(NULL);
    if (!job_cancelled(jcr)) {
       jcr->JobStatus = JS_Terminated;
    }
@@ -162,9 +170,9 @@ static int append_data_cmd(JCR *jcr)
 {
    BSOCK *fd = jcr->file_bsock;
 
-   Dmsg1(20, "Append data: %s", fd->msg);
+   Dmsg1(120, "Append data: %s", fd->msg);
    if (jcr->session_opened) {
-      Dmsg1(10, "<bfiled: %s", fd->msg);
+      Dmsg1(110, "<bfiled: %s", fd->msg);
       if (do_append_data(jcr)) {
         bnet_fsend(fd, OK_append);
         jcr->JobType = JT_BACKUP;
@@ -183,7 +191,7 @@ static int append_end_session(JCR *jcr)
 {
    BSOCK *fd = jcr->file_bsock;
 
-   Dmsg1(20, "store<file: %s", fd->msg);
+   Dmsg1(120, "store<file: %s", fd->msg);
    if (!jcr->session_opened) {
       bnet_fsend(fd, NOT_opened);
       return 0;
@@ -200,18 +208,18 @@ static int append_open_session(JCR *jcr)
 {
    BSOCK *fd = jcr->file_bsock;
 
-   Dmsg1(20, "Append open session: %s", fd->msg);
+   Dmsg1(120, "Append open session: %s", fd->msg);
    if (jcr->session_opened) {
       bnet_fsend(fd, NO_open);
       return 0;
    }
 
-   Dmsg1(10, "Append open session: %s\n", dev_name(jcr->device->dev));
+   Dmsg1(110, "Append open session: %s\n", dev_name(jcr->device->dev));
    jcr->session_opened = TRUE;
 
    /* Send "Ticket" to File Daemon */
    bnet_fsend(fd, OK_open, jcr->VolSessionId);
-   Dmsg1(10, ">filed: %s", fd->msg);
+   Dmsg1(110, ">filed: %s", fd->msg);
 
    return 1;
 }
@@ -225,22 +233,22 @@ static int append_close_session(JCR *jcr)
 {
    BSOCK *fd = jcr->file_bsock;
 
-   Dmsg1(20, "<filed: %s\n", fd->msg);
+   Dmsg1(120, "<filed: %s\n", fd->msg);
    if (!jcr->session_opened) {
       bnet_fsend(fd, NOT_opened);
       return 0;
    }
+   if (jcr->JobStatus != JS_ErrorTerminated) {
+      jcr->JobStatus = JS_Terminated;
+   }
    /* Send final statistics to File daemon */
-   bnet_fsend(fd, OK_close, jcr->NumVolumes);
-   Dmsg1(60, ">filed: %s\n", fd->msg);
+   bnet_fsend(fd, OK_close, jcr->JobStatus);
+   Dmsg1(160, ">filed: %s\n", fd->msg);
 
    bnet_sig(fd, BNET_EOD);           /* send EOD to File daemon */
        
-   Dmsg1(10, "Append close session: %s\n", dev_name(jcr->device->dev));
+   Dmsg1(110, "Append close session: %s\n", dev_name(jcr->device->dev));
 
-   if (jcr->JobStatus != JS_ErrorTerminated) {
-      jcr->JobStatus = JS_Terminated;
-   }
    jcr->session_opened = FALSE;
    return 1;
 }
@@ -255,9 +263,9 @@ static int read_data_cmd(JCR *jcr)
 {
    BSOCK *fd = jcr->file_bsock;
 
-   Dmsg1(20, "Read data: %s\n", fd->msg);
+   Dmsg1(120, "Read data: %s\n", fd->msg);
    if (jcr->session_opened) {
-      Dmsg1(20, "<bfiled: %s", fd->msg);
+      Dmsg1(120, "<bfiled: %s", fd->msg);
       return do_read_data(jcr);
    } else {
       bnet_fsend(fd, NOT_opened);
@@ -275,7 +283,7 @@ static int read_open_session(JCR *jcr)
 {
    BSOCK *fd = jcr->file_bsock;
 
-   Dmsg1(20, "%s\n", fd->msg);
+   Dmsg1(120, "%s\n", fd->msg);
    if (jcr->session_opened) {
       bnet_fsend(fd, NO_open);
       return 0;
@@ -296,14 +304,14 @@ static int read_open_session(JCR *jcr)
         jcr->read_EndBlock);
    }
 
-   Dmsg1(10, "Read open session: %s\n", dev_name(jcr->device->dev));
+   Dmsg1(110, "Read open session: %s\n", dev_name(jcr->device->dev));
 
    jcr->session_opened = TRUE;
    jcr->JobType = JT_RESTORE;
 
    /* Send "Ticket" to File Daemon */
    bnet_fsend(fd, OK_open, jcr->VolSessionId);
-   Dmsg1(10, ">filed: %s", fd->msg);
+   Dmsg1(110, ">filed: %s", fd->msg);
 
    return 1;
 }
@@ -328,8 +336,8 @@ static int bootstrap_cmd(JCR *jcr)
         jcr->RestoreBootstrap, strerror(errno));
       goto bail_out;
    }
-   while (bnet_recv(fd) > 0) {
-       Dmsg1(000, "stored<filed: bootstrap file %s\n", fd->msg);
+   while (bnet_recv(fd) >= 0) {
+       Dmsg1(400, "stored<filed: bootstrap file %s\n", fd->msg);
        fputs(fd->msg, bs);
    }
    fclose(bs);
@@ -361,14 +369,14 @@ static int read_close_session(JCR *jcr)
 {
    BSOCK *fd = jcr->file_bsock;
 
-   Dmsg1(20, "Read close session: %s\n", fd->msg);
+   Dmsg1(120, "Read close session: %s\n", fd->msg);
    if (!jcr->session_opened) {
       bnet_fsend(fd, NOT_opened);
       return 0;
    }
    /* Send final statistics to File daemon */
    bnet_fsend(fd, OK_close);
-   Dmsg1(60, ">filed: %s\n", fd->msg);
+   Dmsg1(160, ">filed: %s\n", fd->msg);
 
    bnet_sig(fd, BNET_EOD);         /* send EOD to File daemon */