]> git.sur5r.net Git - bacula/bacula/commitdiff
Add new files
authorKern Sibbald <kern@sibbald.com>
Thu, 8 May 2003 07:57:02 +0000 (07:57 +0000)
committerKern Sibbald <kern@sibbald.com>
Thu, 8 May 2003 07:57:02 +0000 (07:57 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@497 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/admin.c [new file with mode: 0644]
bacula/src/lib/bget_msg.c [new file with mode: 0644]

diff --git a/bacula/src/dird/admin.c b/bacula/src/dird/admin.c
new file mode 100644 (file)
index 0000000..0b4f014
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ *
+ *   Bacula Director -- admin.c -- responsible for doing admin jobs
+ *
+ *     Kern Sibbald, May MMIII
+ *
+ *  Basic tasks done here:
+ *     Display the job report.
+ *
+ *   Version $Id$
+ */
+
+/*
+   Copyright (C) 2000-2003 Kern Sibbald and John Walker
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of
+   the License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public
+   License along with this program; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+   MA 02111-1307, USA.
+
+ */
+
+#include "bacula.h"
+#include "dird.h"
+#include "ua.h"
+
+
+/* Forward referenced functions */
+static void admin_cleanup(JCR *jcr, int TermCode);
+
+/* External functions */
+
+/* 
+ *  Returns:  0 on failure
+ *           1 on success
+ */
+int do_admin(JCR *jcr) 
+{
+
+   jcr->jr.JobId = jcr->JobId;
+   jcr->jr.StartTime = jcr->start_time;
+   if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
+      Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
+      goto bail_out;
+   }
+
+   jcr->fname = (char *)get_pool_memory(PM_FNAME);
+
+   /* Print Job Start message */
+   Jmsg(jcr, M_INFO, 0, _("Start Admin JobId %d, Job=%s\n"),
+       jcr->JobId, jcr->Job);
+
+   set_jcr_job_status(jcr, JS_Running);
+   admin_cleanup(jcr, JS_Terminated);
+   return 0;
+    
+bail_out:
+   admin_cleanup(jcr, JS_ErrorTerminated);
+   return 0;
+}
+
+/*
+ * Release resources allocated during backup.
+ */
+static void admin_cleanup(JCR *jcr, int TermCode)
+{
+   char sdt[50], edt[50];
+   char term_code[100];
+   char *term_msg;
+   int msg_type;
+   MEDIA_DBR mr;
+   utime_t RunTime;
+
+   Dmsg0(100, "Enter backup_cleanup()\n");
+   memset(&mr, 0, sizeof(mr));
+   set_jcr_job_status(jcr, TermCode);
+
+   update_job_end_record(jcr);       /* update database */
+   
+   if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
+      Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"), 
+        db_strerror(jcr->db));
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
+   }
+
+   msg_type = M_INFO;                /* by default INFO message */
+   switch (jcr->JobStatus) {
+      case JS_Terminated:
+         term_msg = _("Admin OK");
+        break;
+      case JS_FatalError:
+      case JS_ErrorTerminated:
+         term_msg = _("*** Admin Error ***"); 
+        msg_type = M_ERROR;          /* Generate error message */
+        break;
+      case JS_Canceled:
+         term_msg = _("Admin Canceled");
+        break;
+      default:
+        term_msg = term_code;
+         sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
+        break;
+   }
+   bstrftime(sdt, sizeof(sdt), jcr->jr.StartTime);
+   bstrftime(edt, sizeof(edt), jcr->jr.EndTime);
+   RunTime = jcr->jr.EndTime - jcr->jr.StartTime;
+
+   Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n\
+JobId:                  %d\n\
+Job:                    %s\n\
+Start time:             %s\n\
+End time:               %s\n\
+Termination:            %s\n\n"),
+       edt,
+       jcr->jr.JobId,
+       jcr->jr.Job,
+       sdt,
+       edt,
+       term_msg);
+
+   Dmsg0(100, "Leave admin_cleanup()\n");
+}
diff --git a/bacula/src/lib/bget_msg.c b/bacula/src/lib/bget_msg.c
new file mode 100644 (file)
index 0000000..0e03ebc
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ *  Subroutines to receive network data and handle
+ *   network signals for the FD and the SD.
+ *
+ *   Kern Sibbald, May MMI previously in src/stored/fdmsg.c
+ *
+ *   Version $Id$
+ *                           
+ */
+/*
+   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of
+   the License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public
+   License along with this program; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+   MA 02111-1307, USA.
+
+ */
+
+#include "bacula.h"                   /* pull in global headers */
+
+extern char OK_msg[];
+extern char TERM_msg[];
+
+#define msglvl 200
+
+/*      
+ * This routine does a bnet_recv(), then if a signal was
+ *   sent, it handles it.  The return codes are the same as
+ *   bne_recv() except the BNET_SIGNAL messages that can
+ *   be handled are done so without returning.
+ *
+ * Returns number of bytes read (may return zero)
+ * Returns -1 on signal (BNET_SIGNAL) 
+ * Returns -2 on hard end of file (BNET_HARDEOF)
+ * Returns -3 on error (BNET_ERROR)
+ */
+int bget_msg(BSOCK *sock)
+{
+   int n;
+   for ( ;; ) {
+      n = bnet_recv(sock);
+      if (n >= 0) {                 /* normal return */
+        return n;
+      }  
+      if (is_bnet_stop(sock)) {      /* error return */
+        return n;
+      }
+
+      /* BNET_SIGNAL (-1) return from bnet_recv() => network signal */
+      switch (sock->msglen) {
+      case BNET_EOD:              /* end of data */
+         Dmsg0(msglvl, "Got BNET_EOD\n");
+        return n;
+      case BNET_EOD_POLL:
+         Dmsg0(msglvl, "Got BNET_EOD_POLL\n");
+        if (sock->terminated) {
+           bnet_fsend(sock, TERM_msg);
+        } else {
+           bnet_fsend(sock, OK_msg); /* send response */
+        }
+        return n;                 /* end of data */
+      case BNET_TERMINATE:
+         Dmsg0(msglvl, "Got BNET_TERMINATE\n");
+        sock->terminated = 1;
+        return n;
+      case BNET_POLL:
+         Dmsg0(msglvl, "Got BNET_POLL\n");
+        if (sock->terminated) {
+           bnet_fsend(sock, TERM_msg);
+        } else {
+           bnet_fsend(sock, OK_msg); /* send response */
+        }
+        break;
+      case BNET_HEARTBEAT:
+      case BNET_HB_RESPONSE:
+        break;
+      case BNET_STATUS:
+        /* *****FIXME***** Implement BNET_STATUS */
+         Dmsg0(msglvl, "Got BNET_STATUS\n");
+         bnet_fsend(sock, "Status OK\n");
+        bnet_sig(sock, BNET_EOD);
+        break;
+      default:
+         Emsg1(M_ERROR, 0, "bget_msg: unknown signal %d\n", sock->msglen);
+        break;
+      }
+   }
+}