]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/bug_1166_cancel_read.patch
ebl Update patch for #1166 with select() instead of kill
[bacula/bacula] / bacula / patches / testing / bug_1166_cancel_read.patch
1 Index: src/dird/backup.c
2 ===================================================================
3 --- src/dird/backup.c   (rĂ©vision 7736)
4 +++ src/dird/backup.c   (copie de travail)
5 @@ -329,10 +329,10 @@
6  /* Come here only after starting SD thread */
7  bail_out:
8     set_jcr_job_status(jcr, JS_ErrorTerminated);
9 -   Dmsg1(400, "wait for sd. use=%d\n", jcr->use_count());
10 -   /* Cancel SD */
11 -   wait_for_job_termination(jcr, FDConnectTimeout);
12 -   Dmsg1(400, "after wait for sd. use=%d\n", jcr->use_count());
13 +   Dmsg1(400, "wait for sd and fd. use=%d\n", jcr->use_count());
14 +   /* Get status from SD and FD */
15 +   wait_for_job_termination(jcr);   /* TODO: don't expect the EndJob message */
16 +   Dmsg1(400, "after wait for sd and fd. use=%d\n", jcr->use_count());
17     return false;
18  }
19  
20 @@ -343,7 +343,7 @@
21   *   are done, we return the job status.
22   * Also used by restore.c
23   */
24 -int wait_for_job_termination(JCR *jcr, int timeout)
25 +int wait_for_job_termination(JCR *jcr)
26  {
27     int32_t n = 0;
28     BSOCK *fd = jcr->file_bsock;
29 @@ -353,40 +353,43 @@
30     uint64_t JobBytes = 0;
31     int VSS = 0;
32     int Encrypt = 0;
33 -   btimer_t *tid=NULL;
34 -
35     set_jcr_job_status(jcr, JS_Running);
36  
37     if (fd) {
38 -      if (timeout) {
39 -         tid = start_bsock_timer(fd, timeout); /* TODO: New timeout directive??? */
40 -      }
41 -      /* Wait for Client to terminate */
42 -      while ((n = bget_dirmsg(fd)) >= 0) {
43 -         if (!fd_ok && 
44 -             (sscanf(fd->msg, EndJob, &jcr->FDJobStatus, &JobFiles,
45 -                     &ReadBytes, &JobBytes, &Errors, &VSS, &Encrypt) == 7 ||
46 -              sscanf(fd->msg, OldEndJob, &jcr->FDJobStatus, &JobFiles,
47 -                     &ReadBytes, &JobBytes, &Errors) == 5)) {
48 -            fd_ok = true;
49 -            set_jcr_job_status(jcr, jcr->FDJobStatus);
50 -            Dmsg1(100, "FDStatus=%c\n", (char)jcr->JobStatus);
51 -         } else {
52 -            Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"),
53 -                 fd->msg);
54 +      /* Wait for Client to terminate 
55 +       * In some conditions, the client isn't able to send
56 +       * any messages and we should not wait for ages
57 +       */
58 +      int OK=true;
59 +      int ret;
60 +      while (OK) {
61 +         ret = fd->wait_data_intr(5*60, 0); /* wait for data few minutes */
62 +
63 +         if (ret == 1) {       /* get data */
64 +            n = bget_dirmsg(fd);
65 +            if (n >= 0 && !fd_ok && 
66 +                (sscanf(fd->msg, EndJob, &jcr->FDJobStatus, &JobFiles,
67 +                        &ReadBytes, &JobBytes, &Errors, &VSS, &Encrypt) == 7 ||
68 +                 sscanf(fd->msg, OldEndJob, &jcr->FDJobStatus, &JobFiles,
69 +                        &ReadBytes, &JobBytes, &Errors) == 5)) {
70 +               OK=false;        /* end of loop */
71 +               fd_ok = true;
72 +               set_jcr_job_status(jcr, jcr->FDJobStatus);
73 +            } else {
74 +               Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"),
75 +                    fd->msg);
76 +            }
77 +         } /* else get timeout or network error */
78 +
79 +         if (is_bnet_error(fd)) {
80 +            Jmsg(jcr, M_FATAL, 0, _("Network error with FD during %s: ERR=%s\n"),
81 +                 job_type_to_str(jcr->get_JobType()), fd->bstrerror());
82           }
83           if (job_canceled(jcr)) {
84 -            break;
85 +            OK=false;
86           }
87        }
88 -      if (tid) {
89 -         stop_bsock_timer(tid);
90 -      }
91  
92 -      if (is_bnet_error(fd)) {
93 -         Jmsg(jcr, M_FATAL, 0, _("Network error with FD during %s: ERR=%s\n"),
94 -              job_type_to_str(jcr->get_JobType()), fd->bstrerror());
95 -      }
96        fd->signal(BNET_TERMINATE);   /* tell Client we are terminating */
97     }
98  
99 Index: src/dird/protos.h
100 ===================================================================
101 --- src/dird/protos.h   (rĂ©vision 7736)
102 +++ src/dird/protos.h   (copie de travail)
103 @@ -52,7 +52,7 @@
104  extern bool find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr);
105  
106  /* backup.c */
107 -extern int wait_for_job_termination(JCR *jcr, int timeout=0);
108 +extern int wait_for_job_termination(JCR *jcr);
109  extern bool do_backup_init(JCR *jcr);
110  extern bool do_backup(JCR *jcr);
111  extern void backup_cleanup(JCR *jcr, int TermCode);