]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/runscript_with_multiple_command_v2.patch
added latest changes
[bacula/bacula] / bacula / patches / testing / runscript_with_multiple_command_v2.patch
1 Index: src/dird/dird_conf.c
2 ===================================================================
3 --- src/dird/dird_conf.c        (rĂ©vision 6586)
4 +++ src/dird/dird_conf.c        (copie de travail)
5 @@ -1772,7 +1772,11 @@
6     lex_get_token(lc, T_STRING);
7  
8     if (pass == 2) {
9 -      ((RUNSCRIPT*)item->value)->set_command(lc->str, item->code);
10 +      Dmsg2(1, "runscript cmd=%s type=%c\n", lc->str, item->code);
11 +      POOLMEM *c = get_pool_memory(PM_FNAME);
12 +      pm_strcpy(c, lc->str);
13 +      ((RUNSCRIPT*) item->value)->commands->prepend(c);
14 +      ((RUNSCRIPT*) item->value)->commands->prepend((void *)item->code);
15     }
16     scan_to_eol(lc);
17  }
18 @@ -1874,7 +1878,8 @@
19   */
20  static void store_runscript(LEX *lc, RES_ITEM *item, int index, int pass)
21  {
22 -   int token, i;
23 +   char *c;
24 +   int token, i, t;
25     alist **runscripts = (alist **)(item->value) ;
26  
27     Dmsg1(200, "store_runscript: begin store_runscript pass=%i\n", pass);
28 @@ -1887,6 +1892,10 @@
29        scan_err1(lc, _("Expecting open brace. Got %s"), lc->str);
30     }
31     
32 +   if (pass == 2) {
33 +      res_runscript.commands = New(alist(10, not_owned_by_alist));
34 +   }
35 +
36     while ((token = lex_get_token(lc, T_SKIP_EOL)) != T_EOF) {
37        if (token == T_EOB) {
38          break;
39 @@ -1914,26 +1923,25 @@
40     }
41  
42     if (pass == 2) {
43 -      if (res_runscript.command == NULL) {
44 -         scan_err2(lc, _("%s item is required in %s resource, but not found.\n"),
45 -                   "command", "runscript");
46 -      }
47 -
48        /* run on client by default */
49        if (res_runscript.target == NULL) {
50           res_runscript.set_target("%c");
51        }
52 -
53 -      RUNSCRIPT *script = new_runscript();
54 -      memcpy(script, &res_runscript, sizeof(RUNSCRIPT));
55 -      script->set_job_code_callback(job_code_callback_filesetname);
56 -      
57        if (*runscripts == NULL) {
58 -        *runscripts = New(alist(10, not_owned_by_alist));
59 +         *runscripts = New(alist(10, not_owned_by_alist));
60        }
61 -      
62 -      (*runscripts)->append(script);
63 -      script->debug();
64 +      while ((c=(char*)res_runscript.commands->pop()) != NULL) {
65 +        t = (int) res_runscript.commands->pop();
66 +         RUNSCRIPT *script = new_runscript();
67 +         memcpy(script, &res_runscript, sizeof(RUNSCRIPT));
68 +         script->set_job_code_callback(job_code_callback_filesetname);
69 +         script->set_command(c, t);
70 +
71 +         (*runscripts)->append(script);
72 +         script->debug();
73 +      }
74 +      delete res_runscript.commands;
75 +      res_runscript.commands = NULL;
76     }
77  
78     scan_to_eol(lc);
79 Index: src/lib/runscript.h
80 ===================================================================
81 --- src/lib/runscript.h (rĂ©vision 6586)
82 +++ src/lib/runscript.h (copie de travail)
83 @@ -62,8 +62,8 @@
84  };
85  
86  enum {
87 -   SHELL_CMD   = 1,
88 -   CONSOLE_CMD = 2 
89 +   SHELL_CMD   = '|',
90 +   CONSOLE_CMD = '@' 
91  };
92  
93  /*
94 @@ -83,7 +83,7 @@
95     bool old_proto;              /* used by old 1.3X protocol */
96     job_code_callback_t job_code_callback;
97                                  /* Optional callback function passed to edit_job_code */
98 -
99 +   alist *commands;             /* Use during parsing */
100     bool run(JCR *job, const char *name=""); /* name must contain "Before" or "After" keyword */
101     bool can_run_at_level(int JobLevel) { return true;};        /* TODO */
102     void set_command(const POOLMEM *cmd, int cmd_type = SHELL_CMD);