2 * Bacula File Daemon Status routines
4 * Kern Sibbald, August MMI
10 Copyright (C) 2000-2003 Kern Sibbald and John Walker
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of
15 the License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public
23 License along with this program; if not, write to the Free
24 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32 extern char my_name[];
33 extern struct s_last_job last_job;
34 extern time_t daemon_start_time;
37 * General status generator
39 static void do_status(void sendit(char *msg, int len, void *sarg), void *arg)
42 char *msg, b1[32], b2[32], b3[32];
45 char dt[MAX_TIME_LENGTH];
47 msg = (char *)get_pool_memory(PM_MESSAGE);
49 len = Mmsg(&msg, "%s Version: " VERSION " (" DATE ")\n", my_name);
50 sendit(msg, len, arg);
51 bstrftime(dt, sizeof(dt), daemon_start_time);
52 len = Mmsg(&msg, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
53 last_job.NumJobs == 1 ? "" : "s");
54 sendit(msg, len, arg);
55 if (last_job.NumJobs > 0) {
58 bstrftime(dt, sizeof(dt), last_job.end_time);
59 len = Mmsg(&msg, _("Last Job %s finished at %s\n"), last_job.Job, dt);
60 sendit(msg, len, arg);
62 jobstatus_to_ascii(last_job.JobStatus, termstat, sizeof(termstat));
63 len = Mmsg(&msg, _(" Files=%s Bytes=%s Termination Status=%s\n"),
64 edit_uint64_with_commas(last_job.JobFiles, b1),
65 edit_uint64_with_commas(last_job.JobBytes, b2),
67 sendit(msg, len, arg);
70 for (njcr=NULL; (njcr=get_next_jcr(njcr)); ) {
71 bstrftime(dt, sizeof(dt), njcr->start_time);
72 if (njcr->JobId == 0) {
73 len = Mmsg(&msg, _("Director connected at: %s\n"), dt);
75 len = Mmsg(&msg, _("JobId %d Job %s is running.\n"),
76 njcr->JobId, njcr->Job);
77 sendit(msg, len, arg);
78 len = Mmsg(&msg, _(" %s Job started: %s\n"),
79 job_type_to_str(njcr->JobType), dt);
81 sendit(msg, len, arg);
82 if (njcr->JobId == 0) {
83 free_locked_jcr(njcr);
86 sec = time(NULL) - njcr->start_time;
90 bps = njcr->JobBytes / sec;
91 len = Mmsg(&msg, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
92 edit_uint64_with_commas(njcr->JobFiles, b1),
93 edit_uint64_with_commas(njcr->JobBytes, b2),
94 edit_uint64_with_commas(bps, b3));
95 sendit(msg, len, arg);
96 len = Mmsg(&msg, _(" Files Examined=%s\n"),
97 edit_uint64_with_commas(njcr->num_files_examined, b1));
98 sendit(msg, len, arg);
99 if (njcr->JobFiles > 0) {
101 len = Mmsg(&msg, _(" Processing file: %s\n"), njcr->last_fname);
103 sendit(msg, len, arg);
107 if (njcr->store_bsock) {
108 len = Mmsg(&msg, " SDReadSeqNo=%" lld " fd=%d\n",
109 njcr->store_bsock->read_seqno, njcr->store_bsock->fd);
110 sendit(msg, len, arg);
112 len = Mmsg(&msg, _(" SDSocket closed.\n"));
113 sendit(msg, len, arg);
115 free_locked_jcr(njcr);
119 len = Mmsg(&msg, _("No jobs running.\n"));
120 sendit(msg, len, arg);
122 free_pool_memory(msg);
128 static void sendit(char *msg, int len, void *arg)
130 BSOCK *user = (BSOCK *)arg;
132 memcpy(user->msg, msg, len+1);
133 user->msglen = len+1;
138 * Status command from Director
140 int status_cmd(JCR *jcr)
142 BSOCK *user = jcr->dir_bsock;
144 bnet_fsend(user, "\n");
145 do_status(sendit, (void *)user);
146 bnet_fsend(user, "====\n");
148 bnet_sig(user, BNET_EOD);
156 static char buf[100];
165 * Put message in Window List Box
167 static void win32_sendit(char *msg, int len, void *marg)
169 struct s_win32_arg *arg = (struct s_win32_arg *)marg;
172 msg[len-1] = 0; /* eliminate newline */
174 SendDlgItemMessage(arg->hwnd, arg->idlist, LB_ADDSTRING, 0, (LONG)msg);
178 void FillStatusBox(HWND hwnd, int idlist)
180 struct s_win32_arg arg;
186 for ( ; SendDlgItemMessage(hwnd, idlist, LB_DELETESTRING, 0, (LONG)0) > 0; )
188 do_status(win32_sendit, (void *)&arg);
191 char *bac_status(int stat)
194 char *termstat = _("Bacula Idle");
197 if (last_job.NumJobs > 0) {
198 switch (last_job.JobStatus) {
199 case JS_ErrorTerminated:
201 termstat = _("Last Job Erred");
208 for (njcr=NULL; (njcr=get_next_jcr(njcr)); ) {
209 if (njcr->JobId != 0) {
211 termstat = _("Bacula Running");
212 free_locked_jcr(njcr);
215 free_locked_jcr(njcr);
218 strcpy(buf, termstat);
222 #endif /* HAVE_CYGWIN */