]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/fd_cmds.c
Important protocol change -- see kes29Oct02
[bacula/bacula] / bacula / src / dird / fd_cmds.c
index 08e4f1147b41c5153d780b11b6e86d21700b7fff..8ec2304133d2686e7a7231b0e8456b24d0758150 100644 (file)
@@ -44,7 +44,7 @@ static char jobcmd[]      = "JobId=%d Job=%s SDid=%u SDtime=%u Authorization=%s\
 /* Responses received from File daemon */
 static char OKinc[]      = "2000 OK include\n";
 static char OKexc[]      = "2000 OK exclude\n";
-static char OKjob[]      = "2000 OK Job\n";
+static char OKjob[]      = "2000 OK Job";
 
 /* Forward referenced functions */
 
@@ -85,14 +85,16 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time,
     */
    bnet_fsend(fd, jobcmd, jcr->JobId, jcr->Job, jcr->VolSessionId, 
       jcr->VolSessionTime, jcr->sd_auth_key);
-   Dmsg1(10, ">filed: %s", fd->msg);
+   Dmsg1(110, ">filed: %s", fd->msg);
    if (bnet_recv(fd) > 0) {
-       Dmsg1(10, "<filed: %s", fd->msg);
-       if (strcmp(fd->msg, OKjob) != 0) {
+       Dmsg1(110, "<filed: %s", fd->msg);
+       if (strncmp(fd->msg, OKjob, strlen(OKjob)) != 0) {
           Jmsg(jcr, M_FATAL, 0, _("File daemon rejected Job command: %s\n"), fd->msg);
          jcr->JobStatus = JS_ErrorTerminated;
          return 0;
-       } 
+       } else {
+         /***** ***FIXME***** update Client Uname */
+       }
    } else {
       Jmsg(jcr, M_FATAL, 0, _("<filed: bad response to JobId command: %s\n"),
         bnet_strerror(fd));
@@ -122,15 +124,16 @@ int send_include_list(JCR *jcr)
    bnet_send(fd);
    for (i=0; i < fileset->num_includes; i++) {
       fd->msglen = strlen(fileset->include_array[i]);
-      Dmsg1(20, "dird>filed: include file: %s\n", fileset->include_array[i]);
+      Dmsg1(120, "dird>filed: include file: %s\n", fileset->include_array[i]);
       fd->msg = fileset->include_array[i];
       if (!bnet_send(fd)) {
+        fd->msg = msgsave;
          Emsg0(M_FATAL, 0, _(">filed: write error on socket\n"));
         jcr->JobStatus = JS_ErrorTerminated;
         return 0;
       }
    }
-   bnet_sig(fd, BNET_EOF);
+   bnet_sig(fd, BNET_EOD);           /* end of data */
    fd->msg = msgsave;
    if (!response(fd, OKinc, "Include")) {
       jcr->JobStatus = JS_ErrorTerminated;
@@ -157,7 +160,7 @@ int send_exclude_list(JCR *jcr)
    bnet_send(fd);
    for (i=0; i < fileset->num_excludes; i++) {
       fd->msglen = strlen(fileset->exclude_array[i]);
-      Dmsg1(20, "dird>filed: exclude file: %s\n", fileset->exclude_array[i]);
+      Dmsg1(120, "dird>filed: exclude file: %s\n", fileset->exclude_array[i]);
       fd->msg = fileset->exclude_array[i];
       if (!bnet_send(fd)) {
          Emsg0(M_FATAL, 0, _(">filed: write error on socket\n"));
@@ -165,7 +168,7 @@ int send_exclude_list(JCR *jcr)
         return 0;
       }
    }
-   bnet_sig(fd, BNET_EOF);
+   bnet_sig(fd, BNET_EOD);
    fd->msg = msgsave;
    if (!response(fd, OKexc, "Exclude")) {
       jcr->JobStatus = JS_ErrorTerminated;
@@ -182,14 +185,15 @@ int send_exclude_list(JCR *jcr)
 int get_attributes_and_put_in_catalog(JCR *jcr)
 {
    BSOCK   *fd;
-   int n;
+   int n = 0;
    ATTR_DBR ar;
 
    fd = jcr->file_bsock;
    jcr->jr.FirstIndex = 1;
    memset(&ar, 0, sizeof(ar));
+   jcr->FileIndex = 0;
 
-   Dmsg0(20, "bdird: waiting to receive file attributes\n");
+   Dmsg0(120, "bdird: waiting to receive file attributes\n");
    /* Pickup file attributes and signature */
    while (!fd->errors && (n = bget_msg(fd, 0)) > 0) {
 
@@ -224,11 +228,12 @@ msglen=%d msg=%s\n"), len, fd->msglen, fd->msg);
       *fn = *p++;                    /* term filename and point to attribs */
       attr = p;
 
-      if (stream == STREAM_UNIX_ATTRIBUTES) {
+      if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_WIN32_ATTRIBUTES) {
         jcr->JobFiles++;
+        jcr->FileIndex = file_index;
         ar.attr = attr;
         ar.fname = jcr->fname;
-        ar.FileIndex = 0;           /* used as mark field during compare */
+        ar.FileIndex = file_index;
         ar.Stream = stream;
         ar.link = NULL;
         ar.JobId = jcr->JobId;
@@ -236,8 +241,8 @@ msglen=%d msg=%s\n"), len, fd->msglen, fd->msg);
         ar.PathId = 0;
         ar.FilenameId = 0;
 
-         Dmsg2(11, "dird<filed: stream=%d %s\n", stream, jcr->fname);
-         Dmsg1(20, "dird<filed: attr=%s\n", attr);
+         Dmsg2(111, "dird<filed: stream=%d %s\n", stream, jcr->fname);
+         Dmsg1(120, "dird<filed: attr=%s\n", attr);
 
         /* ***FIXME*** fix link field */
         if (!db_create_file_attributes_record(jcr->db, &ar)) {
@@ -245,16 +250,16 @@ msglen=%d msg=%s\n"), len, fd->msglen, fd->msg);
            jcr->JobStatus = JS_Error;
            continue;
         }
-        jcr->FileIndex = file_index;
         jcr->FileId = ar.FileId;
       } else if (stream == STREAM_MD5_SIGNATURE) {
         if (jcr->FileIndex != (uint32_t)file_index) {
-            Jmsg0(jcr, M_ERROR, 0, _("Got MD5 but not same block as attributes\n"));
+            Jmsg2(jcr, M_ERROR, 0, _("MD5 index %d not same as attributes %d\n"),
+              file_index, jcr->FileIndex);
            jcr->JobStatus = JS_Error;
            continue;
         }
         db_escape_string(MD5, Opts_MD5, strlen(Opts_MD5));
-         Dmsg2(20, "MD5len=%d MD5=%s\n", strlen(MD5), MD5);
+         Dmsg2(120, "MD5len=%d MD5=%s\n", strlen(MD5), MD5);
         if (!db_add_MD5_to_file_record(jcr->db, jcr->FileId, MD5)) {
             Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
            jcr->JobStatus = JS_Error;
@@ -263,7 +268,7 @@ msglen=%d msg=%s\n"), len, fd->msglen, fd->msg);
       jcr->jr.JobFiles = jcr->JobFiles = file_index;
       jcr->jr.LastIndex = file_index;
    } 
-   if (n < 0) {
+   if (is_bnet_error(fd)) {
       Jmsg1(jcr, M_FATAL, 0, _("<filed: Network error getting attributes. ERR=%s\n"),
                        bnet_strerror(fd));
       jcr->JobStatus = JS_ErrorTerminated;