]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/1.36.0/1.36.0-list.patch
Cleanup patches a bit
[bacula/bacula] / bacula / patches / 1.36.0 / 1.36.0-list.patch
1
2  This patch corrects a Bacula crash after a "list nextvol" followed
3  by "list media". 
4  It can be applied to 1.36.0 with:
5
6  cd <bacula-source>
7  patch -p0 <1.36.0-list.patch
8  make
9  make install
10
11
12 Index: src/dird/ua_output.c
13 ===================================================================
14 RCS file: /cvsroot/bacula/bacula/src/dird/ua_output.c,v
15 retrieving revision 1.47
16 diff -u -r1.47 ua_output.c
17 --- src/dird/ua_output.c        19 Sep 2004 18:56:24 -0000      1.47
18 +++ src/dird/ua_output.c        13 Nov 2004 10:26:08 -0000
19 @@ -42,11 +42,11 @@
20  extern FILE *con_fd;
21  extern brwlock_t con_lock;
22  
23 -
24  /* Imported functions */
25  
26  /* Forward referenced functions */
27  static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist);
28 +static bool list_nextvol(UAContext *ua);
29  
30  /*
31   * Turn auto display of console messages on/off
32 @@ -401,58 +401,7 @@
33        /* List next volume */
34        } else if (strcasecmp(ua->argk[i], _("nextvol")) == 0 || 
35                   strcasecmp(ua->argk[i], _("nextvolume")) == 0) {
36 -        JOB *job;
37 -        JCR *jcr = ua->jcr;
38 -        POOL *pool;
39 -        RUN *run;
40 -        time_t runtime;
41 -        bool found = false;
42 -
43 -         i = find_arg_with_value(ua, "job");
44 -        if (i <= 0) {
45 -           if ((job = select_job_resource(ua)) == NULL) {
46 -              return 1;
47 -           }
48 -        } else {
49 -           job = (JOB *)GetResWithName(R_JOB, ua->argv[i]);
50 -           if (!job) {
51 -               Jmsg(jcr, M_ERROR, 0, _("%s is not a job name.\n"), ua->argv[i]);
52 -              if ((job = select_job_resource(ua)) == NULL) {
53 -                 return 1;
54 -              }
55 -           }
56 -        }
57 -        for (run=NULL; (run = find_next_run(run, job, runtime)); ) {
58 -           pool = run ? run->pool : NULL;
59 -           if (!complete_jcr_for_job(jcr, job, pool)) {
60 -              return 1;
61 -           }
62 -          
63 -           if (!find_next_volume_for_append(jcr, &mr, 0)) {
64 -               bsendmsg(ua, _("Could not find next Volume.\n"));
65 -              if (jcr->db) {
66 -                 db_close_database(jcr, jcr->db);
67 -                 jcr->db = NULL;
68 -              }
69 -              return 1;
70 -           } else {
71 -               bsendmsg(ua, _("The next Volume to be used by Job \"%s\" will be %s\n"), 
72 -                 job->hdr.name, mr.VolumeName);
73 -              found = true;
74 -           }
75 -           if (jcr->db) {
76 -              db_close_database(jcr, jcr->db);
77 -              jcr->db = NULL;
78 -           }
79 -        }
80 -        if (jcr->db) {
81 -           db_close_database(jcr, jcr->db);
82 -           jcr->db = NULL;
83 -        }
84 -        if (!found) {
85 -            bsendmsg(ua, _("Could not find next Volume.\n"));
86 -        }
87 -        return 1;
88 +        list_nextvol(ua);
89        } else {
90           bsendmsg(ua, _("Unknown list keyword: %s\n"), NPRT(ua->argk[i]));
91        }
92 @@ -460,6 +409,57 @@
93     return 1;
94  }
95  
96 +static bool list_nextvol(UAContext *ua)
97 +{
98 +   JOB *job;
99 +   JCR *jcr = ua->jcr;
100 +   POOL *pool;
101 +   RUN *run;
102 +   time_t runtime;
103 +   bool found = false;
104 +   MEDIA_DBR mr;
105 +
106 +   memset(&mr, 0, sizeof(mr));
107 +   int i = find_arg_with_value(ua, "job");
108 +   if (i <= 0) {
109 +      if ((job = select_job_resource(ua)) == NULL) {
110 +        return false;
111 +      }
112 +   } else {
113 +      job = (JOB *)GetResWithName(R_JOB, ua->argv[i]);
114 +      if (!job) {
115 +         Jmsg(jcr, M_ERROR, 0, _("%s is not a job name.\n"), ua->argv[i]);
116 +        if ((job = select_job_resource(ua)) == NULL) {
117 +           return false;
118 +        }
119 +      }
120 +   }
121 +   for (run=NULL; (run = find_next_run(run, job, runtime)); ) {
122 +      pool = run ? run->pool : NULL;
123 +      if (!complete_jcr_for_job(jcr, job, pool)) {
124 +        return false;
125 +      }
126 +     
127 +      if (!find_next_volume_for_append(jcr, &mr, 0)) {
128 +         bsendmsg(ua, _("Could not find next Volume.\n"));
129 +      } else {
130 +         bsendmsg(ua, _("The next Volume to be used by Job \"%s\" will be %s\n"), 
131 +           job->hdr.name, mr.VolumeName);
132 +        found = true;
133 +      }
134 +      if (jcr->db && jcr->db != ua->db) {
135 +        db_close_database(jcr, jcr->db);
136 +        jcr->db = NULL;
137 +      }
138 +   }
139 +   if (!found) {
140 +      bsendmsg(ua, _("Could not find next Volume.\n"));
141 +      return false;
142 +   }
143 +   return true;
144 +}
145 +
146 +
147  /* 
148   * For a given job, we examine all his run records
149   *  to see if it is scheduled today or tomorrow.