]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/1.36.1-store.patch
Apply Preben 'Peppe' Guldberg <peppe@wielders.org>
[bacula/bacula] / bacula / patches / 1.36.1-store.patch
1  This patch fixes a problem with overriding storage daemon
2  specifications. Previously they were not always honored.
3  This implements more uniform handling. It also eliminates
4  an orphaned buffer situation using JobDefs.
5  Apply to version 1.36.1 with:
6
7  cd <bacula-source>
8  patch -p0 <1.36.1-store.patch
9  make
10  make install
11  ...
12
13 Index: src/dird/job.c
14 ===================================================================
15 RCS file: /cvsroot/bacula/bacula/src/dird/job.c,v
16 retrieving revision 1.92
17 diff -u -r1.92 job.c
18 --- src/dird/job.c      21 Nov 2004 13:10:15 -0000      1.92
19 +++ src/dird/job.c      21 Dec 2004 13:04:08 -0000
20 @@ -4,10 +4,10 @@
21   *
22   *     Kern Sibbald, October MM
23   *
24 - *    Version $Id$
25 + *    Version $Id$
26   */
27  /*
28 -   Copyright (C) 2000-2004 Kern Sibbald and John Walker
29 +   Copyright (C) 2000-2004 Kern Sibbald
30  
31     This program is free software; you can redistribute it and/or
32     modify it under the terms of the GNU General Public License as
33 @@ -344,7 +344,7 @@
34          if (!ua->jcr->storage[0]) {
35             copy_storage(ua->jcr, jcr);
36          } else {
37 -           ua->jcr->store = jcr->store;
38 +           set_storage(ua->jcr, jcr->store);
39          }
40          if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
41              bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
42 @@ -724,6 +724,12 @@
43     if (jcr->term_wait_inited) {
44        pthread_cond_destroy(&jcr->term_wait);
45     }
46 +   /* Delete lists setup to hold storage pointers */
47 +   for (int i=0; i<MAX_STORE; i++) {
48 +      if (jcr->storage[i]) {
49 +        delete jcr->storage[i];
50 +      }
51 +   }
52     jcr->job_end_push.destroy();
53     Dmsg0(200, "End dird free_jcr\n");
54  }
55 @@ -749,10 +755,17 @@
56        break;
57     }
58     jcr->JobPriority = job->Priority;
59 +   /* Copy storage definitions -- deleted in dir_free_jcr above */
60     for (int i=0; i<MAX_STORE; i++) {
61 -      jcr->storage[i] = job->storage[i];
62 +      STORE *st;
63 +      if (job->storage[i]) {
64 +        jcr->storage[i] = New(alist(10, not_owned_by_alist));
65 +        foreach_alist(st, job->storage[i]) {
66 +           jcr->storage[i]->append(st);
67 +        }
68 +      }
69     }
70 -   if (!jcr->store && jcr->storage[0]) {
71 +   if (jcr->storage[0]) {
72        jcr->store = (STORE *)jcr->storage[0]->first();
73     }
74     jcr->client = job->client;
75 @@ -805,6 +818,9 @@
76     for (int i=0; i < MAX_STORE; i++) {
77        if (old_jcr->storage[i]) {
78          STORE *st;
79 +        if (old_jcr->storage[i]) {
80 +           delete old_jcr->storage[i];
81 +        }
82          new_jcr->storage[i] = New(alist(10, not_owned_by_alist));
83          foreach_alist(st, old_jcr->storage[i]) {
84             new_jcr->storage[i]->append(st);
85 @@ -817,3 +833,10 @@
86        }
87     }
88  }
89 +
90 +/* Set storage override */
91 +void set_storage(JCR *jcr, STORE *store)
92 +{
93 +   jcr->store = store;
94 +   jcr->storage[0]->prepend(store);
95 +}
96 Index: src/dird/msgchan.c
97 ===================================================================
98 RCS file: /cvsroot/bacula/bacula/src/dird/msgchan.c,v
99 retrieving revision 1.32
100 diff -u -r1.32 msgchan.c
101 --- src/dird/msgchan.c  29 Sep 2004 19:58:17 -0000      1.32
102 +++ src/dird/msgchan.c  21 Dec 2004 13:04:08 -0000
103 @@ -13,10 +13,10 @@
104   *    Create a thread to interact with the Storage daemon
105   *     who returns a job status and requests Catalog services, etc.
106   *
107 - *   Version $Id$
108 + *   Version $Id$
109   */
110  /*
111 -   Copyright (C) 2000-2004 Kern Sibbald and John Walker
112 +   Copyright (C) 2000-2004 Kern Sibbald
113  
114     This program is free software; you can redistribute it and/or
115     modify it under the terms of the GNU General Public License as
116 @@ -64,10 +64,9 @@
117                               int max_retry_time, int verbose)
118  {
119     BSOCK *sd;
120 -   STORE *store = jcr->store;
121 -   if (!store) {
122 -      jcr->store = store = (STORE *)jcr->storage[0]->first();
123 -   }
124 +   STORE *store;
125 +
126 +   store = (STORE *)jcr->storage[0]->first();
127  
128     /*
129      *  Open message channel with the Storage daemon   
130 @@ -94,13 +93,13 @@
131   */
132  int start_storage_daemon_job(JCR *jcr)
133  {
134 -   int status;
135 +   int status = 0;
136     STORE *storage;
137     BSOCK *sd;
138     char auth_key[100];
139     POOL_MEM device_name, pool_name, pool_type, media_type;
140 +   int i;
141  
142 -   storage = jcr->store;
143     sd = jcr->store_bsock;
144     /*
145      * Now send JobId and permissions, and get back the authorization key.
146 @@ -139,23 +138,29 @@
147     /*
148      * Send use device = xxx media = yyy pool = zzz
149      */
150 -   pm_strcpy(device_name, storage->dev_name);
151 -   pm_strcpy(media_type, storage->media_type);
152 -   pm_strcpy(pool_type, jcr->pool->pool_type);
153 -   pm_strcpy(pool_name, jcr->pool->hdr.name);
154 -   bash_spaces(device_name);
155 -   bash_spaces(media_type);
156 -   bash_spaces(pool_type);
157 -   bash_spaces(pool_name);
158 -   bnet_fsend(sd, use_device, device_name.c_str(), 
159 -             media_type.c_str(), pool_name.c_str(), pool_type.c_str());
160 -   Dmsg1(110, ">stored: %s", sd->msg);
161 -   status = response(jcr, sd, OK_device, "Use Device", NO_DISPLAY);
162 -   if (!status) {
163 -      pm_strcpy(pool_type, sd->msg); /* save message */
164 -      Jmsg(jcr, M_FATAL, 0, _("\n"
165 -         "     Storage daemon didn't accept Device \"%s\" because:\n     %s"),
166 -        device_name.c_str(), pool_type.c_str()/* sd->msg */);
167 +
168 +   for (i=0; i < MAX_STORE; i++) {
169 +      if (jcr->storage[i]) {
170 +        storage = (STORE *)jcr->storage[i]->first();
171 +        pm_strcpy(device_name, storage->dev_name);
172 +        pm_strcpy(media_type, storage->media_type);
173 +        pm_strcpy(pool_type, jcr->pool->pool_type);
174 +        pm_strcpy(pool_name, jcr->pool->hdr.name);
175 +        bash_spaces(device_name);
176 +        bash_spaces(media_type);
177 +        bash_spaces(pool_type);
178 +        bash_spaces(pool_name);
179 +        bnet_fsend(sd, use_device, device_name.c_str(), 
180 +                   media_type.c_str(), pool_name.c_str(), pool_type.c_str());
181 +         Dmsg1(110, ">stored: %s", sd->msg);
182 +         status = response(jcr, sd, OK_device, "Use Device", NO_DISPLAY);
183 +        if (!status) {
184 +           pm_strcpy(pool_type, sd->msg); /* save message */
185 +            Jmsg(jcr, M_FATAL, 0, _("\n"
186 +               "     Storage daemon didn't accept Device \"%s\" because:\n     %s"),
187 +              device_name.c_str(), pool_type.c_str()/* sd->msg */);
188 +        }
189 +      }
190     }
191     return status;
192  }
193 Index: src/dird/protos.h
194 ===================================================================
195 RCS file: /cvsroot/bacula/bacula/src/dird/protos.h,v
196 retrieving revision 1.56
197 diff -u -r1.56 protos.h
198 --- src/dird/protos.h   17 Nov 2004 22:48:22 -0000      1.56
199 +++ src/dird/protos.h   21 Dec 2004 13:04:08 -0000
200 @@ -1,7 +1,7 @@
201  /*
202   * Director external function prototypes
203   *
204 - *   Version $Id$
205 + *   Version $Id$
206   */
207  /*
208     Copyright (C) 2000-2004 Kern Sibbald and John Walker
209 @@ -62,7 +62,7 @@
210  
211  /* fd_cmds.c */
212  extern int connect_to_file_daemon(JCR *jcr, int retry_interval,
213 -                                  int max_retry_time, int verbose);
214 +                                 int max_retry_time, int verbose);
215  extern int send_include_list(JCR *jcr);
216  extern int send_exclude_list(JCR *jcr);
217  extern int send_bootstrap_file(JCR *jcr);
218 @@ -70,7 +70,7 @@
219  extern int get_attributes_and_put_in_catalog(JCR *jcr);
220  extern int get_attributes_and_compare_to_catalog(JCR *jcr, JobId_t JobId);
221  extern int put_file_into_catalog(JCR *jcr, long file_index, char *fname, 
222 -                          char *link, char *attr, int stream);
223 +                         char *link, char *attr, int stream);
224  extern void get_level_since_time(JCR *jcr, char *since, int since_len);
225  extern int send_run_before_and_after_commands(JCR *jcr);
226  
227 @@ -91,13 +91,14 @@
228  extern int cancel_job(UAContext *ua, JCR *jcr);
229  extern void init_jcr_job_record(JCR *jcr);
230  extern void copy_storage(JCR *new_jcr, JCR *old_jcr);
231 +extern void set_storage(JCR *jcr, STORE *store);
232  
233  /* mountreq.c */
234  extern void mount_request(JCR *jcr, BSOCK *bs, char *buf);
235  
236  /* msgchan.c */
237  extern bool connect_to_storage_daemon(JCR *jcr, int retry_interval,    
238 -                              int max_retry_time, int verbose);
239 +                             int max_retry_time, int verbose);
240  extern int start_storage_daemon_job(JCR *jcr);
241  extern int start_storage_daemon_message_thread(JCR *jcr);
242  extern int bget_dirmsg(BSOCK *bs);
243 @@ -149,28 +150,28 @@
244  void free_ua_context(UAContext *ua);
245  
246  /* ua_select.c */
247 -STORE   *select_storage_resource(UAContext *ua);
248 -JOB     *select_job_resource(UAContext *ua);
249 -JOB     *select_restore_job_resource(UAContext *ua);
250 -CLIENT  *select_client_resource(UAContext *ua);
251 +STORE  *select_storage_resource(UAContext *ua);
252 +JOB    *select_job_resource(UAContext *ua);
253 +JOB    *select_restore_job_resource(UAContext *ua);
254 +CLIENT *select_client_resource(UAContext *ua);
255  FILESET *select_fileset_resource(UAContext *ua);
256 -int     select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr);
257 -int     select_media_dbr(UAContext *ua, MEDIA_DBR *mr);
258 -bool    select_pool_dbr(UAContext *ua, POOL_DBR *pr);
259 -int     select_client_dbr(UAContext *ua, CLIENT_DBR *cr);
260 -
261 -void    start_prompt(UAContext *ua, const char *msg);
262 -void    add_prompt(UAContext *ua, const char *prompt);
263 -int     do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt);
264 -CAT    *get_catalog_resource(UAContext *ua);           
265 +int    select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr);
266 +int    select_media_dbr(UAContext *ua, MEDIA_DBR *mr);
267 +bool   select_pool_dbr(UAContext *ua, POOL_DBR *pr);
268 +int    select_client_dbr(UAContext *ua, CLIENT_DBR *cr);
269 +
270 +void   start_prompt(UAContext *ua, const char *msg);
271 +void   add_prompt(UAContext *ua, const char *prompt);
272 +int    do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt);
273 +CAT    *get_catalog_resource(UAContext *ua);          
274  STORE  *get_storage_resource(UAContext *ua, int use_default);
275 -int     get_media_type(UAContext *ua, char *MediaType, int max_media);
276 -bool    get_pool_dbr(UAContext *ua, POOL_DBR *pr);
277 -int     get_client_dbr(UAContext *ua, CLIENT_DBR *cr);
278 +int    get_media_type(UAContext *ua, char *MediaType, int max_media);
279 +bool   get_pool_dbr(UAContext *ua, POOL_DBR *pr);
280 +int    get_client_dbr(UAContext *ua, CLIENT_DBR *cr);
281  POOL   *get_pool_resource(UAContext *ua);
282  POOL   *select_pool_resource(UAContext *ua);
283  CLIENT *get_client_resource(UAContext *ua);
284 -int     get_job_dbr(UAContext *ua, JOB_DBR *jr);
285 +int    get_job_dbr(UAContext *ua, JOB_DBR *jr);
286  
287  int find_arg_keyword(UAContext *ua, const char **list);
288  int find_arg(UAContext *ua, const char *keyword);
289 @@ -190,3 +191,6 @@
290  
291  /* ua_purge.c */
292  int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr);
293 +
294 +/* ua_run.c */
295 +extern int run_cmd(UAContext *ua, const char *cmd);
296 Index: src/dird/scheduler.c
297 ===================================================================
298 RCS file: /cvsroot/bacula/bacula/src/dird/scheduler.c,v
299 retrieving revision 1.27
300 diff -u -r1.27 scheduler.c
301 --- src/dird/scheduler.c        3 Oct 2004 19:47:34 -0000       1.27
302 +++ src/dird/scheduler.c        21 Dec 2004 13:04:08 -0000
303 @@ -10,7 +10,7 @@
304   *   Version $Id$
305   */
306  /*
307 -   Copyright (C) 2000-2004 Kern Sibbald and John Walker
308 +   Copyright (C) 2000-2004 Kern Sibbald
309  
310     This program is free software; you can redistribute it and/or
311     modify it under the terms of the GNU General Public License as
312 @@ -157,7 +157,7 @@
313        jcr->dif_pool = run->dif_pool;  /* override dif pool */
314     }
315     if (run->storage) {
316 -      jcr->store = run->storage;      /* override storage */
317 +      set_storage(jcr, run->storage); /* override storage */
318     }
319     if (run->msgs) {
320        jcr->messages = run->msgs;      /* override messages */
321 Index: src/dird/ua.h
322 ===================================================================
323 RCS file: /cvsroot/bacula/bacula/src/dird/ua.h,v
324 retrieving revision 1.23
325 diff -u -r1.23 ua.h
326 --- src/dird/ua.h       18 Jun 2004 10:07:41 -0000      1.23
327 +++ src/dird/ua.h       21 Dec 2004 13:04:08 -0000
328 @@ -3,7 +3,7 @@
329   *
330   *     Kern Sibbald, August MMI
331   *
332 - *     Version $Id$
333 + *     Version $Id$
334   */
335  /*
336     Copyright (C) 2000-2004 Kern Sibbald and John Walker
337 @@ -48,6 +48,7 @@
338     bool automount;                    /* if set, mount after label */
339     bool quit;                         /* if set, quit */
340     bool verbose;                      /* set for normal UA verbosity */
341 +   bool batch;                        /* set for non-interactive mode */
342     uint32_t pint32_val;               /* positive integer */
343     int32_t  int32_val;                /* positive/negative */
344  };          
345 Index: src/dird/ua_cmds.c
346 ===================================================================
347 RCS file: /cvsroot/bacula/bacula/src/dird/ua_cmds.c,v
348 retrieving revision 1.127
349 diff -u -r1.127 ua_cmds.c
350 --- src/dird/ua_cmds.c  4 Oct 2004 20:34:01 -0000       1.127
351 +++ src/dird/ua_cmds.c  21 Dec 2004 13:04:10 -0000
352 @@ -4,7 +4,7 @@
353   *
354   *     Kern Sibbald, September MM
355   *
356 - *   Version $Id$
357 + *   Version $Id$
358   */
359  
360  /*
361 @@ -52,7 +52,6 @@
362  extern int gui_cmd(UAContext *ua, const char *cmd);
363  extern int sqlquerycmd(UAContext *ua, const char *cmd);
364  extern int querycmd(UAContext *ua, const char *cmd);
365 -extern int run_cmd(UAContext *ua, const char *cmd);
366  extern int retentioncmd(UAContext *ua, const char *cmd);
367  extern int prunecmd(UAContext *ua, const char *cmd);
368  extern int purgecmd(UAContext *ua, const char *cmd);
369 @@ -1195,7 +1194,7 @@
370     BSOCK *sd;
371     JCR *jcr = ua->jcr;
372  
373 -   jcr->store = store;
374 +   set_storage(jcr, store);
375     /* Try connecting for up to 15 seconds */
376     bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d\n"), 
377        store->hdr.name, store->address, store->SDport);
378 @@ -1254,8 +1253,10 @@
379     /* Count Storage items */
380     LockRes();
381     store = NULL;
382 -   for (i=0; (store = (STORE *)GetNextRes(R_STORAGE, (RES *)store)); i++)
383 -      { }
384 +   i = 0;
385 +   foreach_res(store, R_STORAGE) {
386 +      i++;
387 +   }
388     unique_store = (STORE **) malloc(i * sizeof(STORE));
389     /* Find Unique Storage address/port */        
390     store = (STORE *)GetNextRes(R_STORAGE, NULL);
391 @@ -1286,8 +1287,10 @@
392     /* Count Client items */
393     LockRes();
394     client = NULL;
395 -   for (i=0; (client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client)); i++)
396 -      { }
397 +   i = 0;
398 +   foreach_res(client, R_CLIENT) {
399 +      i++;
400 +   }
401     unique_client = (CLIENT **) malloc(i * sizeof(CLIENT));
402     /* Find Unique Client address/port */        
403     client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
404 @@ -1841,7 +1844,7 @@
405     Dmsg2(120, "Found storage, MediaType=%s DevName=%s\n",
406        store->media_type, store->dev_name);
407  
408 -   jcr->store = store;
409 +   set_storage(jcr, store);
410     if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
411        bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
412        return;
413 Index: src/dird/ua_label.c
414 ===================================================================
415 RCS file: /cvsroot/bacula/bacula/src/dird/ua_label.c,v
416 retrieving revision 1.38
417 diff -u -r1.38 ua_label.c
418 --- src/dird/ua_label.c 17 Aug 2004 14:40:09 -0000      1.38
419 +++ src/dird/ua_label.c 21 Dec 2004 13:04:10 -0000
420 @@ -8,7 +8,7 @@
421   */
422  
423  /*
424 -   Copyright (C) 2000-2004 Kern Sibbald and John Walker
425 +   Copyright (C) 2000-2004 Kern Sibbald
426  
427     This program is free software; you can redistribute it and/or
428     modify it under the terms of the GNU General Public License as
429 @@ -170,7 +170,7 @@
430     if (!store) {
431        return 1;
432     }
433 -   ua->jcr->store = store;
434 +   set_storage(ua->jcr, store);
435  
436     scan = find_arg(ua, _("scan")) >= 0;
437  
438 @@ -296,7 +296,7 @@
439     if (!store) {
440        return 1;
441     }
442 -   ua->jcr->store = store;
443 +   set_storage(ua->jcr, store);
444  
445     if (!relabel && find_arg_keyword(ua, barcode_keyword) >= 0) {
446        label_from_barcodes(ua);
447 Index: src/dird/ua_run.c
448 ===================================================================
449 RCS file: /cvsroot/bacula/bacula/src/dird/ua_run.c,v
450 retrieving revision 1.58
451 diff -u -r1.58 ua_run.c
452 --- src/dird/ua_run.c   8 Nov 2004 21:12:12 -0000       1.58
453 +++ src/dird/ua_run.c   21 Dec 2004 13:04:11 -0000
454 @@ -4,11 +4,11 @@
455   *
456   *     Kern Sibbald, December MMI
457   *
458 - *   Version $Id$
459 + *   Version $Id$
460   */
461  
462  /*
463 -   Copyright (C) 2001-2004 Kern Sibbald and John Walker
464 +   Copyright (C) 2001-2004 Kern Sibbald
465  
466     This program is free software; you can redistribute it and/or
467     modify it under the terms of the GNU General Public License as
468 @@ -42,6 +42,9 @@
469   * For Restore Jobs
470   *     run <job-name> jobid=nn
471   *
472 + *  Returns: 0 on error
473 + *          JobId if OK
474 + *
475   */
476  int run_cmd(UAContext *ua, const char *cmd)
477  {
478 @@ -101,7 +104,7 @@
479     catalog_name = NULL;
480  
481     for (i=1; i<ua->argc; i++) {
482 -      Dmsg2(200, "Doing arg %d = %s\n", i, ua->argk[i]);
483 +      Dmsg2(800, "Doing arg %d = %s\n", i, ua->argk[i]);
484        kw_ok = false;
485        /* Keep looking until we find a good keyword */
486        for (j=0; !kw_ok && kw[j]; j++) {
487 @@ -111,12 +114,12 @@
488                 bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]);
489                return 1;
490             }
491 -            Dmsg1(200, "Got keyword=%s\n", kw[j]);
492 +            Dmsg1(800, "Got keyword=%s\n", kw[j]);
493             switch (j) {
494             case 0: /* job */
495                if (job_name) {
496                    bsendmsg(ua, _("Job name specified twice.\n"));
497 -                 return 1;
498 +                 return 0;
499                }
500                job_name = ua->argv[i];
501                kw_ok = true;
502 @@ -124,7 +127,7 @@
503             case 1: /* JobId */
504                if (jid) {
505                    bsendmsg(ua, _("JobId specified twice.\n"));
506 -                 return 1;
507 +                 return 0;
508                }
509                jid = ua->argv[i];
510                kw_ok = true;
511 @@ -133,7 +136,7 @@
512             case 3: /* fd */
513                if (client_name) {
514                    bsendmsg(ua, _("Client specified twice.\n"));
515 -                 return 1;
516 +                 return 0;
517                }
518                client_name = ua->argv[i];
519                kw_ok = true;
520 @@ -141,7 +144,7 @@
521             case 4: /* fileset */
522                if (fileset_name) {
523                    bsendmsg(ua, _("FileSet specified twice.\n"));
524 -                 return 1;
525 +                 return 0;
526                }
527                fileset_name = ua->argv[i];
528                kw_ok = true;
529 @@ -149,7 +152,7 @@
530             case 5: /* level */
531                if (level_name) {
532                    bsendmsg(ua, _("Level specified twice.\n"));
533 -                 return 1;
534 +                 return 0;
535                }
536                level_name = ua->argv[i];
537                kw_ok = true;
538 @@ -158,7 +161,7 @@
539             case 7: /* sd */
540                if (store_name) {
541                    bsendmsg(ua, _("Storage specified twice.\n"));
542 -                 return 1;
543 +                 return 0;
544                }
545                store_name = ua->argv[i];
546                kw_ok = true;
547 @@ -166,7 +169,7 @@
548             case 8: /* pool */
549                if (pool_name) {
550                    bsendmsg(ua, _("Pool specified twice.\n"));
551 -                 return 1;
552 +                 return 0;
553                }
554                pool_name = ua->argv[i];
555                kw_ok = true;
556 @@ -174,7 +177,7 @@
557             case 9: /* where */
558                if (where) {
559                    bsendmsg(ua, _("Where specified twice.\n"));
560 -                 return 1;
561 +                 return 0;
562                }
563                where = ua->argv[i];
564                kw_ok = true;
565 @@ -182,7 +185,7 @@
566             case 10: /* bootstrap */
567                if (bootstrap) {
568                    bsendmsg(ua, _("Bootstrap specified twice.\n"));
569 -                 return 1;
570 +                 return 0;
571                }
572                bootstrap = ua->argv[i];
573                kw_ok = true;
574 @@ -190,7 +193,7 @@
575             case 11: /* replace */
576                if (replace) {
577                    bsendmsg(ua, _("Replace specified twice.\n"));
578 -                 return 1;
579 +                 return 0;
580                }
581                replace = ua->argv[i];
582                kw_ok = true;
583 @@ -198,7 +201,7 @@
584             case 12: /* When */
585                if (when) {
586                    bsendmsg(ua, _("When specified twice.\n"));
587 -                 return 1;
588 +                 return 0;
589                }
590                when = ua->argv[i];
591                kw_ok = true;
592 @@ -206,7 +209,7 @@
593             case 13:  /* Priority */
594                if (Priority) {
595                    bsendmsg(ua, _("Priority specified twice.\n"));
596 -                 return 1;
597 +                 return 0;
598                }
599                Priority = atoi(ua->argv[i]);
600                if (Priority <= 0) {
601 @@ -221,7 +224,7 @@
602             case 15: /* Verify Job */
603                if (verify_job_name) {
604                    bsendmsg(ua, _("Verify Job specified twice.\n"));
605 -                 return 1;
606 +                 return 0;
607                }
608                verify_job_name = ua->argv[i];
609                kw_ok = true;
610 @@ -255,21 +258,22 @@
611              Dmsg1(200, "Set jobname=%s\n", job_name);
612          } else {
613              bsendmsg(ua, _("Invalid keyword: %s\n"), ua->argk[i]);
614 -           return 1;
615 +           return 0;
616          }
617        }
618     } /* end argc loop */
619              
620 -   Dmsg0(200, "Done scan.\n");
621 +   Dmsg0(800, "Done scan.\n");
622  
623     CAT *catalog = NULL;
624     if (catalog_name != NULL) {
625         catalog = (CAT *)GetResWithName(R_CATALOG, catalog_name);
626         if (catalog == NULL) {
627              bsendmsg(ua, _("Catalog \"%s\" not found\n"), catalog_name);
628 -          return 1;
629 +          return 0;
630         }
631     }
632 +   Dmsg1(200, "Using catalog=%s\n", catalog_name);
633  
634     if (job_name) {
635        /* Find Job */
636 @@ -287,11 +291,11 @@
637        job = select_job_resource(ua);
638     }
639     if (!job) {
640 -      return 1;
641 +      return 0;
642     } else if (!acl_access_ok(ua, Job_ACL, job->hdr.name)) {
643        bsendmsg(ua, _("No authorization. Job \"%s\".\n"),
644          job->hdr.name);
645 -      return 1;
646 +      return 0;
647     }
648  
649     if (store_name) {
650 @@ -310,8 +314,9 @@
651     } else if (!acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
652        bsendmsg(ua, _("No authorization. Storage \"%s\".\n"),
653                store->hdr.name);
654 -      return 1;
655 +      return 0;
656     }
657 +   Dmsg1(200, "Using storage=%s\n", store->hdr.name);
658  
659     if (pool_name) {
660        pool = (POOL *)GetResWithName(R_POOL, pool_name);
661 @@ -325,12 +330,13 @@
662        pool = job->pool;            /* use default */
663     }
664     if (!pool) {
665 -      return 1;
666 +      return 0;
667     } else if (!acl_access_ok(ua, Pool_ACL, store->hdr.name)) {
668        bsendmsg(ua, _("No authorization. Pool \"%s\".\n"),
669                pool->hdr.name);
670 -      return 1;
671 +      return 0;
672     }
673 +   Dmsg1(200, "Using pool\n", pool->hdr.name);
674  
675     if (client_name) {
676        client = (CLIENT *)GetResWithName(R_CLIENT, client_name);
677 @@ -344,12 +350,13 @@
678        client = job->client;          /* use default */
679     }
680     if (!client) {
681 -      return 1;
682 +      return 0;
683     } else if (!acl_access_ok(ua, Client_ACL, store->hdr.name)) {
684        bsendmsg(ua, _("No authorization. Client \"%s\".\n"),
685                client->hdr.name);
686 -      return 1;
687 +      return 0;
688     }
689 +   Dmsg1(200, "Using client=%s\n", client->hdr.name);
690  
691     if (fileset_name) {
692        fileset = (FILESET *)GetResWithName(R_FILESET, fileset_name);
693 @@ -361,11 +368,11 @@
694        fileset = job->fileset;          /* use default */
695     }
696     if (!fileset) {
697 -      return 1;
698 +      return 0;
699     } else if (!acl_access_ok(ua, FileSet_ACL, store->hdr.name)) {
700        bsendmsg(ua, _("No authorization. FileSet \"%s\".\n"),
701                fileset->hdr.name);
702 -      return 1;
703 +      return 0;
704     }
705  
706     if (verify_job_name) {
707 @@ -386,7 +393,7 @@
708     set_jcr_defaults(jcr, job);
709  
710     jcr->verify_job = verify_job;
711 -   jcr->store = store;
712 +   set_storage(jcr, store);
713     jcr->client = client;
714     jcr->fileset = fileset;
715     jcr->pool = pool;
716 @@ -460,7 +467,7 @@
717     }
718  
719     /* Run without prompting? */
720 -   if (find_arg(ua, _("yes")) > 0) {
721 +   if (ua->batch || find_arg(ua, _("yes")) > 0) {
722        goto start_job;
723     }
724  
725 @@ -701,7 +708,7 @@
726          /* Storage */
727          store = select_storage_resource(ua);
728          if (store) {
729 -           jcr->store = store;
730 +           set_storage(jcr, store);
731             goto try_again;
732          }
733          break;
734 @@ -847,7 +854,7 @@
735        } else {
736           bsendmsg(ua, _("Job started. JobId=%u\n"), JobId);
737        }
738 -      return 1;
739 +      return JobId;
740     }
741  
742  bail_out:
743 Index: src/dird/ua_server.c
744 ===================================================================
745 RCS file: /cvsroot/bacula/bacula/src/dird/ua_server.c,v
746 retrieving revision 1.35
747 diff -u -r1.35 ua_server.c
748 --- src/dird/ua_server.c        19 Sep 2004 18:56:24 -0000      1.35
749 +++ src/dird/ua_server.c        21 Dec 2004 13:04:11 -0000
750 @@ -99,6 +99,15 @@
751  {
752     JCR *jcr;
753     jcr = new_jcr(sizeof(JCR), dird_free_jcr);
754 +   /*
755 +    * The job and defaults are not really used, but
756 +    *  we set them up to ensure that everything is correctly
757 +    *  initialized.
758 +    */
759 +   LockRes();
760 +   jcr->job = (JOB *)GetNextRes(R_JOB, NULL);
761 +   set_jcr_defaults(jcr, jcr->job);
762 +   UnlockRes();
763     jcr->sd_auth_key = bstrdup("dummy"); /* dummy Storage daemon key */
764     create_unique_job_name(jcr, base_name);
765     jcr->sched_time = jcr->start_time;
766 @@ -106,20 +115,6 @@
767     jcr->JobLevel = L_NONE;
768     jcr->JobStatus = JS_Running;
769     jcr->JobId = 0;
770 -   /*
771 -    * None of these are really defined for control JCRs, so we
772 -    * simply take the first of each one. This ensures that there
773 -    * will be no null pointer references.
774 -    */
775 -   LockRes();
776 -   jcr->job = (JOB *)GetNextRes(R_JOB, NULL);
777 -   jcr->messages = (MSGS *)GetNextRes(R_MSGS, NULL);
778 -   jcr->client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
779 -   jcr->pool = (POOL *)GetNextRes(R_POOL, NULL);
780 -   jcr->catalog = (CAT *)GetNextRes(R_CATALOG, NULL);
781 -   jcr->store = (STORE *)GetNextRes(R_STORAGE, NULL);
782 -   jcr->fileset = (FILESET *)GetNextRes(R_FILESET, NULL);
783 -   UnlockRes();
784     return jcr;
785  }
786  
787 Index: src/dird/ua_status.c
788 ===================================================================
789 RCS file: /cvsroot/bacula/bacula/src/dird/ua_status.c,v
790 retrieving revision 1.61
791 diff -u -r1.61 ua_status.c
792 --- src/dird/ua_status.c        19 Sep 2004 18:56:25 -0000      1.61
793 +++ src/dird/ua_status.c        21 Dec 2004 13:04:12 -0000
794 @@ -282,7 +282,7 @@
795  {
796     BSOCK *sd;
797  
798 -   ua->jcr->store = store;
799 +   set_storage(ua->jcr, store);
800     /* Try connecting for up to 15 seconds */
801     bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d\n"), 
802        store->hdr.name, store->address, store->SDport);