]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/getmsg.c
ebl Modify disk-changer to check if slot contains something before
[bacula/bacula] / bacula / src / dird / getmsg.c
index 4a7b758c939865f8208f6cd6da40d6e921aed48e..59a1ecd2dec68ac82c0d6ef9a773a6eaea9b0f24 100644 (file)
@@ -1,36 +1,14 @@
-/*
- *
- *   Bacula Director -- routines to receive network data and
- *    handle network signals. These routines handle the connections
- *    to the Storage daemon and the File daemon.
- *
- *     Kern Sibbald, August MM
- *
- *    This routine runs as a thread and must be thread reentrant.
- *
- *  Basic tasks done here:
- *    Handle  network signals (signals).
- *       Signals always have return status 0 from bnet_recv() and
- *       a zero or negative message length.
- *    Pass appropriate messages back to the caller (responses).
- *       Responses always have a digit as the first character.
- *    Handle requests for message and catalog services (requests).
- *       Requests are any message that does not begin with a digit.
- *       In affect, they are commands.
- *
- *   Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 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.
    This program is Free Software; you can redistribute it and/or
    modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ *
+ *   Bacula Director -- routines to receive network data and
+ *    handle network signals. These routines handle the connections
+ *    to the Storage daemon and the File daemon.
+ *
+ *     Kern Sibbald, August MM
+ *
+ *    This routine runs as a thread and must be thread reentrant.
+ *
+ *  Basic tasks done here:
+ *    Handle  network signals (signals).
+ *       Signals always have return status 0 from bnet_recv() and
+ *       a zero or negative message length.
+ *    Pass appropriate messages back to the caller (responses).
+ *       Responses always have a digit as the first character.
+ *    Handle requests for message and catalog services (requests).
+ *       Requests are any message that does not begin with a digit.
+ *       In affect, they are commands.
+ *
+ *   Version $Id$
+ */
 
 #include "bacula.h"
 #include "dird.h"
@@ -70,6 +70,33 @@ static char Device_update[]   = "DevUpd Job=%127s "
 
 static char OK_msg[] = "1000 OK\n";
 
+
+void set_jcr_sd_job_status(JCR *jcr, int SDJobStatus)
+{
+   bool set_waittime=false;
+   Dmsg2(800, "set_jcr_sd_job_status(%s, %c)\n", jcr->Job, SDJobStatus);
+   /* if wait state is new, we keep current time for watchdog MaxWaitTime */
+   switch (SDJobStatus) {
+      case JS_WaitMedia:
+      case JS_WaitMount:
+      case JS_WaitMaxJobs:
+        set_waittime = true;
+      default:
+        break;
+   }
+
+   if (job_waiting(jcr)) {
+      set_waittime = false;
+   }
+
+   if (set_waittime) {
+      /* set it before JobStatus */
+      Dmsg0(800, "Setting wait_time\n");
+      jcr->wait_time = time(NULL);
+   }
+   jcr->SDJobStatus = SDJobStatus;
+}
+
 /*
  * Get a message
  *  Call appropriate processing routine
@@ -106,8 +133,8 @@ int bget_dirmsg(BSOCK *bs)
    char *msg;
 
    for (;;) {
-      n = bnet_recv(bs);
-      Dmsg2(900, "bget_dirmsg %d: %s", n, bs->msg);
+      n = bs->recv();
+      Dmsg2(100, "bget_dirmsg %d: %s\n", n, bs->msg);
 
       if (is_bnet_stop(bs)) {
          return n;                    /* error or terminate */
@@ -118,13 +145,13 @@ int bget_dirmsg(BSOCK *bs)
          case BNET_EOD:            /* end of data */
             return n;
          case BNET_EOD_POLL:
-            bnet_fsend(bs, OK_msg);/* send response */
+            bs->fsend(OK_msg);/* send response */
             return n;              /* end of data */
          case BNET_TERMINATE:
-            bs->terminated = 1;
+            bs->set_terminated();
             return n;
          case BNET_POLL:
-            bnet_fsend(bs, OK_msg); /* send response */
+            bs->fsend(OK_msg); /* send response */
             break;
          case BNET_HEARTBEAT:
 //          encode_time(time(NULL), Job);
@@ -134,12 +161,12 @@ int bget_dirmsg(BSOCK *bs)
             break;
          case BNET_STATUS:
             /* *****FIXME***** Implement more completely */
-            bnet_fsend(bs, "Status OK\n");
-            bnet_sig(bs, BNET_EOD);
+            bs->fsend("Status OK\n");
+            bs->signal(BNET_EOD);
             break;
          case BNET_BTIME:             /* send Bacula time */
             char ed1[50];
-            bnet_fsend(bs, "btime %s\n", edit_uint64(get_current_btime(),ed1));
+            bs->fsend("btime %s\n", edit_uint64(get_current_btime(),ed1));
             break;
          default:
             Emsg1(M_WARNING, 0, _("bget_dirmsg: unknown bnet signal %d\n"), bs->msglen);
@@ -213,7 +240,7 @@ int bget_dirmsg(BSOCK *bs)
          free_jcr(jcr);
          continue;
       }
-      if (bs->msg[0] == 'U') {        /* Catalog update */
+      if (bs->msg[0] == 'U') {        /* SD sending attributes */
          Dmsg2(900, "Catalog upd jcr 0x%x: %s", jcr, bs->msg);
          catalog_update(jcr, bs);
          Dmsg1(900, "Calling freejcr 0x%x\n", jcr);
@@ -230,7 +257,7 @@ int bget_dirmsg(BSOCK *bs)
          int JobStatus;
          char Job[MAX_NAME_LENGTH];
          if (sscanf(bs->msg, Job_status, &Job, &JobStatus) == 2) {
-            jcr->SDJobStatus = JobStatus; /* current status */
+            set_jcr_sd_job_status(jcr,JobStatus); /* current status */
          } else {
             Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
          }