]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/status.c
Remove broken run when code
[bacula/bacula] / bacula / src / stored / status.c
index b21d277911d1ddc8ebd1a47bd092e45b80832af4..00ebed2fd7913092a31d10ceda8763e0a9d9ddfc 100644 (file)
@@ -1,3 +1,30 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2003-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.
+
+   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., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 /*
  *  This file handles the status command
  *
@@ -6,20 +33,6 @@
  *   Version $Id$
  *
  */
-/*
-   Copyright (C) 2003-2006 Kern Sibbald
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
-
-   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 
-   the file LICENSE for additional details.
-
- */
 
 #include "bacula.h"
 #include "stored.h"
@@ -30,6 +43,7 @@
 extern BSOCK *filed_chan;
 extern int r_first, r_last;
 extern struct s_res resources[];
+extern void *start_heap;
 
 /* Static variables */
 static char qstatus[] = ".status %127s\n";
@@ -43,26 +57,24 @@ static void send_blocked_status(DEVICE *dev, void sendit(const char *msg, int le
 static void list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg);
 static void list_running_jobs(void sendit(const char *msg, int len, void *sarg), void *arg);
 static void list_jobs_waiting_on_reservation(void sendit(const char *msg, int len, void *sarg), void *arg);
-#if defined(HAVE_WIN32)
-static void win32_sendit(const char *msg, int len, void *arg);
-#endif
 
 static const char *level_to_str(int level);
 
 /*
  * Status command from Director
  */
-bool do_status(void sendit(const char *msg, int len, void *sarg), void *arg)
+void output_status(void sendit(const char *msg, int len, void *sarg), void *arg)
 {
    DEVRES *device;
    AUTOCHANGER *changer;
    DEVICE *dev;
    char dt[MAX_TIME_LENGTH];
-   char *msg, b1[35], b2[35], b3[35], b4[35];
+   char b1[35], b2[35], b3[35], b4[35], b5[35];
+   POOLMEM *msg;
    int bpb;
    int len;
 
-   msg = (char *)get_pool_memory(PM_MESSAGE);
+   msg = get_pool_memory(PM_MESSAGE);
 
    len = Mmsg(msg, _("%s Version: %s (%s) %s %s %s\n"), 
               my_name, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
@@ -75,11 +87,12 @@ bool do_status(void sendit(const char *msg, int len, void *sarg), void *arg)
         dt, num_jobs_run, num_jobs_run == 1 ? "" : "s");
    sendit(msg, len, arg);
 
-   len = Mmsg(msg, _(" Heap: bytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
-         edit_uint64_with_commas(sm_bytes, b1),
-         edit_uint64_with_commas(sm_max_bytes, b2),
-         edit_uint64_with_commas(sm_buffers, b3),
-         edit_uint64_with_commas(sm_max_buffers, b4));
+   len = Mmsg(msg, _(" Heap: heap=%s smbytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
+         edit_uint64_with_commas((char *)sbrk(0)-(char *)start_heap, b1),
+         edit_uint64_with_commas(sm_bytes, b2),
+         edit_uint64_with_commas(sm_max_bytes, b3),
+         edit_uint64_with_commas(sm_buffers, b4),
+         edit_uint64_with_commas(sm_max_buffers, b5));
    sendit(msg, len, arg);
 
    /*
@@ -127,7 +140,7 @@ bool do_status(void sendit(const char *msg, int len, void *sarg), void *arg)
                dev->pool_name[0]?dev->pool_name:"*unknown*");
             sendit(msg, len, arg);
          } else {
-            len = Mmsg(msg, _("Device %s open but no Bacula volume is mounted.\n"), 
+            len = Mmsg(msg, _("Device %s open but no Bacula volume is currently mounted.\n"), 
                dev->print_name());
             sendit(msg, len, arg);
          }
@@ -168,21 +181,19 @@ bool do_status(void sendit(const char *msg, int len, void *sarg), void *arg)
          if (dev) {
             len = Mmsg(msg, _("Device %s is not open.\n"), dev->print_name());
             sendit(msg, len, arg);
+            send_blocked_status(dev, sendit, arg);
         } else {
             len = Mmsg(msg, _("Device \"%s\" is not open or does not exist.\n"), device->hdr.name);
             sendit(msg, len, arg);
          }
-         send_blocked_status(dev, sendit, arg);
       }
    }
-   len = Mmsg(msg, _("====\n\n"));
-   sendit(msg, len, arg);
+   sendit("====\n\n", 6, arg);
    len = Mmsg(msg, _("In Use Volume status:\n"));
    sendit(msg, len, arg);
    list_volumes(sendit, arg);
-   len = Mmsg(msg, _("====\n\n"));
-   sendit(msg, len, arg);
-       
+   sendit("====\n\n", 6, arg);
+
 #ifdef xxx
    if (debug_level > 10) {
       bnet_fsend(user, _("====\n\n"));
@@ -194,7 +205,6 @@ bool do_status(void sendit(const char *msg, int len, void *sarg), void *arg)
    list_spool_stats(sendit, arg);
 
    free_pool_memory(msg);
-   return true;
 }
 
 static void send_blocked_status(DEVICE *dev, void sendit(const char *msg, int len, void *sarg), void *arg)
@@ -210,7 +220,7 @@ static void send_blocked_status(DEVICE *dev, void sendit(const char *msg, int le
       free_pool_memory(msg);
       return;
    }
-   switch (dev->dev_blocked) {
+   switch (dev->blocked()) {
    case BST_UNMOUNTED:
       len = Mmsg(msg, _("    Device is BLOCKED. User unmounted.\n"));
       sendit(msg, len, arg);
@@ -256,13 +266,16 @@ static void send_blocked_status(DEVICE *dev, void sendit(const char *msg, int le
    }
    /* Send autochanger slot status */
    if (dev->is_autochanger()) {
-      if (dev->Slot) {
+      if (dev->Slot > 0) {
          len = Mmsg(msg, _("    Slot %d is loaded in drive %d.\n"), 
             dev->Slot, dev->drive_index);
          sendit(msg, len, arg);
-      } else {
+      } else if (dev->Slot == 0) {
          len = Mmsg(msg, _("    Drive %d is not loaded.\n"), dev->drive_index);
          sendit(msg, len, arg);
+      } else {
+         len = Mmsg(msg, _("    Drive %d status unknown.\n"), dev->drive_index);
+         sendit(msg, len, arg);
       }
    }
    if (debug_level > 1) {
@@ -302,7 +315,7 @@ static void send_blocked_status(DEVICE *dev, void sendit(const char *msg, int le
          dev->state & ST_MOUNTED ? "" : "!");
       sendit(msg, len, arg);
 
-      len = Mmsg(msg, _("num_writers=%d block=%d\n\n"), dev->num_writers, dev->dev_blocked);
+      len = Mmsg(msg, _("num_writers=%d block=%d\n\n"), dev->num_writers, dev->blocked());
       sendit(msg, len, arg);
 
       len = Mmsg(msg, _("Device parameters:\n"));
@@ -356,7 +369,7 @@ static void list_running_jobs(void sendit(const char *msg, int len, void *sarg),
          }
          if (rdcr && rdcr->device) {
             len = Mmsg(msg, _("Reading: %s %s job %s JobId=%d Volume=\"%s\"\n"
-                            "    pool=\"%s\" device=\"%s\"\n"),
+                            "    pool=\"%s\" device=%s\n"),
                    job_level_to_str(jcr->JobLevel),
                    job_type_to_str(jcr->JobType),
                    JobName,
@@ -369,7 +382,7 @@ static void list_running_jobs(void sendit(const char *msg, int len, void *sarg),
          }
          if (dcr && dcr->device) {
             len = Mmsg(msg, _("Writing: %s %s job %s JobId=%d Volume=\"%s\"\n"
-                            "    pool=\"%s\" device=\"%s\"\n"),
+                            "    pool=\"%s\" device=%s\n"),
                    job_level_to_str(jcr->JobLevel),
                    job_type_to_str(jcr->JobType),
                    JobName,
@@ -379,6 +392,9 @@ static void list_running_jobs(void sendit(const char *msg, int len, void *sarg),
                    dcr->dev?dcr->dev->print_name(): 
                             dcr->device->device_name);
             sendit(msg, len, arg);
+            len= Mmsg(msg, _("    spooling=%d despooling=%d despool_wait=%d\n"),
+                   dcr->spooling, dcr->despooling, dcr->despool_wait);
+            sendit(msg, len, arg);
          }
          sec = time(NULL) - jcr->run_time;
          if (sec <= 0) {
@@ -411,8 +427,7 @@ static void list_running_jobs(void sendit(const char *msg, int len, void *sarg),
       len = Mmsg(msg, _("No Jobs running.\n"));
       sendit(msg, len, arg);
    }
-   len = Mmsg(msg, _("====\n"));
-   sendit(msg, len, arg);
+   sendit("====\n", 5, arg);
 
    free_pool_memory(msg);
 }
@@ -433,8 +448,7 @@ static void list_jobs_waiting_on_reservation(void sendit(const char *msg, int le
    }
    endeach_jcr(jcr);
 
-   msg = _("====\n");
-   sendit(msg, strlen(msg), arg);
+   sendit("====\n", 5, arg);
 }
 
 
@@ -445,14 +459,13 @@ static void list_terminated_jobs(void sendit(const char *msg, int len, void *sar
    struct s_last_job *je;
    const char *msg;
 
+   msg =  _("\nTerminated Jobs:\n");
+   sendit(msg, strlen(msg), arg);
    if (last_jobs->size() == 0) {
-      msg = _("No Terminated Jobs.\n");
-      sendit(msg, strlen(msg), arg);
+      sendit("====\n", 5, arg);
       return;
    }
    lock_last_jobs_list();
-   msg =  _("\nTerminated Jobs:\n");
-   sendit(msg, strlen(msg), arg);
    msg =  _(" JobId  Level    Files      Bytes   Status   Finished        Name \n");
    sendit(msg, strlen(msg), arg);
    msg =  _("===================================================================\n");
@@ -511,8 +524,8 @@ static void list_terminated_jobs(void sendit(const char *msg, int len, void *sar
          dt, JobName);
       sendit(buf, strlen(buf), arg);
    }
-   sendit(_("====\n"), 5, arg);
    unlock_last_jobs_list();
+   sendit("====\n", 5, arg);
 }
 
 /*
@@ -582,7 +595,7 @@ bool status_cmd(JCR *jcr)
    BSOCK *user = jcr->dir_bsock;
 
    bnet_fsend(user, "\n");
-   do_status(bsock_sendit, (void *)user);
+   output_status(bsock_sendit, (void *)user);
 
    bnet_sig(user, BNET_EOD);
    return 1;
@@ -635,46 +648,10 @@ bool qstatus_cmd(JCR *jcr)
 #if defined(HAVE_WIN32)
 int bacstat = 0;
 
-struct s_win32_arg {
-   HWND hwnd;
-   int idlist;
-};
-
-/*
- * Put message in Window List Box
- */
-static void win32_sendit(const char *msg, int len, void *marg)
-{
-   struct s_win32_arg *arg = (struct s_win32_arg *)marg;
-
-   if (len > 0 && msg[len-1] == '\n') {
-       // when compiling with visual studio some strings are read-only
-       // and cause access violations.  So we creat a tmp copy.
-       char *_msg = (char *)alloca(len);
-       bstrncpy(_msg, msg, len);
-       msg = _msg;
-   }
-   SendDlgItemMessage(arg->hwnd, arg->idlist, LB_ADDSTRING, 0, (LONG)msg);
-
-}
-
-void FillStatusBox(HWND hwnd, int idlist)
-{
-   struct s_win32_arg arg;
-
-   arg.hwnd = hwnd;
-   arg.idlist = idlist;
-
-   /* Empty box */
-   for ( ; SendDlgItemMessage(hwnd, idlist, LB_DELETESTRING, 0, (LONG)0) > 0; )
-      { }
-   do_status(win32_sendit, (void *)&arg);
-}
-
 char *bac_status(char *buf, int buf_len)
 {
    JCR *njcr;
-   const char *termstat = _("Bacula Idle");
+   const char *termstat = _("Bacula Storage: Idle");
    struct s_last_job *job;
    int stat = 0;                      /* Idle */
 
@@ -685,7 +662,7 @@ char *bac_status(char *buf, int buf_len)
    foreach_jcr(njcr) {
       if (njcr->JobId != 0) {
          stat = JS_Running;
-         termstat = _("Bacula Running");
+         termstat = _("Bacula Storage: Running");
          break;
       }
    }
@@ -699,15 +676,15 @@ char *bac_status(char *buf, int buf_len)
       stat = job->JobStatus;
       switch (job->JobStatus) {
       case JS_Canceled:
-         termstat = _("Last Job Canceled");
+         termstat = _("Bacula Storage: Last Job Canceled");
          break;
       case JS_ErrorTerminated:
       case JS_FatalError:
-         termstat = _("Last Job Failed");
+         termstat = _("Bacula Storage: Last Job Failed");
          break;
       default:
          if (job->Errors) {
-            termstat = _("Last Job had Warnings");
+            termstat = _("Bacula Storage: Last Job had Warnings");
          }
          break;
       }