2 * Bacula File Daemon Job processing
4 * Kern Sibbald, October MM
10 Copyright (C) 2000-2005 Kern Sibbald
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 version 2 as amended with additional clauses defined in the
15 file LICENSE in the main source directory.
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
20 the file LICENSE for additional details.
28 static pthread_mutex_t vss_mutex = PTHREAD_MUTEX_INITIALIZER;
31 extern char my_name[];
32 extern CLIENT *me; /* our client resource */
34 int enable_vss = 0; /* set to use vss */
36 /* Imported functions */
37 extern int status_cmd(JCR *jcr);
38 extern int qstatus_cmd(JCR *jcr);
40 /* Forward referenced functions */
41 static int backup_cmd(JCR *jcr);
42 static int bootstrap_cmd(JCR *jcr);
43 static int cancel_cmd(JCR *jcr);
44 static int setdebug_cmd(JCR *jcr);
45 static int estimate_cmd(JCR *jcr);
46 static int hello_cmd(JCR *jcr);
47 static int job_cmd(JCR *jcr);
48 static int fileset_cmd(JCR *jcr);
49 static int level_cmd(JCR *jcr);
50 static int verify_cmd(JCR *jcr);
51 static int restore_cmd(JCR *jcr);
52 static int storage_cmd(JCR *jcr);
53 static int session_cmd(JCR *jcr);
54 static int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd);
55 static void filed_free_jcr(JCR *jcr);
56 static int open_sd_read_session(JCR *jcr);
57 static int send_bootstrap_file(JCR *jcr);
58 static int runbefore_cmd(JCR *jcr);
59 static int runafter_cmd(JCR *jcr);
60 static bool run_cmd(JCR *jcr, char *cmd, const char *name);
61 static void set_options(findFOPTS *fo, const char *opts);
64 /* Exported functions */
69 int monitoraccess; /* specify if monitors have access to this function */
73 * The following are the recognized commands from the Director.
75 static struct s_cmds cmds[] = {
76 {"backup", backup_cmd, 0},
77 {"cancel", cancel_cmd, 0},
78 {"setdebug=", setdebug_cmd, 0},
79 {"estimate", estimate_cmd, 0},
80 {"Hello", hello_cmd, 1},
81 {"fileset", fileset_cmd, 0},
82 {"JobId=", job_cmd, 0},
83 {"level = ", level_cmd, 0},
84 {"restore", restore_cmd, 0},
85 {"session", session_cmd, 0},
86 {"status", status_cmd, 1},
87 {".status", qstatus_cmd, 1},
88 {"storage ", storage_cmd, 0},
89 {"verify", verify_cmd, 0},
90 {"bootstrap", bootstrap_cmd, 0},
91 {"RunBeforeJob", runbefore_cmd, 0},
92 {"RunAfterJob", runafter_cmd, 0},
93 {NULL, NULL} /* list terminator */
96 /* Commands received from director that need scanning */
97 static char jobcmd[] = "JobId=%d Job=%127s SDid=%d SDtime=%d Authorization=%100s";
98 static char storaddr[] = "storage address=%s port=%d ssl=%d\n";
99 static char sessioncmd[] = "session %127s %ld %ld %ld %ld %ld %ld\n";
100 static char restorecmd[] = "restore replace=%c prelinks=%d where=%s\n";
101 static char restorecmd1[] = "restore replace=%c prelinks=%d where=\n";
102 static char verifycmd[] = "verify level=%30s\n";
103 static char estimatecmd[] = "estimate listing=%d\n";
104 static char runbefore[] = "RunBeforeJob %s\n";
105 static char runafter[] = "RunAfterJob %s\n";
107 /* Responses sent to Director */
108 static char errmsg[] = "2999 Invalid command\n";
109 static char no_auth[] = "2998 No Authorization\n";
110 static char illegal_cmd[] = "2997 Illegal command for a Director with Monitor directive enabled\n";
111 static char OKinc[] = "2000 OK include\n";
112 static char OKest[] = "2000 OK estimate files=%u bytes=%s\n";
113 static char OKlevel[] = "2000 OK level\n";
114 static char OKbackup[] = "2000 OK backup\n";
115 static char OKbootstrap[] = "2000 OK bootstrap\n";
116 static char OKverify[] = "2000 OK verify\n";
117 static char OKrestore[] = "2000 OK restore\n";
118 static char OKsession[] = "2000 OK session\n";
119 static char OKstore[] = "2000 OK storage\n";
120 static char OKjob[] = "2000 OK Job %s,%s,%s";
121 static char OKsetdebug[] = "2000 OK setdebug=%d\n";
122 static char BADjob[] = "2901 Bad Job\n";
123 static char EndJob[] = "2800 End Job TermCode=%d JobFiles=%u ReadBytes=%s JobBytes=%s Errors=%u\n";
124 static char OKRunBefore[] = "2000 OK RunBefore\n";
125 static char OKRunAfter[] = "2000 OK RunAfter\n";
127 /* Responses received from Storage Daemon */
128 static char OK_end[] = "3000 OK end\n";
129 static char OK_close[] = "3000 OK close Status = %d\n";
130 static char OK_open[] = "3000 OK open ticket = %d\n";
131 static char OK_data[] = "3000 OK data\n";
132 static char OK_append[] = "3000 OK append data\n";
133 static char OKSDbootstrap[] = "3000 OK bootstrap\n";
136 /* Commands sent to Storage Daemon */
137 static char append_open[] = "append open session\n";
138 static char append_data[] = "append data %d\n";
139 static char append_end[] = "append end session %d\n";
140 static char append_close[] = "append close session %d\n";
141 static char read_open[] = "read open session = %s %ld %ld %ld %ld %ld %ld\n";
142 static char read_data[] = "read data %d\n";
143 static char read_close[] = "read close session %d\n";
146 * Accept requests from a Director
148 * NOTE! We are running as a separate thread
150 * Send output one line
151 * at a time followed by a zero length transmission.
153 * Return when the connection is terminated or there
156 * Basic task here is:
157 * Authenticate Director (during Hello command).
158 * Accept commands one at a time from the Director
162 void *handle_client_request(void *dirp)
167 BSOCK *dir = (BSOCK *)dirp;
169 jcr = new_jcr(sizeof(JCR), filed_free_jcr); /* create JCR */
170 jcr->dir_bsock = dir;
171 jcr->ff = init_find_files();
172 jcr->start_time = time(NULL);
173 jcr->last_fname = get_pool_memory(PM_FNAME);
174 jcr->last_fname[0] = 0;
175 jcr->client_name = get_memory(strlen(my_name) + 1);
176 pm_strcpy(jcr->client_name, my_name);
178 enable_backup_privileges(NULL, 1 /* ignore_errors */);
180 /**********FIXME******* add command handler error code */
182 for (quit=false; !quit;) {
185 if (bnet_recv(dir) < 0) {
186 break; /* connection terminated */
188 dir->msg[dir->msglen] = 0;
189 Dmsg1(100, "<dird: %s", dir->msg);
191 for (i=0; cmds[i].cmd; i++) {
192 if (strncmp(cmds[i].cmd, dir->msg, strlen(cmds[i].cmd)) == 0) {
193 found = true; /* indicate command found */
194 if (!jcr->authenticated && cmds[i].func != hello_cmd) {
195 bnet_fsend(dir, no_auth);
196 bnet_sig(dir, BNET_EOD);
199 if ((jcr->authenticated) && (!cmds[i].monitoraccess) && (jcr->director->monitor)) {
200 Dmsg1(100, "Command %s illegal.\n", cmds[i].cmd);
201 bnet_fsend(dir, illegal_cmd);
202 bnet_sig(dir, BNET_EOD);
205 Dmsg1(100, "Executing %s command.\n", cmds[i].cmd);
206 if (!cmds[i].func(jcr)) { /* do command */
207 quit = true; /* error or fully terminated, get out */
208 Dmsg1(20, "Quit command loop. Canceled=%d\n", job_canceled(jcr));
213 if (!found) { /* command not found */
214 bnet_fsend(dir, errmsg);
220 /* Inform Storage daemon that we are done */
221 if (jcr->store_bsock) {
222 bnet_sig(jcr->store_bsock, BNET_TERMINATE);
225 if (jcr->RunAfterJob && !job_canceled(jcr)) {
226 run_cmd(jcr, jcr->RunAfterJob, "ClientRunAfterJob");
228 generate_daemon_event(jcr, "JobEnd");
230 dequeue_messages(jcr); /* send any queued messages */
232 /* Inform Director that we are done */
233 bnet_sig(dir, BNET_TERMINATE);
235 /* Clean up fileset */
236 FF_PKT *ff = jcr->ff;
237 findFILESET *fileset = ff->fileset;
240 /* Delete FileSet Include lists */
241 for (i=0; i<fileset->include_list.size(); i++) {
242 findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
243 for (j=0; j<incexe->opts_list.size(); j++) {
244 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
245 for (k=0; k<fo->regex.size(); k++) {
246 regfree((regex_t *)fo->regex.get(k));
249 fo->regexdir.destroy();
250 fo->regexfile.destroy();
252 fo->wilddir.destroy();
253 fo->wildfile.destroy();
255 fo->fstype.destroy();
263 incexe->opts_list.destroy();
264 incexe->name_list.destroy();
266 fileset->include_list.destroy();
268 /* Delete FileSet Exclude lists */
269 for (i=0; i<fileset->exclude_list.size(); i++) {
270 findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
271 for (j=0; j<incexe->opts_list.size(); j++) {
272 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
274 fo->regexdir.destroy();
275 fo->regexfile.destroy();
277 fo->wilddir.destroy();
278 fo->wildfile.destroy();
280 fo->fstype.destroy();
282 incexe->opts_list.destroy();
283 incexe->name_list.destroy();
285 fileset->exclude_list.destroy();
289 Dmsg0(100, "Calling term_find_files\n");
290 term_find_files(jcr->ff);
292 Dmsg0(100, "Done with term_find_files\n");
293 free_jcr(jcr); /* destroy JCR record */
294 Dmsg0(100, "Done with free_jcr\n");
299 * Hello from Director he must identify himself and provide his
302 static int hello_cmd(JCR *jcr)
304 Dmsg0(120, "Calling Authenticate\n");
305 if (!authenticate_director(jcr)) {
308 Dmsg0(120, "OK Authenticate\n");
309 jcr->authenticated = true;
316 static int cancel_cmd(JCR *jcr)
318 BSOCK *dir = jcr->dir_bsock;
319 char Job[MAX_NAME_LENGTH];
322 if (sscanf(dir->msg, "cancel Job=%127s", Job) == 1) {
323 if (!(cjcr=get_jcr_by_full_name(Job))) {
324 bnet_fsend(dir, _("2901 Job %s not found.\n"), Job);
326 if (cjcr->store_bsock) {
327 cjcr->store_bsock->timed_out = 1;
328 cjcr->store_bsock->terminated = 1;
329 pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL);
331 set_jcr_job_status(cjcr, JS_Canceled);
333 bnet_fsend(dir, _("2001 Job %s marked to be canceled.\n"), Job);
336 bnet_fsend(dir, _("2902 Error scanning cancel command.\n"));
338 bnet_sig(dir, BNET_EOD);
344 * Set debug level as requested by the Director
347 static int setdebug_cmd(JCR *jcr)
349 BSOCK *dir = jcr->dir_bsock;
350 int level, trace_flag;
352 Dmsg1(110, "setdebug_cmd: %s", dir->msg);
353 if (sscanf(dir->msg, "setdebug=%d trace=%d", &level, &trace_flag) != 2 || level < 0) {
354 pm_strcpy(jcr->errmsg, dir->msg);
355 bnet_fsend(dir, _("2991 Bad setdebug command: %s\n"), jcr->errmsg);
359 set_trace(trace_flag);
360 return bnet_fsend(dir, OKsetdebug, level);
364 static int estimate_cmd(JCR *jcr)
366 BSOCK *dir = jcr->dir_bsock;
369 if (sscanf(dir->msg, estimatecmd, &jcr->listing) != 1) {
370 pm_strcpy(jcr->errmsg, dir->msg);
371 Jmsg(jcr, M_FATAL, 0, _("Bad estimate command: %s"), jcr->errmsg);
372 bnet_fsend(dir, _("2992 Bad estimate command.\n"));
376 bnet_fsend(dir, OKest, jcr->num_files_examined,
377 edit_uint64_with_commas(jcr->JobBytes, ed2));
378 bnet_sig(dir, BNET_EOD);
383 * Get JobId and Storage Daemon Authorization key from Director
385 static int job_cmd(JCR *jcr)
387 BSOCK *dir = jcr->dir_bsock;
388 POOLMEM *sd_auth_key;
390 sd_auth_key = get_memory(dir->msglen);
391 if (sscanf(dir->msg, jobcmd, &jcr->JobId, jcr->Job,
392 &jcr->VolSessionId, &jcr->VolSessionTime,
394 pm_strcpy(jcr->errmsg, dir->msg);
395 Jmsg(jcr, M_FATAL, 0, _("Bad Job Command: %s"), jcr->errmsg);
396 bnet_fsend(dir, BADjob);
397 free_pool_memory(sd_auth_key);
400 jcr->sd_auth_key = bstrdup(sd_auth_key);
401 free_pool_memory(sd_auth_key);
402 Dmsg2(120, "JobId=%d Auth=%s\n", jcr->JobId, jcr->sd_auth_key);
403 return bnet_fsend(dir, OKjob, HOST_OS, DISTNAME, DISTVER);
406 static int runbefore_cmd(JCR *jcr)
409 BSOCK *dir = jcr->dir_bsock;
410 POOLMEM *cmd = get_memory(dir->msglen+1);
412 Dmsg1(100, "runbefore_cmd: %s", dir->msg);
413 if (sscanf(dir->msg, runbefore, cmd) != 1) {
414 pm_strcpy(jcr->errmsg, dir->msg);
415 Jmsg1(jcr, M_FATAL, 0, _("Bad RunBeforeJob command: %s\n"), jcr->errmsg);
416 bnet_fsend(dir, _("2905 Bad RunBeforeJob command.\n"));
422 /* Run the command now */
423 ok = run_cmd(jcr, cmd, "ClientRunBeforeJob");
426 bnet_fsend(dir, OKRunBefore);
429 bnet_fsend(dir, _("2905 Bad RunBeforeJob command.\n"));
434 static int runafter_cmd(JCR *jcr)
436 BSOCK *dir = jcr->dir_bsock;
437 POOLMEM *msg = get_memory(dir->msglen+1);
439 Dmsg1(100, "runafter_cmd: %s", dir->msg);
440 if (sscanf(dir->msg, runafter, msg) != 1) {
441 pm_strcpy(jcr->errmsg, dir->msg);
442 Jmsg1(jcr, M_FATAL, 0, _("Bad RunAfter command: %s\n"), jcr->errmsg);
443 bnet_fsend(dir, _("2905 Bad RunAfterJob command.\n"));
448 if (jcr->RunAfterJob) {
449 free_pool_memory(jcr->RunAfterJob);
451 jcr->RunAfterJob = get_pool_memory(PM_FNAME);
452 pm_strcpy(jcr->RunAfterJob, msg);
453 free_pool_memory(msg);
454 return bnet_fsend(dir, OKRunAfter);
457 static bool run_cmd(JCR *jcr, char *cmd, const char *name)
459 POOLMEM *ecmd = get_pool_memory(PM_FNAME);
462 char line[MAXSTRING];
464 ecmd = edit_job_codes(jcr, ecmd, cmd, "");
465 bpipe = open_bpipe(ecmd, 0, "r");
466 free_pool_memory(ecmd);
469 Jmsg(jcr, M_FATAL, 0, _("%s could not execute. ERR=%s\n"), name,
473 while (fgets(line, sizeof(line), bpipe->rfd)) {
474 int len = strlen(line);
475 if (len > 0 && line[len-1] == '\n') {
478 Jmsg(jcr, M_INFO, 0, _("%s: %s\n"), name, line);
480 status = close_bpipe(bpipe);
483 Jmsg(jcr, M_FATAL, 0, _("%s returned non-zero status=%d. ERR=%s\n"), name,
484 status, be.strerror(status));
490 static bool init_fileset(JCR *jcr)
493 findFILESET *fileset;
502 fileset = (findFILESET *)malloc(sizeof(findFILESET));
503 memset(fileset, 0, sizeof(findFILESET));
504 ff->fileset = fileset;
505 fileset->state = state_none;
506 fileset->include_list.init(1, true);
507 fileset->exclude_list.init(1, true);
511 static findFOPTS *start_options(FF_PKT *ff)
513 int state = ff->fileset->state;
514 findINCEXE *incexe = ff->fileset->incexe;
516 if (state != state_options) {
517 ff->fileset->state = state_options;
518 findFOPTS *fo = (findFOPTS *)malloc(sizeof(findFOPTS));
519 memset(fo, 0, sizeof(findFOPTS));
520 fo->regex.init(1, true);
521 fo->regexdir.init(1, true);
522 fo->regexfile.init(1, true);
523 fo->wild.init(1, true);
524 fo->wilddir.init(1, true);
525 fo->wildfile.init(1, true);
526 fo->base.init(1, true);
527 fo->fstype.init(1, true);
528 incexe->current_opts = fo;
529 incexe->opts_list.append(fo);
531 return incexe->current_opts;
536 * Add fname to include/exclude fileset list. First check for
537 * | and < and if necessary perform command.
539 static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *fileset)
553 p++; /* skip over | */
554 fn = get_pool_memory(PM_FNAME);
555 fn = edit_job_codes(jcr, fn, p, "");
556 bpipe = open_bpipe(fn, 0, "r");
557 free_pool_memory(fn);
559 Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
563 while (fgets(buf, sizeof(buf), bpipe->rfd)) {
564 strip_trailing_junk(buf);
565 fileset->incexe->name_list.append(bstrdup(buf));
567 if ((stat=close_bpipe(bpipe)) != 0) {
568 Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
569 p, stat, strerror(errno));
574 Dmsg0(100, "Doing < include on client.\n");
575 p++; /* skip over < */
576 if ((ffd = fopen(p, "r")) == NULL) {
578 Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"),
582 while (fgets(buf, sizeof(buf), ffd)) {
583 strip_trailing_junk(buf);
584 Dmsg1(100, "%s\n", buf);
585 fileset->incexe->name_list.append(bstrdup(buf));
590 fileset->incexe->name_list.append(bstrdup(fname));
596 static void add_fileset(JCR *jcr, const char *item)
598 FF_PKT *ff = jcr->ff;
599 findFILESET *fileset = ff->fileset;
600 int state = fileset->state;
601 findFOPTS *current_opts;
603 /* Get code, optional subcode, and position item past the dividing space */
604 Dmsg1(100, "%s\n", item);
609 int subcode = ' '; /* A space is always a valid subcode */
610 if (item[0] != '\0' && item[0] != ' ') {
618 /* Skip all lines we receive after an error */
619 if (state == state_error) {
624 * The switch tests the code for validity.
625 * The subcode is always good if it is a space, otherwise we must confirm.
626 * We set state to state_error first assuming the subcode is invalid,
627 * requiring state to be set in cases below that handle subcodes.
629 if (subcode != ' ') {
635 fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
636 memset(fileset->incexe, 0, sizeof(findINCEXE));
637 fileset->incexe->opts_list.init(1, true);
638 fileset->incexe->name_list.init(1, true);
639 fileset->include_list.append(fileset->incexe);
643 fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
644 memset(fileset->incexe, 0, sizeof(findINCEXE));
645 fileset->incexe->opts_list.init(1, true);
646 fileset->incexe->name_list.init(1, true);
647 fileset->exclude_list.append(fileset->incexe);
653 /* File item to either include/include list */
654 state = state_include;
655 add_file_to_fileset(jcr, item, fileset);
658 current_opts = start_options(ff);
662 preg = (regex_t *)malloc(sizeof(regex_t));
663 if (current_opts->flags & FO_IGNORECASE) {
664 rc = regcomp(preg, item, REG_EXTENDED|REG_ICASE);
666 rc = regcomp(preg, item, REG_EXTENDED);
669 regerror(rc, preg, prbuf, sizeof(prbuf));
672 Jmsg(jcr, M_FATAL, 0, _("REGEX %s compile error. ERR=%s\n"), item, prbuf);
676 state = state_options;
677 if (subcode == ' ') {
678 current_opts->regex.append(preg);
679 } else if (subcode == 'D') {
680 current_opts->regexdir.append(preg);
681 } else if (subcode == 'F') {
682 current_opts->regexfile.append(preg);
688 current_opts = start_options(ff);
689 current_opts->base.append(bstrdup(item));
690 state = state_options;
693 current_opts = start_options(ff);
694 current_opts->fstype.append(bstrdup(item));
695 state = state_options;
698 current_opts = start_options(ff);
699 state = state_options;
700 if (subcode == ' ') {
701 current_opts->wild.append(bstrdup(item));
702 } else if (subcode == 'D') {
703 current_opts->wilddir.append(bstrdup(item));
704 } else if (subcode == 'F') {
705 current_opts->wildfile.append(bstrdup(item));
711 current_opts = start_options(ff);
712 set_options(current_opts, item);
713 state = state_options;
716 current_opts = start_options(ff);
717 current_opts->reader = bstrdup(item);
718 state = state_options;
721 current_opts = start_options(ff);
722 current_opts->writer = bstrdup(item);
723 state = state_options;
726 Jmsg(jcr, M_FATAL, 0, _("Invalid FileSet command: %s\n"), item);
730 ff->fileset->state = state;
733 static bool term_fileset(JCR *jcr)
735 FF_PKT *ff = jcr->ff;
736 findFILESET *fileset = ff->fileset;
739 for (i=0; i<fileset->include_list.size(); i++) {
740 findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
742 for (j=0; j<incexe->opts_list.size(); j++) {
743 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
744 for (k=0; k<fo->regex.size(); k++) {
745 Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
747 for (k=0; k<fo->regexdir.size(); k++) {
748 Dmsg1(400, "RD %s\n", (char *)fo->regexdir.get(k));
750 for (k=0; k<fo->regexfile.size(); k++) {
751 Dmsg1(400, "RF %s\n", (char *)fo->regexfile.get(k));
753 for (k=0; k<fo->wild.size(); k++) {
754 Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
756 for (k=0; k<fo->wilddir.size(); k++) {
757 Dmsg1(400, "WD %s\n", (char *)fo->wilddir.get(k));
759 for (k=0; k<fo->wildfile.size(); k++) {
760 Dmsg1(400, "WF %s\n", (char *)fo->wildfile.get(k));
762 for (k=0; k<fo->base.size(); k++) {
763 Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
765 for (k=0; k<fo->fstype.size(); k++) {
766 Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k));
769 Dmsg1(400, "D %s\n", fo->reader);
772 Dmsg1(400, "T %s\n", fo->writer);
775 for (j=0; j<incexe->name_list.size(); j++) {
776 Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
779 for (i=0; i<fileset->exclude_list.size(); i++) {
780 findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
782 for (j=0; j<incexe->opts_list.size(); j++) {
783 findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
784 for (k=0; k<fo->regex.size(); k++) {
785 Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
787 for (k=0; k<fo->regexdir.size(); k++) {
788 Dmsg1(400, "RD %s\n", (char *)fo->regexdir.get(k));
790 for (k=0; k<fo->regexfile.size(); k++) {
791 Dmsg1(400, "RF %s\n", (char *)fo->regexfile.get(k));
793 for (k=0; k<fo->wild.size(); k++) {
794 Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
796 for (k=0; k<fo->wilddir.size(); k++) {
797 Dmsg1(400, "WD %s\n", (char *)fo->wilddir.get(k));
799 for (k=0; k<fo->wildfile.size(); k++) {
800 Dmsg1(400, "WF %s\n", (char *)fo->wildfile.get(k));
802 for (k=0; k<fo->base.size(); k++) {
803 Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
805 for (k=0; k<fo->fstype.size(); k++) {
806 Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k));
809 for (j=0; j<incexe->name_list.size(); j++) {
810 Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
813 return ff->fileset->state != state_error;
818 * As an optimization, we should do this during
819 * "compile" time in filed/job.c, and keep only a bit mask
820 * and the Verify options.
822 static void set_options(findFOPTS *fo, const char *opts)
827 for (p=opts; *p; p++) {
829 case 'a': /* alway replace */
830 case '0': /* no option */
833 fo->flags |= FO_EXCLUDE;
836 fo->flags |= FO_MULTIFS;
838 case 'h': /* no recursion */
839 fo->flags |= FO_NO_RECURSION;
841 case 'H': /* no hard link handling */
842 fo->flags |= FO_NO_HARDLINK;
845 fo->flags |= FO_IGNORECASE;
851 fo->flags |= FO_NOREPLACE;
853 case 'p': /* use portable data format */
854 fo->flags |= FO_PORTABLE;
856 case 'R': /* Resource forks and Finder Info */
857 fo->flags |= FO_HFSPLUS;
858 case 'r': /* read fifo */
859 fo->flags |= FO_READFIFO;
862 fo->flags |= FO_SHA1;
865 fo->flags |= FO_SPARSE;
868 fo->flags |= FO_MTIMEONLY;
871 fo->flags |= FO_KEEPATIME;
876 case 'V': /* verify options */
877 /* Copy Verify Options */
878 for (j=0; *p && *p != ':'; p++) {
879 fo->VerifyOpts[j] = *p;
880 if (j < (int)sizeof(fo->VerifyOpts) - 1) {
884 fo->VerifyOpts[j] = 0;
887 fo->flags |= FO_IF_NEWER;
889 case 'Z': /* gzip compression */
890 fo->flags |= FO_GZIP;
891 fo->GZIP_level = *++p - '0';
892 Dmsg1(200, "Compression level=%d\n", fo->GZIP_level);
895 Emsg1(M_ERROR, 0, _("Unknown include/exclude option: %c\n"), *p);
903 * Director is passing his Fileset
905 static int fileset_cmd(JCR *jcr)
907 BSOCK *dir = jcr->dir_bsock;
910 sscanf(dir->msg, "fileset vss=%d", &vss);
913 if (!init_fileset(jcr)) {
916 while (bnet_recv(dir) >= 0) {
917 strip_trailing_junk(dir->msg);
918 Dmsg1(400, "Fileset: %s\n", dir->msg);
919 add_fileset(jcr, dir->msg);
921 if (!term_fileset(jcr)) {
924 return bnet_fsend(dir, OKinc);
927 static void free_bootstrap(JCR *jcr)
929 if (jcr->RestoreBootstrap) {
930 unlink(jcr->RestoreBootstrap);
931 free_pool_memory(jcr->RestoreBootstrap);
932 jcr->RestoreBootstrap = NULL;
938 * The Director sends us the bootstrap file, which
939 * we will in turn pass to the SD.
941 static int bootstrap_cmd(JCR *jcr)
943 BSOCK *dir = jcr->dir_bsock;
944 POOLMEM *fname = get_pool_memory(PM_FNAME);
948 Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
950 Dmsg1(400, "bootstrap=%s\n", fname);
951 jcr->RestoreBootstrap = fname;
952 bs = fopen(fname, "a+"); /* create file */
955 Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"),
956 jcr->RestoreBootstrap, be.strerror());
958 * Suck up what he is sending to us so that he will then
959 * read our error message.
961 while (bnet_recv(dir) >= 0)
964 set_jcr_job_status(jcr, JS_ErrorTerminated);
968 while (bnet_recv(dir) >= 0) {
969 Dmsg1(200, "filed<dird: bootstrap file %s\n", dir->msg);
974 * Note, do not free the bootstrap yet -- it needs to be
977 return bnet_fsend(dir, OKbootstrap);
982 * Get backup level from Director
985 static int level_cmd(JCR *jcr)
987 BSOCK *dir = jcr->dir_bsock;
988 POOLMEM *level, *buf = NULL;
991 level = get_memory(dir->msglen+1);
992 Dmsg1(110, "level_cmd: %s", dir->msg);
993 if (sscanf(dir->msg, "level = %s ", level) != 1) {
996 /* Base backup requested? */
997 if (strcmp(level, "base") == 0) {
998 jcr->JobLevel = L_BASE;
999 /* Full backup requested? */
1000 } else if (strcmp(level, "full") == 0) {
1001 jcr->JobLevel = L_FULL;
1002 } else if (strcmp(level, "differential") == 0) {
1003 jcr->JobLevel = L_DIFFERENTIAL;
1006 } else if (strcmp(level, "incremental") == 0) {
1007 jcr->JobLevel = L_INCREMENTAL;
1011 * We get his UTC since time, then sync the clocks and correct it
1012 * to agree with our clock.
1014 } else if (strcmp(level, "since_utime") == 0) {
1015 buf = get_memory(dir->msglen+1);
1016 utime_t since_time, adj;
1017 btime_t his_time, bt_start, rt=0, bt_adj=0;
1018 if (jcr->JobLevel == L_NONE) {
1019 jcr->JobLevel = L_SINCE; /* if no other job level set, do it now */
1021 if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d",
1022 buf, &mtime_only) != 2) {
1025 since_time = str_to_uint64(buf); /* this is the since time */
1026 char ed1[50], ed2[50];
1028 * Sync clocks by polling him for the time. We take
1029 * 10 samples of his time throwing out the first two.
1031 for (int i=0; i<10; i++) {
1032 bt_start = get_current_btime();
1033 bnet_sig(dir, BNET_BTIME); /* poll for time */
1034 if (bnet_recv(dir) <= 0) { /* get response */
1037 if (sscanf(dir->msg, "btime %s", buf) != 1) {
1040 if (i < 2) { /* toss first two results */
1043 his_time = str_to_uint64(buf);
1044 rt = get_current_btime() - bt_start; /* compute round trip time */
1045 bt_adj -= his_time - bt_start - rt/2;
1046 Dmsg2(200, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
1049 bt_adj = bt_adj / 8; /* compute average time */
1050 Dmsg2(100, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
1051 adj = btime_to_utime(bt_adj);
1052 since_time += adj; /* adjust for clock difference */
1054 Jmsg(jcr, M_INFO, 0, _("DIR and FD clocks differ by %d seconds, FD automatically adjusting.\n"), adj);
1056 bnet_sig(dir, BNET_EOD);
1058 Dmsg2(100, "adj = %d since_time=%d\n", (int)adj, (int)since_time);
1059 jcr->incremental = 1; /* set incremental or decremental backup */
1060 jcr->mtime = (time_t)since_time; /* set since time */
1062 Jmsg1(jcr, M_FATAL, 0, _("Unknown backup level: %s\n"), level);
1070 return bnet_fsend(dir, OKlevel);
1073 pm_strcpy(jcr->errmsg, dir->msg);
1074 Jmsg1(jcr, M_FATAL, 0, _("Bad level command: %s\n"), jcr->errmsg);
1083 * Get session parameters from Director -- this is for a Restore command
1085 static int session_cmd(JCR *jcr)
1087 BSOCK *dir = jcr->dir_bsock;
1089 Dmsg1(100, "SessionCmd: %s", dir->msg);
1090 if (sscanf(dir->msg, sessioncmd, jcr->VolumeName,
1091 &jcr->VolSessionId, &jcr->VolSessionTime,
1092 &jcr->StartFile, &jcr->EndFile,
1093 &jcr->StartBlock, &jcr->EndBlock) != 7) {
1094 pm_strcpy(jcr->errmsg, dir->msg);
1095 Jmsg(jcr, M_FATAL, 0, _("Bad session command: %s"), jcr->errmsg);
1099 return bnet_fsend(dir, OKsession);
1103 * Get address of storage daemon from Director
1106 static int storage_cmd(JCR *jcr)
1108 int stored_port; /* storage daemon port */
1109 int enable_ssl; /* enable ssl to sd */
1110 BSOCK *dir = jcr->dir_bsock;
1111 BSOCK *sd; /* storage daemon bsock */
1113 Dmsg1(100, "StorageCmd: %s", dir->msg);
1114 if (sscanf(dir->msg, storaddr, &jcr->stored_addr, &stored_port, &enable_ssl) != 3) {
1115 pm_strcpy(jcr->errmsg, dir->msg);
1116 Jmsg(jcr, M_FATAL, 0, _("Bad storage command: %s"), jcr->errmsg);
1119 Dmsg3(110, "Open storage: %s:%d ssl=%d\n", jcr->stored_addr, stored_port, enable_ssl);
1120 /* Open command communications with Storage daemon */
1121 /* Try to connect for 1 hour at 10 second intervals */
1122 sd = bnet_connect(jcr, 10, (int)me->SDConnectTimeout, _("Storage daemon"),
1123 jcr->stored_addr, NULL, stored_port, 1);
1125 Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"),
1126 jcr->stored_addr, stored_port);
1127 Dmsg2(100, "Failed to connect to Storage daemon: %s:%d\n",
1128 jcr->stored_addr, stored_port);
1131 Dmsg0(110, "Connection OK to SD.\n");
1133 jcr->store_bsock = sd;
1135 bnet_fsend(sd, "Hello Start Job %s\n", jcr->Job);
1136 if (!authenticate_storagedaemon(jcr)) {
1137 Jmsg(jcr, M_FATAL, 0, _("Failed to authenticate Storage daemon.\n"));
1140 Dmsg0(110, "Authenticated with SD.\n");
1142 /* Send OK to Director */
1143 return bnet_fsend(dir, OKstore);
1148 * Do a backup. For now, we handle only Full and Incremental.
1150 static int backup_cmd(JCR *jcr)
1152 BSOCK *dir = jcr->dir_bsock;
1153 BSOCK *sd = jcr->store_bsock;
1156 char ed1[50], ed2[50];
1158 set_jcr_job_status(jcr, JS_Blocked);
1159 jcr->JobType = JT_BACKUP;
1160 Dmsg1(100, "begin backup ff=%p\n", jcr->ff);
1163 Jmsg(jcr, M_FATAL, 0, _("Cannot contact Storage daemon\n"));
1167 bnet_fsend(dir, OKbackup);
1168 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1171 * Send Append Open Session to Storage daemon
1173 bnet_fsend(sd, append_open);
1174 Dmsg1(110, ">stored: %s", sd->msg);
1176 * Expect to receive back the Ticket number
1178 if (bget_msg(sd) >= 0) {
1179 Dmsg1(110, "<stored: %s", sd->msg);
1180 if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
1181 Jmsg(jcr, M_FATAL, 0, _("Bad response to append open: %s\n"), sd->msg);
1184 Dmsg1(110, "Got Ticket=%d\n", jcr->Ticket);
1186 Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to open command\n"));
1191 * Send Append data command to Storage daemon
1193 bnet_fsend(sd, append_data, jcr->Ticket);
1194 Dmsg1(110, ">stored: %s", sd->msg);
1197 * Expect to get OK data
1199 Dmsg1(110, "<stored: %s", sd->msg);
1200 if (!response(jcr, sd, OK_data, "Append Data")) {
1204 generate_daemon_event(jcr, "JobStart");
1207 /* START VSS ON WIN 32 */
1208 if (g_pVSSClient && enable_vss) {
1209 /* Run only one at a time */
1211 if (g_pVSSClient->InitializeForBackup()) {
1212 /* tell vss which drives to snapshot */
1213 char szWinDriveLetters[27];
1214 if (get_win32_driveletters(jcr->ff, szWinDriveLetters)) {
1215 Jmsg(jcr, M_INFO, 0, _("Generate VSS snapshots. Driver=\"%s\", Drive(s)=\"%s\"\n"), g_pVSSClient->GetDriverName(), szWinDriveLetters);
1216 if (!g_pVSSClient->CreateSnapshots(szWinDriveLetters)) {
1218 Jmsg(jcr, M_WARNING, 0, _("Generate VSS snapshots failed. ERR=%s\n"),
1221 /* tell user if snapshot creation of a specific drive failed */
1223 for (i=0; i<strlen (szWinDriveLetters); i++) {
1224 if (islower(szWinDriveLetters[i])) {
1225 Jmsg(jcr, M_WARNING, 0, _("Generate VSS snapshot of drive \"%c:\\\" failed\n"), szWinDriveLetters[i]);
1228 /* inform user about writer states */
1229 for (i=0; i<g_pVSSClient->GetWriterCount(); i++) {
1230 int msg_type = M_INFO;
1231 if (g_pVSSClient->GetWriterState(i) < 0) {
1232 msg_type = M_WARNING;
1234 Jmsg(jcr, msg_type, 0, _("VSS Writer: %s\n"), g_pVSSClient->GetWriterInfo(i));
1238 Jmsg(jcr, M_INFO, 0, _("No drive letters found for generating VSS snapshots.\n"));
1241 Jmsg(jcr, M_WARNING, 0, _("VSS was not initialized properly. VSS support is disabled.\n"));
1247 * Send Files to Storage daemon
1249 Dmsg1(110, "begin blast ff=%p\n", (FF_PKT *)jcr->ff);
1250 if (!blast_data_to_storage_daemon(jcr, NULL)) {
1251 set_jcr_job_status(jcr, JS_ErrorTerminated);
1252 bnet_suppress_error_messages(sd, 1);
1253 bget_msg(sd); /* Read final response from append_data */
1254 Dmsg0(110, "Error in blast_data.\n");
1256 set_jcr_job_status(jcr, JS_Terminated);
1257 if (jcr->JobStatus != JS_Terminated) {
1258 bnet_suppress_error_messages(sd, 1);
1259 goto cleanup; /* bail out now */
1262 * Expect to get response to append_data from Storage daemon
1264 if (!response(jcr, sd, OK_append, "Append Data")) {
1265 set_jcr_job_status(jcr, JS_ErrorTerminated);
1270 * Send Append End Data to Storage daemon
1272 bnet_fsend(sd, append_end, jcr->Ticket);
1274 if (!response(jcr, sd, OK_end, "Append End")) {
1275 set_jcr_job_status(jcr, JS_ErrorTerminated);
1280 * Send Append Close to Storage daemon
1282 bnet_fsend(sd, append_close, jcr->Ticket);
1283 while (bget_msg(sd) >= 0) { /* stop on signal or error */
1284 if (sscanf(sd->msg, OK_close, &SDJobStatus) == 1) {
1286 Dmsg2(200, "SDJobStatus = %d %c\n", SDJobStatus, (char)SDJobStatus);
1290 Jmsg(jcr, M_FATAL, 0, _("Append Close with SD failed.\n"));
1293 if (SDJobStatus != JS_Terminated) {
1294 Jmsg(jcr, M_FATAL, 0, _("Bad status %d returned from Storage Daemon.\n"),
1301 /* STOP VSS ON WIN 32 */
1302 /* tell vss to close the backup session */
1303 if (g_pVSSClient && enable_vss) {
1304 g_pVSSClient->CloseBackup();
1309 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1310 edit_uint64(jcr->ReadBytes, ed1),
1311 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1312 Dmsg1(110, "End FD msg: %s\n", dir->msg);
1314 return 0; /* return and stop command loop */
1318 * Do a Verify for Director
1321 static int verify_cmd(JCR *jcr)
1323 BSOCK *dir = jcr->dir_bsock;
1324 BSOCK *sd = jcr->store_bsock;
1325 char level[100], ed1[50], ed2[50];
1327 jcr->JobType = JT_VERIFY;
1328 if (sscanf(dir->msg, verifycmd, level) != 1) {
1329 bnet_fsend(dir, _("2994 Bad verify command: %s\n"), dir->msg);
1333 if (strcasecmp(level, "init") == 0) {
1334 jcr->JobLevel = L_VERIFY_INIT;
1335 } else if (strcasecmp(level, "catalog") == 0){
1336 jcr->JobLevel = L_VERIFY_CATALOG;
1337 } else if (strcasecmp(level, "volume") == 0){
1338 jcr->JobLevel = L_VERIFY_VOLUME_TO_CATALOG;
1339 } else if (strcasecmp(level, "data") == 0){
1340 jcr->JobLevel = L_VERIFY_DATA;
1341 } else if (strcasecmp(level, "disk_to_catalog") == 0) {
1342 jcr->JobLevel = L_VERIFY_DISK_TO_CATALOG;
1344 bnet_fsend(dir, _("2994 Bad verify level: %s\n"), dir->msg);
1348 bnet_fsend(dir, OKverify);
1350 generate_daemon_event(jcr, "JobStart");
1352 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1354 switch (jcr->JobLevel) {
1356 case L_VERIFY_CATALOG:
1359 case L_VERIFY_VOLUME_TO_CATALOG:
1360 if (!open_sd_read_session(jcr)) {
1363 start_dir_heartbeat(jcr);
1364 do_verify_volume(jcr);
1365 stop_dir_heartbeat(jcr);
1367 * Send Close session command to Storage daemon
1369 bnet_fsend(sd, read_close, jcr->Ticket);
1370 Dmsg1(130, "bfiled>stored: %s", sd->msg);
1372 /* ****FIXME**** check response */
1373 bget_msg(sd); /* get OK */
1375 /* Inform Storage daemon that we are done */
1376 bnet_sig(sd, BNET_TERMINATE);
1379 case L_VERIFY_DISK_TO_CATALOG:
1383 bnet_fsend(dir, _("2994 Bad verify level: %s\n"), dir->msg);
1387 bnet_sig(dir, BNET_EOD);
1389 /* Send termination status back to Dir */
1390 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1391 edit_uint64(jcr->ReadBytes, ed1),
1392 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1394 /* Inform Director that we are done */
1395 bnet_sig(dir, BNET_TERMINATE);
1396 return 0; /* return and terminate command loop */
1400 * Do a Restore for Director
1403 static int restore_cmd(JCR *jcr)
1405 BSOCK *dir = jcr->dir_bsock;
1406 BSOCK *sd = jcr->store_bsock;
1410 char ed1[50], ed2[50];
1413 * Scan WHERE (base directory for restore) from command
1415 Dmsg0(150, "restore command\n");
1416 /* Pickup where string */
1417 where = get_memory(dir->msglen+1);
1420 if (sscanf(dir->msg, restorecmd, &replace, &prefix_links, where) != 3) {
1421 if (sscanf(dir->msg, restorecmd1, &replace, &prefix_links) != 2) {
1422 pm_strcpy(jcr->errmsg, dir->msg);
1423 Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg);
1428 /* Turn / into nothing */
1429 if (where[0] == '/' && where[1] == 0) {
1433 Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
1434 unbash_spaces(where);
1435 jcr->where = bstrdup(where);
1436 free_pool_memory(where);
1437 jcr->replace = replace;
1438 jcr->prefix_links = prefix_links;
1440 bnet_fsend(dir, OKrestore);
1441 Dmsg1(110, "bfiled>dird: %s", dir->msg);
1443 jcr->JobType = JT_RESTORE;
1445 set_jcr_job_status(jcr, JS_Blocked);
1447 if (!open_sd_read_session(jcr)) {
1448 set_jcr_job_status(jcr, JS_ErrorTerminated);
1452 set_jcr_job_status(jcr, JS_Running);
1455 * Do restore of files and data
1457 start_dir_heartbeat(jcr);
1458 generate_daemon_event(jcr, "JobStart");
1460 stop_dir_heartbeat(jcr);
1462 set_jcr_job_status(jcr, JS_Terminated);
1463 if (jcr->JobStatus != JS_Terminated) {
1464 bnet_suppress_error_messages(sd, 1);
1468 * Send Close session command to Storage daemon
1470 bnet_fsend(sd, read_close, jcr->Ticket);
1471 Dmsg1(130, "bfiled>stored: %s", sd->msg);
1473 bget_msg(sd); /* get OK */
1475 /* Inform Storage daemon that we are done */
1476 bnet_sig(sd, BNET_TERMINATE);
1481 set_jcr_job_status(jcr, JS_ErrorTerminated);
1483 /* Send termination status back to Dir */
1484 bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
1485 edit_uint64(jcr->ReadBytes, ed1),
1486 edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
1488 /* Inform Director that we are done */
1489 bnet_sig(dir, BNET_TERMINATE);
1491 Dmsg0(130, "Done in job.c\n");
1492 return 0; /* return and terminate command loop */
1495 static int open_sd_read_session(JCR *jcr)
1497 BSOCK *sd = jcr->store_bsock;
1500 Jmsg(jcr, M_FATAL, 0, _("Improper calling sequence.\n"));
1503 Dmsg4(120, "VolSessId=%ld VolsessT=%ld SF=%ld EF=%ld\n",
1504 jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile);
1505 Dmsg2(120, "JobId=%d vol=%s\n", jcr->JobId, "DummyVolume");
1507 * Open Read Session with Storage daemon
1509 bnet_fsend(sd, read_open, jcr->VolumeName,
1510 jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile,
1511 jcr->StartBlock, jcr->EndBlock);
1512 Dmsg1(110, ">stored: %s", sd->msg);
1517 if (bget_msg(sd) >= 0) {
1518 Dmsg1(110, "bfiled<stored: %s", sd->msg);
1519 if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
1520 Jmsg(jcr, M_FATAL, 0, _("Bad response to SD read open: %s\n"), sd->msg);
1523 Dmsg1(110, "bfiled: got Ticket=%d\n", jcr->Ticket);
1525 Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to read open command\n"));
1529 if (!send_bootstrap_file(jcr)) {
1534 * Start read of data with Storage daemon
1536 bnet_fsend(sd, read_data, jcr->Ticket);
1537 Dmsg1(110, ">stored: %s", sd->msg);
1542 if (!response(jcr, sd, OK_data, "Read Data")) {
1549 * Destroy the Job Control Record and associated
1550 * resources (sockets).
1552 static void filed_free_jcr(JCR *jcr)
1554 if (jcr->store_bsock) {
1555 bnet_close(jcr->store_bsock);
1557 free_bootstrap(jcr);
1558 if (jcr->last_fname) {
1559 free_pool_memory(jcr->last_fname);
1561 if (jcr->RunAfterJob) {
1562 free_pool_memory(jcr->RunAfterJob);
1570 * Get response from Storage daemon to a command we
1571 * sent. Check that the response is OK.
1573 * Returns: 0 on failure
1576 int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd)
1581 if (bget_msg(sd) > 0) {
1582 Dmsg0(110, sd->msg);
1583 if (strcmp(sd->msg, resp) == 0) {
1587 if (job_canceled(jcr)) {
1588 return 0; /* if canceled avoid useless error messages */
1590 if (is_bnet_error(sd)) {
1591 Jmsg2(jcr, M_FATAL, 0, _("Comm error with SD. bad response to %s. ERR=%s\n"),
1592 cmd, bnet_strerror(sd));
1594 Jmsg3(jcr, M_FATAL, 0, _("Bad response to %s command. Wanted %s, got %s\n"),
1595 cmd, resp, sd->msg);
1600 static int send_bootstrap_file(JCR *jcr)
1604 BSOCK *sd = jcr->store_bsock;
1605 const char *bootstrap = "bootstrap\n";
1608 Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap);
1609 if (!jcr->RestoreBootstrap) {
1612 bs = fopen(jcr->RestoreBootstrap, "r");
1615 Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
1616 jcr->RestoreBootstrap, be.strerror());
1617 set_jcr_job_status(jcr, JS_ErrorTerminated);
1620 sd->msglen = pm_strcpy(sd->msg, bootstrap);
1622 while (fgets(buf, sizeof(buf), bs)) {
1623 sd->msglen = Mmsg(sd->msg, "%s", buf);
1626 bnet_sig(sd, BNET_EOD);
1628 if (!response(jcr, sd, OKSDbootstrap, "Bootstrap")) {
1629 set_jcr_job_status(jcr, JS_ErrorTerminated);
1635 free_bootstrap(jcr);