]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/job.c
Fix for reused thread ids by FreeBSD + qfill command
[bacula/bacula] / bacula / src / stored / job.c
index 0481e25866401d05399ea9e630f8bf81df3191c6..04e7ff3a9659cece823b7b7658854b06f6980024 100644 (file)
@@ -84,8 +84,9 @@ int job_cmd(JCR *jcr)
    if (sscanf(dir->msg, jobcmd, &JobId, job, job_name, client_name,
              &JobType, &level, fileset_name, &no_attributes,
              &spool_attributes, fileset_md5) != 10) {
-      bnet_fsend(dir, BAD_job, dir->msg);
-      Emsg1(M_FATAL, 0, _("Bad Job Command from Director: %s\n"), dir->msg);
+      pm_strcpy(&jcr->errmsg, dir->msg);
+      bnet_fsend(dir, BAD_job, jcr->errmsg);
+      Emsg1(M_FATAL, 0, _("Bad Job Command from Director: %s\n"), jcr->errmsg);
       free_memory(job);
       free_memory(job_name);
       free_memory(client_name);
@@ -135,16 +136,18 @@ int job_cmd(JCR *jcr)
    srandom(tv.tv_usec + tv.tv_sec);
    sprintf(auth_key, "%ld", (long)random());
 #endif
-   makeSessionKey(auth_key, NULL, 1);
+   make_session_key(auth_key, NULL, 1);
    bnet_fsend(dir, OKjob, jcr->VolSessionId, jcr->VolSessionTime, auth_key);
    Dmsg1(110, ">dird: %s", dir->msg);
    jcr->sd_auth_key = bstrdup(auth_key);
+   memset(auth_key, 0, sizeof(auth_key));    
 
    /*
     * Wait for the device, media, and pool information
     */
    if (!use_device_cmd(jcr)) {
       set_jcr_job_status(jcr, JS_ErrorTerminated);
+      memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
       return 0;
    }
 
@@ -162,7 +165,7 @@ int job_cmd(JCR *jcr)
     *  expires.
     */
    P(jcr->mutex);
-   for ( ;!job_cancelled(jcr); ) {
+   for ( ;!job_canceled(jcr); ) {
       errstat = pthread_cond_timedwait(&jcr->job_start_wait, &jcr->mutex, &timeout);
       if (errstat == 0 || errstat == ETIMEDOUT) {
         break;
@@ -170,7 +173,9 @@ int job_cmd(JCR *jcr)
    }
    V(jcr->mutex);
 
-   if (jcr->authenticated && !job_cancelled(jcr)) {
+   memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
+
+   if (jcr->authenticated && !job_canceled(jcr)) {
       run_job(jcr);                  /* Run the job */
    }
    return 0;
@@ -180,7 +185,7 @@ int job_cmd(JCR *jcr)
  * This entry point is only called if we have a separate
  *   Storage Daemon Data port. Otherwise, the connection
  *   is made to the main port, and if it is a File daemon
- *   calling, handl_filed_connection() is called directly.
+ *   calling, handle_filed_connection() is called directly.
  */
 void connection_from_filed(void *arg)
 {
@@ -194,8 +199,9 @@ void connection_from_filed(void *arg)
    }
    Dmsg1(100, "got: %s\n", fd->msg);
 
-   if (sscanf(fd->msg, "Hello Start Job %127s\n", job_name) != 1) {
-      Emsg1(M_FATAL, 0, _("Authentication failure: %s\n"), fd->msg);
+   if (fd->msglen < 17 || fd->msglen > 17+127 ||
+       sscanf(fd->msg, "Hello Start Job %127s\n", job_name) != 1) {
+      Emsg1(M_FATAL, 0, _("Bad Hello from FD: %s\n"), fd->msg);
       return;
    }
    handle_filed_connection(fd, job_name);
@@ -212,7 +218,7 @@ void handle_filed_connection(BSOCK *fd, char *job_name)
    }
 
    jcr->file_bsock = fd;
-   jcr->file_bsock->jcr = (void *)jcr;
+   jcr->file_bsock->jcr = jcr;
 
    Dmsg1(110, "Found Job %s\n", job_name);
 
@@ -234,7 +240,7 @@ void handle_filed_connection(BSOCK *fd, char *job_name)
 
    P(jcr->mutex);
    if (!jcr->authenticated) {
-      jcr->JobStatus = JS_ErrorTerminated;
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
    }
    pthread_cond_signal(&jcr->job_start_wait); /* wake waiting job */
    V(jcr->mutex);
@@ -299,19 +305,21 @@ static int use_device_cmd(JCR *jcr)
       UnlockRes();
       if (verbose) {
         unbash_spaces(dir->msg);
-         Jmsg(jcr, M_INFO, 0, _("Failed command: %s\n"), dir->msg);
+        pm_strcpy(&jcr->errmsg, dir->msg);
+         Jmsg(jcr, M_INFO, 0, _("Failed command: %s\n"), jcr->errmsg);
       }
       Jmsg(jcr, M_FATAL, 0, _("\n"
          "     Device \"%s\" requested by Dir not found in SD Device resources.\n"),
           dev_name);
       bnet_fsend(dir, NO_device, dev_name);
    } else {
+      unbash_spaces(dir->msg);
+      pm_strcpy(&jcr->errmsg, dir->msg);
       if (verbose) {
-        unbash_spaces(dir->msg);
-         Jmsg(jcr, M_INFO, 0, _("Failed command: %s\n"), dir->msg);
+         Jmsg(jcr, M_INFO, 0, _("Failed command: %s\n"), jcr->errmsg);
       }
-      Jmsg(jcr, M_FATAL, 0, _("store<dir: Bad Use Device command: %s\n"), dir->msg);
-      bnet_fsend(dir, BAD_use, dir->msg);
+      Jmsg(jcr, M_FATAL, 0, _("Bad Use Device command: %s\n"), jcr->errmsg);
+      bnet_fsend(dir, BAD_use, jcr->errmsg);
    }
 
    free_memory(dev_name);