]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/fd_cmds.c
Correct pool source setting
[bacula/bacula] / bacula / src / dird / fd_cmds.c
index 8eef4c3e6478b9de0c0de3f88e575d82c00acc29..febd1873d82c44b4dfb6ccd09ae672327e9046f5 100644 (file)
 
 /* Commands sent to File daemon */
 static char filesetcmd[]  = "fileset%s\n"; /* set full fileset */
-static char jobcmd[]      = "JobId=%d Job=%s SDid=%u SDtime=%u Authorization=%s\n";
+static char jobcmd[]      = "JobId=%s Job=%s SDid=%u SDtime=%u Authorization=%s\n";
 /* Note, mtime_only is not used here -- implemented as file option */
 static char levelcmd[]    = "level = %s%s mtime_only=%d\n";
-static char runbefore[]   = "RunBeforeJob %s\n";
-static char runafter[]    = "RunAfterJob %s\n";
-
+static char runscript[]   = "Run OnSuccess=%u OnFailure=%u AbortOnError=%u When=%u Command=%s\n";
+static char runbeforenow[]= "RunBeforeNow\n";
 
 /* Responses received from File daemon */
-static char OKinc[]       = "2000 OK include\n";
-static char OKjob[]       = "2000 OK Job";
-static char OKlevel[]     = "2000 OK level\n";
-static char OKRunBefore[] = "2000 OK RunBefore\n";
-static char OKRunAfter[]  = "2000 OK RunAfter\n";
+static char OKinc[]          = "2000 OK include\n";
+static char OKjob[]          = "2000 OK Job";
+static char OKlevel[]        = "2000 OK level\n";
+static char OKRunScript[]    = "2000 OK RunScript\n";
+static char OKRunBeforeNow[] = "2000 OK RunBeforeNow\n";
 
 /* Forward referenced functions */
 
@@ -67,6 +66,7 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time,
                            int verbose)
 {
    BSOCK   *fd;
+   char ed1[30];
 
    if (!jcr->file_bsock) {
       fd = bnet_connect(jcr, retry_interval, max_retry_time,
@@ -92,7 +92,7 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time,
    /*
     * Now send JobId and authorization key
     */
-   bnet_fsend(fd, jobcmd, jcr->JobId, jcr->Job, jcr->VolSessionId,
+   bnet_fsend(fd, jobcmd, edit_int64(jcr->JobId, ed1), jcr->Job, jcr->VolSessionId,
       jcr->VolSessionTime, jcr->sd_auth_key);
    if (strcmp(jcr->sd_auth_key, "dummy") != 0) {
       memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
@@ -193,7 +193,7 @@ static void send_since_time(JCR *jcr)
    char ed1[50];
 
    stime = str_to_utime(jcr->stime);
-   bnet_fsend(fd, levelcmd, _("since_utime "), edit_uint64(stime, ed1), 0);
+   bnet_fsend(fd, levelcmd, NT_("since_utime "), edit_uint64(stime, ed1), 0);
    while (bget_dirmsg(fd) >= 0) {  /* allow him to poll us to sync clocks */
       Jmsg(jcr, M_INFO, 0, "%s\n", fd->msg);
    }
@@ -457,33 +457,64 @@ bool send_bootstrap_file(JCR *jcr, BSOCK *sock)
 }
 
 /*
- * Send ClientRunBeforeJob and ClientRunAfterJob to File daemon
+ * Send RunScripts to File daemon
  */
-int send_run_before_and_after_commands(JCR *jcr)
+int send_runscripts_commands(JCR *jcr)
 {
    POOLMEM *msg = get_pool_memory(PM_FNAME);
    BSOCK *fd = jcr->file_bsock;
-   if (jcr->job->ClientRunBeforeJob) {
-      pm_strcpy(msg, jcr->job->ClientRunBeforeJob);
-      bash_spaces(msg);
-      bnet_fsend(fd, runbefore, msg);
-      if (!response(jcr, fd, OKRunBefore, "ClientRunBeforeJob", DISPLAY_ERROR)) {
-         set_jcr_job_status(jcr, JS_ErrorTerminated);
-         free_pool_memory(msg);
-         return 0;
-      }
+   RUNSCRIPT *cmd;
+   bool launch_before_cmd = false;
+   POOLMEM *ehost = get_pool_memory(PM_FNAME);
+
+   Dmsg0(120, "bdird: sending runscripts to fd\n");
+   
+   foreach_alist(cmd, jcr->job->RunScripts) {
+      
+      if (cmd->can_run_at_level(jcr->JobLevel) && cmd->target) {
+
+         ehost = edit_job_codes(jcr, ehost, cmd->target, "");
+         Dmsg2(200, "bdird: runscript %s -> %s\n", cmd->target, ehost);
+
+         if (strcmp(ehost, jcr->client->hdr.name) == 0) {
+            pm_strcpy(msg, cmd->command);
+            bash_spaces(msg);
+            bnet_fsend(fd, runscript, cmd->on_success, 
+                                      cmd->on_failure,
+                                      cmd->abort_on_error,
+                                      cmd->when,
+                                      msg);
+
+            Dmsg1(120, "bdird: sending runscripts to fd '%s'\n", cmd->command);
+
+            if (!response(jcr, fd, OKRunScript, "RunScript", DISPLAY_ERROR)) {
+               set_jcr_job_status(jcr, JS_ErrorTerminated);
+               free_pool_memory(msg);
+               free_pool_memory(ehost);
+               return 0;
+            }
+            launch_before_cmd=true;
+         }
+         /*
+           else {
+           send command to an other client
+           }
+         */
+      }        
    }
-   if (jcr->job->ClientRunAfterJob) {
-      fd->msglen = pm_strcpy(msg, jcr->job->ClientRunAfterJob);
-      bash_spaces(msg);
-      bnet_fsend(fd, runafter, msg);
-      if (!response(jcr, fd, OKRunAfter, "ClientRunAfterJob", DISPLAY_ERROR)) {
-         set_jcr_job_status(jcr, JS_ErrorTerminated);
-         free_pool_memory(msg);
-         return 0;
+   
+   /* TODO : we have to play with other client */
+   if (launch_before_cmd) {
+      bnet_fsend(fd, runbeforenow);
+      if (!response(jcr, fd, OKRunBeforeNow, "RunBeforeNow", DISPLAY_ERROR)) {
+        set_jcr_job_status(jcr, JS_ErrorTerminated);
+        free_pool_memory(msg);
+        free_pool_memory(ehost);
+        return 0;
       }
    }
    free_pool_memory(msg);
+   free_pool_memory(ehost);
    return 1;
 }