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 ") %s %s %s\n", my_name,
54 HOST_OS, DISTNAME, DISTVER);
55 sendit(msg, len, arg);
56 bstrftime(dt, sizeof(dt), daemon_start_time);
57 len = Mmsg(&msg, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
58 last_job.NumJobs == 1 ? "" : "s");
59 sendit(msg, len, arg);
62 privs = enable_backup_privileges(NULL, 1);
65 _("Priv 0x%x APIs=%sOPT,%sATP,%sLPV,%sGFAE,%sBR,%sBW,%sSPSP\n"), privs,
66 p_OpenProcessToken?"":"!",
67 p_AdjustTokenPrivileges?"":"!",
68 p_LookupPrivilegeValue?"":"!",
69 p_GetFileAttributesEx?"":"!",
72 p_SetProcessShutdownParameters?"":"!");
73 sendit(msg, len, arg);
76 if (last_job.NumJobs > 0) {
79 bstrftime(dt, sizeof(dt), last_job.end_time);
80 len = Mmsg(&msg, _("Last Job %s finished at %s\n"), last_job.Job, dt);
81 sendit(msg, len, arg);
83 jobstatus_to_ascii(last_job.JobStatus, termstat, sizeof(termstat));
84 len = Mmsg(&msg, _(" Files=%s Bytes=%s Termination Status=%s\n"),
85 edit_uint64_with_commas(last_job.JobFiles, b1),
86 edit_uint64_with_commas(last_job.JobBytes, b2),
88 sendit(msg, len, arg);
90 Dmsg0(200, "Begin status jcr loop.\n");
92 for (njcr=NULL; (njcr=get_next_jcr(njcr)); ) {
93 bstrftime(dt, sizeof(dt), njcr->start_time);
94 if (njcr->JobId == 0) {
95 len = Mmsg(&msg, _("Director connected at: %s\n"), dt);
97 len = Mmsg(&msg, _("JobId %d Job %s is running.\n"),
98 njcr->JobId, njcr->Job);
99 sendit(msg, len, arg);
100 len = Mmsg(&msg, _(" %s Job started: %s\n"),
101 job_type_to_str(njcr->JobType), dt);
103 sendit(msg, len, arg);
104 if (njcr->JobId == 0) {
105 free_locked_jcr(njcr);
108 sec = time(NULL) - njcr->start_time;
112 bps = njcr->JobBytes / sec;
113 len = Mmsg(&msg, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
114 edit_uint64_with_commas(njcr->JobFiles, b1),
115 edit_uint64_with_commas(njcr->JobBytes, b2),
116 edit_uint64_with_commas(bps, b3));
117 sendit(msg, len, arg);
118 len = Mmsg(&msg, _(" Files Examined=%s\n"),
119 edit_uint64_with_commas(njcr->num_files_examined, b1));
120 sendit(msg, len, arg);
121 if (njcr->JobFiles > 0) {
123 len = Mmsg(&msg, _(" Processing file: %s\n"), njcr->last_fname);
125 sendit(msg, len, arg);
129 if (njcr->store_bsock) {
130 len = Mmsg(&msg, " SDReadSeqNo=%" lld " fd=%d\n",
131 njcr->store_bsock->read_seqno, njcr->store_bsock->fd);
132 sendit(msg, len, arg);
134 len = Mmsg(&msg, _(" SDSocket closed.\n"));
135 sendit(msg, len, arg);
137 free_locked_jcr(njcr);
140 Dmsg0(200, "Begin status jcr loop.\n");
142 len = Mmsg(&msg, _("No jobs running.\n"));
143 sendit(msg, len, arg);
145 free_pool_memory(msg);
151 static void sendit(char *msg, int len, void *arg)
153 BSOCK *user = (BSOCK *)arg;
155 memcpy(user->msg, msg, len+1);
156 user->msglen = len+1;
161 * Status command from Director
163 int status_cmd(JCR *jcr)
165 BSOCK *user = jcr->dir_bsock;
167 bnet_fsend(user, "\n");
168 do_status(sendit, (void *)user);
169 bnet_fsend(user, "====\n");
171 bnet_sig(user, BNET_EOD);
179 static char buf[100];
188 * Put message in Window List Box
190 static void win32_sendit(char *msg, int len, void *marg)
192 struct s_win32_arg *arg = (struct s_win32_arg *)marg;
195 msg[len-1] = 0; /* eliminate newline */
197 SendDlgItemMessage(arg->hwnd, arg->idlist, LB_ADDSTRING, 0, (LONG)msg);
201 void FillStatusBox(HWND hwnd, int idlist)
203 struct s_win32_arg arg;
209 for ( ; SendDlgItemMessage(hwnd, idlist, LB_DELETESTRING, 0, (LONG)0) > 0; )
211 do_status(win32_sendit, (void *)&arg);
214 char *bac_status(int stat)
217 char *termstat = _("Bacula Idle");
220 if (last_job.NumJobs > 0) {
221 switch (last_job.JobStatus) {
222 case JS_ErrorTerminated:
224 termstat = _("Last Job Erred");
230 Dmsg0(200, "Begin bac_status jcr loop.\n");
232 for (njcr=NULL; (njcr=get_next_jcr(njcr)); ) {
233 if (njcr->JobId != 0) {
235 termstat = _("Bacula Running");
236 free_locked_jcr(njcr);
239 free_locked_jcr(njcr);
242 Dmsg0(200, "End bac_status jcr loop.\n");
243 strcpy(buf, termstat);
247 #endif /* HAVE_CYGWIN */