]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/status.c
- Add a kludge to detect bad date/times, which cause a seg fault in
[bacula/bacula] / bacula / src / filed / status.c
index 1ff65244cb9f1671b1fdc60bf4fcca1c7ff78015..3ca00fe8bceee4d0c7e714a9f89b66a0d703a5ff 100755 (executable)
 extern char my_name[];
 extern int num_jobs_run;
 extern time_t daemon_start_time;
+extern bool get_trace(void);
 
 /* Forward referenced functions */
 static void  list_terminated_jobs(void sendit(const char *msg, int len, void *sarg), void *arg);
 static void bsock_sendit(const char *msg, int len, void *arg);
 static const char *level_to_str(int level);
 
+/* Static variables */
+static char qstatus[] = ".status %s\n";
+
+static char OKqstatus[]   = "2000 OK .status\n";
+static char DotStatusJob[] = "JobId=%d JobStatus=%c JobErrors=%d\n";
 
 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
 static int privs = 0;
@@ -86,11 +92,9 @@ static void do_status(void sendit(const char *msg, int len, void *sarg), void *a
            edit_uint64_with_commas(sm_max_bytes, b2),
            edit_uint64_with_commas(sm_buffers, b3),
            edit_uint64_with_commas(sm_max_buffers, b4));
-       sendit(msg, len, arg);
-    }
-   if (debug_level > 0) {
-      len = Mmsg(msg, _(" Sizeof: off_t=%d size_t=%d\n"), sizeof(off_t),
-           sizeof(size_t));
+      sendit(msg, len, arg);
+      len = Mmsg(msg, _(" Sizeof: off_t=%d size_t=%d debug=%d trace=%d\n"), 
+           sizeof(off_t), sizeof(size_t), debug_level, get_trace());
       sendit(msg, len, arg);
    }
 
@@ -267,6 +271,59 @@ int status_cmd(JCR *jcr)
    return 1;
 }
 
+/*
+ * .status command from Director
+ */
+int qstatus_cmd(JCR *jcr)
+{
+   BSOCK *dir = jcr->dir_bsock;
+   POOLMEM *time;
+   JCR *njcr;
+   s_last_job* job;
+
+   time = get_memory(dir->msglen+1);
+   
+   if (sscanf(dir->msg, qstatus, time) != 1) {
+      pm_strcpy(&jcr->errmsg, dir->msg);
+      Jmsg1(jcr, M_FATAL, 0, _("Bad .status command: %s\n"), jcr->errmsg);
+      bnet_fsend(dir, "2900 Bad .status command, missing argument.\n");
+      bnet_sig(dir, BNET_EOD);
+      free_memory(time);
+      return 0;
+   }
+   unbash_spaces(time);
+   
+   if (strcmp(time, "current") == 0) {
+      bnet_fsend(dir, OKqstatus, time);
+      lock_jcr_chain();
+      foreach_jcr(njcr) {
+        if (njcr->JobId != 0) {
+           bnet_fsend(dir, DotStatusJob, njcr->JobId, njcr->JobStatus, njcr->JobErrors);
+        }
+        free_locked_jcr(njcr);
+      }
+      unlock_jcr_chain();
+   }
+   else if (strcmp(time, "last") == 0) {
+      bnet_fsend(dir, OKqstatus, time);
+      if ((last_jobs) && (last_jobs->size() > 0)) {
+        job = (s_last_job*)last_jobs->last();
+        bnet_fsend(dir, DotStatusJob, job->JobId, job->JobStatus, job->Errors);
+      }
+   }
+   else {
+      pm_strcpy(&jcr->errmsg, dir->msg);
+      Jmsg1(jcr, M_FATAL, 0, _("Bad .status command: %s\n"), jcr->errmsg);
+      bnet_fsend(dir, "2900 Bad .status command, wrong argument.\n");
+      bnet_sig(dir, BNET_EOD);
+      free_memory(time);
+      return 0;
+   }
+   
+   bnet_sig(dir, BNET_EOD);
+   free_memory(time);
+   return 1;
+}
 
 /*
  * Convert Job Level into a string