]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/msgchan.c
Implement first cut running console commands in a RunScript.
[bacula/bacula] / bacula / src / dird / msgchan.c
index ea1bfa390beacd254de324a81373113b1fe6a9d9..43d859aa28cc9ced483c6879476e34f8de95287a 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-20076 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
@@ -51,7 +51,7 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 /* Commands sent to Storage daemon */
 static char jobcmd[]     = "JobId=%s job=%s job_name=%s client_name=%s "
    "type=%d level=%d FileSet=%s NoAttr=%d SpoolAttr=%d FileSetMD5=%s "
-   "SpoolData=%d WritePartAfterJob=%d PreferMountedVols=%d\n";
+   "SpoolData=%d WritePartAfterJob=%d PreferMountedVols=%d SpoolSize=%s\n";
 static char use_storage[] = "use storage=%s media_type=%s pool_name=%s "
    "pool_type=%s append=%d copy=%d stripe=%d\n";
 static char use_device[] = "use device=%s\n";
@@ -112,7 +112,7 @@ bool connect_to_storage_daemon(JCR *jcr, int retry_interval,
    jcr->store_bsock = sd;
 
    if (!authenticate_storage_daemon(jcr, store)) {
-      bnet_close(sd);
+      sd->close();
       jcr->store_bsock = NULL;
       return false;
    }
@@ -134,7 +134,7 @@ bool update_device_res(JCR *jcr, DEVICE *dev)
    sd = jcr->store_bsock;
    pm_strcpy(device_name, dev->name());
    bash_spaces(device_name);
-   bnet_fsend(sd, query_device, device_name.c_str());
+   sd->fsend(query_device, device_name.c_str());
    Dmsg1(100, ">stored: %s\n", sd->msg);
    /* The data is returned through Device_update */
    if (bget_dirmsg(sd) <= 0) {
@@ -157,7 +157,7 @@ bool start_storage_daemon_job(JCR *jcr, alist *rstore, alist *wstore)
    POOL_MEM job_name, client_name, fileset_name;
    int copy = 0;
    int stripe = 0;
-   char ed1[30];
+   char ed1[30], ed2[30];
 
    sd = jcr->store_bsock;
    /*
@@ -178,16 +178,17 @@ bool start_storage_daemon_job(JCR *jcr, alist *rstore, alist *wstore)
     *  for the same jobid.
     */
    if (jcr->reschedule_count) {
-      bnet_fsend(sd, "cancel Job=%s\n", jcr->Job);
-      while (bnet_recv(sd) >= 0)
+      sd->fsend("cancel Job=%s\n", jcr->Job);
+      while (sd->recv() >= 0)
          { }
    } 
-   bnet_fsend(sd, jobcmd, edit_int64(jcr->JobId, ed1), jcr->Job, 
-              job_name.c_str(), client_name.c_str(), 
-              jcr->JobType, jcr->JobLevel,
-              fileset_name.c_str(), !jcr->pool->catalog_files,
-              jcr->job->SpoolAttributes, jcr->fileset->MD5, jcr->spool_data, 
-              jcr->write_part_after_job, jcr->job->PreferMountedVolumes);
+   sd->fsend(jobcmd, edit_int64(jcr->JobId, ed1), jcr->Job, 
+             job_name.c_str(), client_name.c_str(), 
+             jcr->JobType, jcr->JobLevel,
+             fileset_name.c_str(), !jcr->pool->catalog_files,
+             jcr->job->SpoolAttributes, jcr->fileset->MD5, jcr->spool_data, 
+             jcr->write_part_after_job, jcr->job->PreferMountedVolumes,
+             edit_int64(jcr->spool_size, ed2));
    Dmsg1(100, ">stored: %s\n", sd->msg);
    if (bget_dirmsg(sd) > 0) {
        Dmsg1(100, "<stored: %s", sd->msg);
@@ -202,7 +203,7 @@ bool start_storage_daemon_job(JCR *jcr, alist *rstore, alist *wstore)
        }
    } else {
       Jmsg(jcr, M_FATAL, 0, _("<stored: bad response to Job command: %s\n"),
-         bnet_strerror(sd));
+         sd->bstrerror());
       return 0;
    }
 
@@ -232,20 +233,20 @@ bool start_storage_daemon_job(JCR *jcr, alist *rstore, alist *wstore)
          bash_spaces(store_name);
          pm_strcpy(media_type, storage->media_type);
          bash_spaces(media_type);
-         bnet_fsend(sd, use_storage, store_name.c_str(), media_type.c_str(), 
-                    pool_name.c_str(), pool_type.c_str(), 0, copy, stripe);
+         sd->fsend(use_storage, store_name.c_str(), media_type.c_str(), 
+                   pool_name.c_str(), pool_type.c_str(), 0, copy, stripe);
          Dmsg1(100, "rstore >stored: %s", sd->msg);
          DEVICE *dev;
          /* Loop over alternative storage Devices until one is OK */
          foreach_alist(dev, storage->device) {
             pm_strcpy(device_name, dev->name());
             bash_spaces(device_name);
-            bnet_fsend(sd, use_device, device_name.c_str());
+            sd->fsend(use_device, device_name.c_str());
             Dmsg1(100, ">stored: %s", sd->msg);
          }
-         bnet_sig(sd, BNET_EOD);            /* end of Devices */
+         sd->signal(BNET_EOD);           /* end of Devices */
       }
-      bnet_sig(sd, BNET_EOD);            /* end of Storages */
+      sd->signal(BNET_EOD);              /* end of Storages */
       if (bget_dirmsg(sd) > 0) {
          Dmsg1(100, "<stored: %s", sd->msg);
          /* ****FIXME**** save actual device name */
@@ -266,8 +267,8 @@ bool start_storage_daemon_job(JCR *jcr, alist *rstore, alist *wstore)
          bash_spaces(store_name);
          pm_strcpy(media_type, storage->media_type);
          bash_spaces(media_type);
-         bnet_fsend(sd, use_storage, store_name.c_str(), media_type.c_str(), 
-                    pool_name.c_str(), pool_type.c_str(), 1, copy, stripe);
+         sd->fsend(use_storage, store_name.c_str(), media_type.c_str(), 
+                   pool_name.c_str(), pool_type.c_str(), 1, copy, stripe);
 
          Dmsg1(100, "wstore >stored: %s", sd->msg);
          DEVICE *dev;
@@ -275,12 +276,12 @@ bool start_storage_daemon_job(JCR *jcr, alist *rstore, alist *wstore)
          foreach_alist(dev, storage->device) {
             pm_strcpy(device_name, dev->name());
             bash_spaces(device_name);
-            bnet_fsend(sd, use_device, device_name.c_str());
+            sd->fsend(use_device, device_name.c_str());
             Dmsg1(100, ">stored: %s", sd->msg);
          }
-         bnet_sig(sd, BNET_EOD);            /* end of Devices */
+         sd->signal(BNET_EOD);           /* end of Devices */
       }
-      bnet_sig(sd, BNET_EOD);            /* end of Storages */
+      sd->signal(BNET_EOD);              /* end of Storages */
       if (bget_dirmsg(sd) > 0) {
          Dmsg1(100, "<stored: %s", sd->msg);
          /* ****FIXME**** save actual device name */
@@ -363,6 +364,7 @@ extern "C" void *msg_thread(void *arg)
    int stat;
 
    pthread_detach(pthread_self());
+   set_jcr_in_tsd(jcr);
    jcr->SD_msg_chan = pthread_self();
    pthread_cleanup_push(msg_thread_cleanup, arg);
    sd = jcr->store_bsock;
@@ -409,8 +411,8 @@ void wait_for_storage_daemon_termination(JCR *jcr)
       V(mutex);
       if (job_canceled(jcr)) {
          if (jcr->SD_msg_chan) {
-            jcr->store_bsock->m_timed_out = 1;
-            jcr->store_bsock->m_terminated = 1;
+            jcr->store_bsock->set_timed_out();
+            jcr->store_bsock->set_terminated();
             Dmsg2(400, "kill jobid=%d use=%d\n", (int)jcr->JobId, jcr->use_count());
             pthread_kill(jcr->SD_msg_chan, TIMEOUT_SIGNAL);
          }