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;
41 * General status generator
43 static void do_status(void sendit(char *msg, int len, void *sarg), void *arg)
46 char *msg, b1[32], b2[32], b3[32];
49 char dt[MAX_TIME_LENGTH];
51 msg = (char *)get_pool_memory(PM_MESSAGE);
53 len = Mmsg(&msg, "%s Version: " VERSION " (" BDATE ")\n", my_name);
54 sendit(msg, len, arg);
55 bstrftime(dt, sizeof(dt), daemon_start_time);
56 len = Mmsg(&msg, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
57 last_job.NumJobs == 1 ? "" : "s");
58 sendit(msg, len, arg);
61 privs = get_backup_privileges(NULL, 1);
64 _("Priv 0x%x APIs=%sOPT,%sATP,%sLPV,%sGFAE,%sBR,%sBW,%sSPSP\n"), privs,
65 p_OpenProcessToken?"":"!",
66 p_AdjustTokenPrivileges?"":"!",
67 p_LookupPrivilegeValue?"":"!",
68 p_GetFileAttributesEx?"":"!",
71 p_SetProcessShutdownParameters?"":"!");
72 sendit(msg, len, arg);
75 if (last_job.NumJobs > 0) {
78 bstrftime(dt, sizeof(dt), last_job.end_time);
79 len = Mmsg(&msg, _("Last Job %s finished at %s\n"), last_job.Job, dt);
80 sendit(msg, len, arg);
82 jobstatus_to_ascii(last_job.JobStatus, termstat, sizeof(termstat));
83 len = Mmsg(&msg, _(" Files=%s Bytes=%s Termination Status=%s\n"),
84 edit_uint64_with_commas(last_job.JobFiles, b1),
85 edit_uint64_with_commas(last_job.JobBytes, b2),
87 sendit(msg, len, arg);
89 Dmsg0(200, "Begin status jcr loop.\n");
91 for (njcr=NULL; (njcr=get_next_jcr(njcr)); ) {
92 bstrftime(dt, sizeof(dt), njcr->start_time);
93 if (njcr->JobId == 0) {
94 len = Mmsg(&msg, _("Director connected at: %s\n"), dt);
96 len = Mmsg(&msg, _("JobId %d Job %s is running.\n"),
97 njcr->JobId, njcr->Job);
98 sendit(msg, len, arg);
99 len = Mmsg(&msg, _(" %s Job started: %s\n"),
100 job_type_to_str(njcr->JobType), dt);
102 sendit(msg, len, arg);
103 if (njcr->JobId == 0) {
104 free_locked_jcr(njcr);
107 sec = time(NULL) - njcr->start_time;
111 bps = njcr->JobBytes / sec;
112 len = Mmsg(&msg, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
113 edit_uint64_with_commas(njcr->JobFiles, b1),
114 edit_uint64_with_commas(njcr->JobBytes, b2),
115 edit_uint64_with_commas(bps, b3));
116 sendit(msg, len, arg);
117 len = Mmsg(&msg, _(" Files Examined=%s\n"),
118 edit_uint64_with_commas(njcr->num_files_examined, b1));
119 sendit(msg, len, arg);
120 if (njcr->JobFiles > 0) {
122 len = Mmsg(&msg, _(" Processing file: %s\n"), njcr->last_fname);
124 sendit(msg, len, arg);
128 if (njcr->store_bsock) {
129 len = Mmsg(&msg, " SDReadSeqNo=%" lld " fd=%d\n",
130 njcr->store_bsock->read_seqno, njcr->store_bsock->fd);
131 sendit(msg, len, arg);
133 len = Mmsg(&msg, _(" SDSocket closed.\n"));
134 sendit(msg, len, arg);
136 free_locked_jcr(njcr);
139 Dmsg0(200, "Begin status jcr loop.\n");
141 len = Mmsg(&msg, _("No jobs running.\n"));
142 sendit(msg, len, arg);
144 free_pool_memory(msg);
150 static void sendit(char *msg, int len, void *arg)
152 BSOCK *user = (BSOCK *)arg;
154 memcpy(user->msg, msg, len+1);
155 user->msglen = len+1;
160 * Status command from Director
162 int status_cmd(JCR *jcr)
164 BSOCK *user = jcr->dir_bsock;
166 bnet_fsend(user, "\n");
167 do_status(sendit, (void *)user);
168 bnet_fsend(user, "====\n");
170 bnet_sig(user, BNET_EOD);
178 static char buf[100];
187 * Put message in Window List Box
189 static void win32_sendit(char *msg, int len, void *marg)
191 struct s_win32_arg *arg = (struct s_win32_arg *)marg;
194 msg[len-1] = 0; /* eliminate newline */
196 SendDlgItemMessage(arg->hwnd, arg->idlist, LB_ADDSTRING, 0, (LONG)msg);
200 void FillStatusBox(HWND hwnd, int idlist)
202 struct s_win32_arg arg;
208 for ( ; SendDlgItemMessage(hwnd, idlist, LB_DELETESTRING, 0, (LONG)0) > 0; )
210 do_status(win32_sendit, (void *)&arg);
213 char *bac_status(int stat)
216 char *termstat = _("Bacula Idle");
219 if (last_job.NumJobs > 0) {
220 switch (last_job.JobStatus) {
221 case JS_ErrorTerminated:
223 termstat = _("Last Job Erred");
229 Dmsg0(200, "Begin bac_status jcr loop.\n");
231 for (njcr=NULL; (njcr=get_next_jcr(njcr)); ) {
232 if (njcr->JobId != 0) {
234 termstat = _("Bacula Running");
235 free_locked_jcr(njcr);
238 free_locked_jcr(njcr);
241 Dmsg0(200, "End bac_status jcr loop.\n");
242 strcpy(buf, termstat);
246 #endif /* HAVE_CYGWIN */