From c45f734f644c338b700d77eced38ff52f259079c Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Thu, 19 Aug 2004 20:18:50 +0000 Subject: [PATCH] - Add .status [current|last] command to filed and stored git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1546 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/filed/job.c | 4 ++- bacula/src/filed/status.c | 53 ++++++++++++++++++++++++++++++++++++++ bacula/src/stored/dircmd.c | 2 ++ bacula/src/stored/status.c | 53 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 1 deletion(-) diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 84f602dc65..86bdfab4bc 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -34,7 +34,8 @@ extern CLIENT *me; /* our client resource */ /* Imported functions */ extern int status_cmd(JCR *jcr); - +extern int qstatus_cmd(JCR *jcr); + /* Forward referenced functions */ static int backup_cmd(JCR *jcr); static int bootstrap_cmd(JCR *jcr); @@ -85,6 +86,7 @@ static struct s_cmds cmds[] = { {"restore", restore_cmd}, {"session", session_cmd}, {"status", status_cmd}, + {".status", qstatus_cmd}, {"storage ", storage_cmd}, {"verify", verify_cmd}, {"bootstrap", bootstrap_cmd}, diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index 1ff65244cb..557d0c718d 100755 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -38,6 +38,11 @@ static void list_terminated_jobs(void sendit(const char *msg, int len, void *sa 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; @@ -267,6 +272,54 @@ int status_cmd(JCR *jcr) return 1; } +/* + * .status command from Director + */ +int qstatus_cmd(JCR *jcr) +{ + BSOCK *dir = jcr->dir_bsock; + char time[dir->msglen+1]; + JCR *njcr; + s_last_job* job; + + 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); + 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); + return 0; + } + + bnet_sig(dir, BNET_EOD); + return 1; +} /* * Convert Job Level into a string diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 045add3b5a..40c43f1648 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -60,6 +60,7 @@ static char OKsetdebug[] = "3000 OK setdebug=%d\n"; extern void terminate_child(); extern int job_cmd(JCR *jcr); extern int status_cmd(JCR *sjcr); +extern int qstatus_cmd(JCR *jcr); /* Forward referenced functions */ static int label_cmd(JCR *jcr); @@ -95,6 +96,7 @@ static struct s_cmds cmds[] = { {"mount", mount_cmd}, {"unmount", unmount_cmd}, {"status", status_cmd}, + {".status", qstatus_cmd}, {"autochanger", autochanger_cmd}, {"release", release_cmd}, {"readlabel", readlabel_cmd}, diff --git a/bacula/src/stored/status.c b/bacula/src/stored/status.c index d07c43029d..5ae33f1dc0 100644 --- a/bacula/src/stored/status.c +++ b/bacula/src/stored/status.c @@ -41,6 +41,10 @@ extern int num_jobs_run; /* 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"; /* Forward referenced functions */ @@ -414,3 +418,52 @@ static void sendit(const char *msg, int len, void *arg) user->msglen = len+1; bnet_send(user); } + +/* + * .status command from Director + */ +int qstatus_cmd(JCR *jcr) +{ + BSOCK *dir = jcr->dir_bsock; + char time[dir->msglen+1]; + JCR *njcr; + s_last_job* job; + + 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); + 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); + return 0; + } + + bnet_sig(dir, BNET_EOD); + return 1; +} -- 2.39.2