2 * Bacula File Daemon Job processing
4 * Kern Sibbald, October MM
10 Copyright (C) 2000, 2001, 2002 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,
33 extern char my_name[];
34 extern CLIENT *me; /* our client resource */
36 /* Imported functions */
37 extern int status_cmd(JCR *jcr);
39 /* Forward referenced functions */
40 static int backup_cmd(JCR *jcr);
41 static int bootstrap_cmd(JCR *jcr);
42 static int cancel_cmd(JCR *jcr);
43 static int setdebug_cmd(JCR *jcr);
44 static int estimate_cmd(JCR *jcr);
45 static int exclude_cmd(JCR *jcr);
46 static int hello_cmd(JCR *jcr);
47 static int job_cmd(JCR *jcr);
48 static int include_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, 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);
60 /* Exported functions */
68 * The following are the recognized commands from the Director.
70 static struct s_cmds cmds[] = {
71 {"backup", backup_cmd},
72 {"cancel", cancel_cmd},
73 {"setdebug=", setdebug_cmd},
74 {"estimate", estimate_cmd},
75 {"exclude", exclude_cmd},
77 {"include", include_cmd},
79 {"level = ", level_cmd},
80 {"restore", restore_cmd},
81 {"session", session_cmd},
82 {"status", status_cmd},
83 {"storage ", storage_cmd},
84 {"verify", verify_cmd},
85 {"bootstrap",bootstrap_cmd},
86 {NULL, NULL} /* list terminator */
89 /* Commands received from director that need scanning */
90 static char jobcmd[] = "JobId=%d Job=%127s SDid=%d SDtime=%d Authorization=%100s";
91 static char storaddr[] = "storage address=%s port=%d\n";
92 static char sessioncmd[] = "session %s %ld %ld %ld %ld %ld %ld\n";
93 static char restorecmd[] = "restore replace=%c where=%s\n";
94 static char verifycmd[] = "verify level=%20s\n";
96 /* Responses sent to Director */
97 static char errmsg[] = "2999 Invalid command\n";
98 static char no_auth[] = "2998 No Authorization\n";
99 static char OKinc[] = "2000 OK include\n";
100 static char OKest[] = "2000 OK estimate files=%ld bytes=%ld\n";
101 static char OKexc[] = "2000 OK exclude\n";
102 static char OKlevel[] = "2000 OK level\n";
103 static char OKbackup[] = "2000 OK backup\n";
104 static char OKbootstrap[] = "2000 OK bootstrap\n";
105 static char OKverify[] = "2000 OK verify\n";
106 static char OKrestore[] = "2000 OK restore\n";
107 static char OKsession[] = "2000 OK session\n";
108 static char OKstore[] = "2000 OK storage\n";
109 static char OKjob[] = "2000 OK Job " FDHOST "," DISTNAME "," DISTVER;
110 static char OKsetdebug[] = "2000 OK setdebug=%d\n";
111 static char BADjob[] = "2901 Bad Job\n";
112 static char EndRestore[] = "2800 End Job TermCode=%d JobFiles=%u JobBytes=%" lld "\n";
113 static char EndBackup[] = "2801 End Backup Job TermCode=%d JobFiles=%u ReadBytes=%" lld " JobBytes=%" lld "\n";
115 /* Responses received from Storage Daemon */
116 static char OK_end[] = "3000 OK end\n";
117 static char OK_close[] = "3000 OK close Status = %d\n";
118 static char OK_open[] = "3000 OK open ticket = %d\n";
119 static char OK_data[] = "3000 OK data\n";
120 static char OK_append[] = "3000 OK append data\n";
121 static char OKSDbootstrap[] = "3000 OK bootstrap\n";
124 /* Commands sent to Storage Daemon */
125 static char append_open[] = "append open session\n";
126 static char append_data[] = "append data %d\n";
127 static char append_end[] = "append end session %d\n";
128 static char append_close[] = "append close session %d\n";
129 static char read_open[] = "read open session = %s %ld %ld %ld %ld %ld %ld\n";
130 static char read_data[] = "read data %d\n";
131 static char read_close[] = "read close session %d\n";
134 * Accept requests from a Director
136 * NOTE! We are running as a separate thread
138 * Send output one line
139 * at a time followed by a zero length transmission.
141 * Return when the connection is terminated or there
144 * Basic task here is:
145 * Authenticate Director (during Hello command).
146 * Accept commands one at a time from the Director
150 void *handle_client_request(void *dirp)
154 BSOCK *dir = (BSOCK *)dirp;
156 jcr = new_jcr(sizeof(JCR), filed_free_jcr); /* create JCR */
157 jcr->dir_bsock = dir;
158 jcr->ff = init_find_files();
159 jcr->start_time = time(NULL);
160 jcr->last_fname = get_pool_memory(PM_FNAME);
161 jcr->last_fname[0] = 0;
162 jcr->client_name = get_memory(strlen(my_name) + 1);
163 strcpy(jcr->client_name, my_name);
164 dir->jcr = (void *)jcr;
166 /**********FIXME******* add command handler error code */
168 for (quit=0; !quit;) {
171 if (bnet_recv(dir) < 0) {
172 break; /* connection terminated */
174 dir->msg[dir->msglen] = 0;
175 Dmsg1(100, "<dird: %s", dir->msg);
177 for (i=0; cmds[i].cmd; i++) {
178 if (strncmp(cmds[i].cmd, dir->msg, strlen(cmds[i].cmd)) == 0) {
179 if (!jcr->authenticated && cmds[i].func != hello_cmd) {
180 bnet_fsend(dir, no_auth);
183 if (!cmds[i].func(jcr)) { /* do command */
184 quit = TRUE; /* error, get out */
185 Pmsg0(20, "Command error\n");
187 found = TRUE; /* indicate command found */
191 if (!found) { /* command not found */
192 bnet_fsend(dir, errmsg);
197 Dmsg0(100, "Calling term_find_files\n");
198 term_find_files(jcr->ff);
199 Dmsg0(100, "Done with term_find_files\n");
200 free_jcr(jcr); /* destroy JCR record */
201 Dmsg0(100, "Done with free_jcr\n");
206 * Hello from Director he must identify himself and provide his
209 static int hello_cmd(JCR *jcr)
211 Dmsg0(120, "Calling Authenticate\n");
212 if (!authenticate_director(jcr)) {
215 Dmsg0(120, "OK Authenticate\n");
216 jcr->authenticated = TRUE;
223 static int cancel_cmd(JCR *jcr)
225 BSOCK *dir = jcr->dir_bsock;
226 char Job[MAX_NAME_LENGTH];
229 if (sscanf(dir->msg, "cancel Job=%127s", Job) == 1) {
230 if (!(cjcr=get_jcr_by_full_name(Job))) {
231 bnet_fsend(dir, "2901 Job %s not found.\n", Job);
233 cjcr->JobStatus = JS_Cancelled;
235 bnet_fsend(dir, "2001 Job %s marked to be cancelled.\n", Job);
238 bnet_fsend(dir, "2902 Error scanning cancel command.\n");
240 bnet_sig(dir, BNET_EOD);
246 * Set debug level as requested by the Director
249 static int setdebug_cmd(JCR *jcr)
251 BSOCK *dir = jcr->dir_bsock;
254 Dmsg1(110, "setdebug_cmd: %s", dir->msg);
255 if (sscanf(dir->msg, "setdebug=%d", &level) != 1 || level < 0) {
256 bnet_fsend(dir, "2991 Bad setdebug command: %s\n", dir->msg);
260 return bnet_fsend(dir, OKsetdebug, level);
264 static int estimate_cmd(JCR *jcr)
266 BSOCK *dir = jcr->dir_bsock;
268 return bnet_fsend(dir, OKest, jcr->num_files_examined, jcr->JobBytes);
272 * Get JobId and Storage Daemon Authorization key from Director
274 static int job_cmd(JCR *jcr)
276 BSOCK *dir = jcr->dir_bsock;
277 POOLMEM *sd_auth_key;
279 sd_auth_key = get_memory(dir->msglen);
280 if (sscanf(dir->msg, jobcmd, &jcr->JobId, jcr->Job,
281 &jcr->VolSessionId, &jcr->VolSessionTime,
283 bnet_fsend(dir, BADjob);
284 Jmsg(jcr, M_FATAL, 0, _("Bad Job Command: %s\n"), dir->msg);
285 free_pool_memory(sd_auth_key);
288 jcr->sd_auth_key = bstrdup(sd_auth_key);
289 free_pool_memory(sd_auth_key);
290 Dmsg2(120, "JobId=%d Auth=%s\n", jcr->JobId, jcr->sd_auth_key);
291 return bnet_fsend(dir, OKjob);
296 * Get list of files/directories to include from Director
299 static int include_cmd(JCR *jcr)
301 BSOCK *dir = jcr->dir_bsock;
303 while (bnet_recv(dir) >= 0) {
304 dir->msg[dir->msglen] = 0;
305 strip_trailing_junk(dir->msg);
306 Dmsg1(110, "filed<dird: include file %s\n", dir->msg);
307 add_fname_to_include_list(jcr->ff, 1, dir->msg);
310 return bnet_fsend(dir, OKinc);
314 * Get list of files to exclude from Director
317 static int exclude_cmd(JCR *jcr)
319 BSOCK *dir = jcr->dir_bsock;
322 while (bnet_recv(dir) >= 0) {
323 dir->msg[dir->msglen] = 0;
324 strip_trailing_junk(dir->msg);
325 /* Skip leading options */
326 for (p=dir->msg; *p && *p != ' '; p++)
329 for ( ; *p && *p == ' '; p++)
331 add_fname_to_exclude_list(jcr->ff, p);
332 Dmsg1(110, "<dird: exclude file %s\n", dir->msg);
335 return bnet_fsend(dir, OKexc);
339 static int bootstrap_cmd(JCR *jcr)
341 BSOCK *dir = jcr->dir_bsock;
342 POOLMEM *fname = get_pool_memory(PM_FNAME);
345 if (jcr->RestoreBootstrap) {
346 unlink(jcr->RestoreBootstrap);
347 free_pool_memory(jcr->RestoreBootstrap);
349 Mmsg(&fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
351 Dmsg1(400, "bootstrap=%s\n", fname);
352 jcr->RestoreBootstrap = fname;
353 bs = fopen(fname, "a+"); /* create file */
355 Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"),
356 jcr->RestoreBootstrap, strerror(errno));
357 free_pool_memory(jcr->RestoreBootstrap);
358 jcr->RestoreBootstrap = NULL;
362 while (bnet_recv(dir) >= 0) {
363 Dmsg1(200, "filed<dird: bootstrap file %s\n", dir->msg);
368 return bnet_fsend(dir, OKbootstrap);
373 * Get backup level from Director
376 static int level_cmd(JCR *jcr)
378 BSOCK *dir = jcr->dir_bsock;
383 level = (char *) get_memory(dir->msglen);
384 Dmsg1(110, "level_cmd: %s", dir->msg);
385 if (sscanf(dir->msg, "level = %s ", level) != 1) {
386 Jmsg1(jcr, M_FATAL, 0, _("Bad level command: %s\n"), dir->msg);
391 * Full backup requested
393 if (strcmp(level, "full") == 0) {
394 jcr->save_level = L_FULL;
396 * Backup requested since <date> <time>
397 * This form is also used for incremental and differential
399 } else if (strcmp(level, "since") == 0) {
400 jcr->save_level = L_SINCE;
401 if (sscanf(dir->msg, "level = since %d-%d-%d %d:%d:%d",
402 &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
403 &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
404 Jmsg1(jcr, M_FATAL, 0, "Bad scan of date/time: %s\n", dir->msg);
410 tm.tm_wday = tm.tm_yday = 0;
413 Dmsg1(100, "Got since time: %s", ctime(&mtime));
414 jcr->incremental = 1;
417 Jmsg1(jcr, M_FATAL, 0, "Unknown backup level: %s\n", level);
422 return bnet_fsend(dir, OKlevel);
426 * Get session parameters from Director -- this is for a Restore command
428 static int session_cmd(JCR *jcr)
430 BSOCK *dir = jcr->dir_bsock;
432 Dmsg1(100, "SessionCmd: %s", dir->msg);
433 if (sscanf(dir->msg, sessioncmd, jcr->VolumeName,
434 &jcr->VolSessionId, &jcr->VolSessionTime,
435 &jcr->StartFile, &jcr->EndFile,
436 &jcr->StartBlock, &jcr->EndBlock) != 7) {
437 Jmsg(jcr, M_FATAL, 0, "Bad session command: %s", dir->msg);
441 return bnet_fsend(dir, OKsession);
445 * Get address of storage daemon from Director
448 static int storage_cmd(JCR *jcr)
450 int stored_port; /* storage daemon port */
451 BSOCK *dir = jcr->dir_bsock;
452 BSOCK *sd; /* storage daemon bsock */
454 Dmsg1(100, "StorageCmd: %s", dir->msg);
455 if (sscanf(dir->msg, storaddr, &jcr->stored_addr, &stored_port) != 2) {
456 Jmsg(jcr, M_FATAL, 0, _("Bad storage command: %s"), dir->msg);
459 Dmsg2(110, "Open storage: %s:%d\n", jcr->stored_addr, stored_port);
460 /* Open command communications with Storage daemon */
461 /* Try to connect for 1 hour at 10 second intervals */
462 sd = bnet_connect(jcr, 10, 3600, _("Storage daemon"),
463 jcr->stored_addr, NULL, stored_port, 1);
465 Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"),
466 jcr->stored_addr, stored_port);
470 jcr->store_bsock = sd;
472 bnet_fsend(sd, "Hello Start Job %s\n", jcr->Job);
473 if (!authenticate_storagedaemon(jcr)) {
474 Jmsg(jcr, M_FATAL, 0, _("Failed to authenticate Storage daemon.\n"));
477 Dmsg0(110, "Authenticated with SD.\n");
479 /* Send OK to Director */
480 return bnet_fsend(dir, OKstore);
485 * Do a backup. For now, we handle only Full and Incremental.
487 static int backup_cmd(JCR *jcr)
489 BSOCK *dir = jcr->dir_bsock;
490 BSOCK *sd = jcr->store_bsock;
494 jcr->JobStatus = JS_Blocked;
495 jcr->JobType = JT_BACKUP;
496 Dmsg1(100, "begin backup ff=%p\n", jcr->ff);
499 Jmsg(jcr, M_FATAL, 0, _("Cannot contact Storage daemon\n"));
500 jcr->JobStatus = JS_ErrorTerminated;
504 bnet_fsend(dir, OKbackup);
505 Dmsg1(110, "bfiled>dird: %s", dir->msg);
508 * Send Append Open Session to Storage daemon
510 bnet_fsend(sd, append_open);
511 Dmsg1(110, ">stored: %s", sd->msg);
513 * Expect to receive back the Ticket number
515 if (bnet_recv(sd) >= 0) {
516 Dmsg1(110, "<stored: %s", sd->msg);
517 if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
518 Jmsg(jcr, M_FATAL, 0, _("Bad response to append open: %s\n"), sd->msg);
519 jcr->JobStatus = JS_ErrorTerminated;
522 Dmsg1(110, "Got Ticket=%d\n", jcr->Ticket);
524 Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to open command\n"));
525 jcr->JobStatus = JS_ErrorTerminated;
530 * Send Append data command to Storage daemon
532 bnet_fsend(sd, append_data, jcr->Ticket);
533 Dmsg1(110, ">stored: %s", sd->msg);
536 * Expect to get OK data
538 Dmsg1(110, "<stored: %s", sd->msg);
539 if (!response(jcr, sd, OK_data, "Append Data")) {
540 jcr->JobStatus = JS_ErrorTerminated;
545 * Send Files to Storage daemon
547 Dmsg1(110, "begin blast ff=%p\n", jcr->ff);
548 if (!blast_data_to_storage_daemon(jcr, NULL)) {
549 jcr->JobStatus = JS_ErrorTerminated;
551 jcr->JobStatus = JS_Terminated;
553 * Expect to get response to append_data from Storage daemon
555 if (!response(jcr, sd, OK_append, "Append Data")) {
556 jcr->JobStatus = JS_ErrorTerminated;
561 * Send Append End Data to Storage daemon
563 bnet_fsend(sd, append_end, jcr->Ticket);
565 if (!response(jcr, sd, OK_end, "Append End")) {
566 jcr->JobStatus = JS_ErrorTerminated;
571 * Send Append Close to Storage daemon
573 bnet_fsend(sd, append_close, jcr->Ticket);
574 while (bnet_recv(sd) >= 0) { /* stop on signal or error */
575 if (sscanf(sd->msg, OK_close, &SDJobStatus) == 1) {
577 Dmsg2(200, "SDJobStatus = %d %c\n", SDJobStatus, (char)SDJobStatus);
581 Jmsg(jcr, M_FATAL, 0, _("Append Close with SD failed.\n"));
582 jcr->JobStatus = JS_ErrorTerminated;
585 if (SDJobStatus != JS_Terminated) {
586 Jmsg(jcr, M_FATAL, 0, _("Bad status %d returned from Storage Daemon.\n"),
588 jcr->JobStatus = JS_ErrorTerminated;
594 /* Inform Storage daemon that we are done */
596 bnet_sig(sd, BNET_TERMINATE);
599 bnet_fsend(dir, EndBackup, jcr->JobStatus, jcr->JobFiles, jcr->ReadBytes, jcr->JobBytes);
601 /* Inform Director that we are done */
602 bnet_sig(dir, BNET_TERMINATE);
604 return jcr->JobStatus == JS_Terminated;
608 * Do a Verify for Director
611 static int verify_cmd(JCR *jcr)
613 BSOCK *dir = jcr->dir_bsock;
614 BSOCK *sd = jcr->store_bsock;
617 jcr->JobType = JT_VERIFY;
618 if (sscanf(dir->msg, verifycmd, level) != 1) {
619 bnet_fsend(dir, "2994 Bad verify command: %s\n", dir->msg);
622 if (strcasecmp(level, "init") == 0) {
623 jcr->JobLevel = L_VERIFY_INIT;
624 } else if (strcasecmp(level, "catalog") == 0){
625 jcr->JobLevel = L_VERIFY_CATALOG;
626 } else if (strcasecmp(level, "volume") == 0){
627 jcr->JobLevel = L_VERIFY_VOLUME_TO_CATALOG;
628 } else if (strcasecmp(level, "data") == 0){
629 jcr->JobLevel = L_VERIFY_DATA;
631 bnet_fsend(dir, "2994 Bad verify level: %s\n", dir->msg);
635 bnet_fsend(dir, OKverify);
636 Dmsg1(110, "bfiled>dird: %s", dir->msg);
638 switch (jcr->JobLevel) {
640 case L_VERIFY_CATALOG:
643 case L_VERIFY_VOLUME_TO_CATALOG:
644 if (!open_sd_read_session(jcr)) {
647 do_verify_volume(jcr);
649 * Send Close session command to Storage daemon
651 bnet_fsend(sd, read_close, jcr->Ticket);
652 Dmsg1(130, "bfiled>stored: %s", sd->msg);
654 /* ****FIXME**** check response */
655 bnet_recv(sd); /* get OK */
657 /* Inform Storage daemon that we are done */
658 bnet_sig(sd, BNET_TERMINATE);
662 bnet_fsend(dir, "2994 Bad verify level: %s\n", dir->msg);
666 /* Inform Director that we are done */
667 return bnet_sig(dir, BNET_TERMINATE);
671 * Do a Restore for Director
674 static int restore_cmd(JCR *jcr)
676 BSOCK *dir = jcr->dir_bsock;
677 BSOCK *sd = jcr->store_bsock;
682 * Scan WHERE (base directory for restore) from command
684 Dmsg0(150, "restore command\n");
685 /* Pickup where string */
686 where = get_memory(dir->msglen+1);
689 if (sscanf(dir->msg, restorecmd, &replace, where) != 2) {
690 Jmsg(jcr, M_FATAL, 0, _("Bad replace command.\n"));
694 Dmsg2(150, "Got replace %c, where=%s\n", replace, where);
695 unbash_spaces(where);
697 jcr->replace = replace;
699 bnet_fsend(dir, OKrestore);
700 Dmsg1(110, "bfiled>dird: %s", dir->msg);
702 jcr->JobType = JT_RESTORE;
703 jcr->JobStatus = JS_Blocked;
705 if (!open_sd_read_session(jcr)) {
710 * Do restore of files and data
715 * Send Close session command to Storage daemon
717 bnet_fsend(sd, read_close, jcr->Ticket);
718 Dmsg1(130, "bfiled>stored: %s", sd->msg);
720 /* ****FIXME**** check response */
721 bnet_recv(sd); /* get OK */
723 /* Inform Storage daemon that we are done */
724 bnet_sig(sd, BNET_TERMINATE);
726 bnet_fsend(dir, EndRestore, jcr->JobStatus, jcr->num_files_examined, jcr->JobBytes);
728 /* Inform Director that we are done */
729 bnet_sig(dir, BNET_TERMINATE);
731 Dmsg0(130, "Done in job.c\n");
735 static int open_sd_read_session(JCR *jcr)
737 BSOCK *sd = jcr->store_bsock;
740 Jmsg(jcr, M_FATAL, 0, _("Improper calling sequence.\n"));
743 Dmsg4(120, "VolSessId=%ld VolsessT=%ld SF=%ld EF=%ld\n",
744 jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile);
745 Dmsg2(120, "JobId=%d vol=%s\n", jcr->JobId, "DummyVolume");
747 * Open Read Session with Storage daemon
749 bnet_fsend(sd, read_open, jcr->VolumeName,
750 jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile,
751 jcr->StartBlock, jcr->EndBlock);
752 Dmsg1(110, ">stored: %s", sd->msg);
757 if (bnet_recv(sd) >= 0) {
758 Dmsg1(110, "bfiled<stored: %s", sd->msg);
759 if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
760 Jmsg(jcr, M_FATAL, 0, _("Bad response to SD read open: %s\n"), sd->msg);
763 Dmsg1(110, "bfiled: got Ticket=%d\n", jcr->Ticket);
765 Jmsg(jcr, M_FATAL, 0, _("Bad response from stored to read open command\n"));
769 if (!send_bootstrap_file(jcr)) {
774 * Start read of data with Storage daemon
776 bnet_fsend(sd, read_data, jcr->Ticket);
777 Dmsg1(110, ">stored: %s", sd->msg);
782 if (!response(jcr, sd, OK_data, "Read Data")) {
789 * Destroy the Job Control Record and associated
790 * resources (sockets).
792 static void filed_free_jcr(JCR *jcr)
794 if (jcr->store_bsock) {
795 bnet_close(jcr->store_bsock);
798 free_pool_memory(jcr->where);
800 if (jcr->RestoreBootstrap) {
801 unlink(jcr->RestoreBootstrap);
802 free_pool_memory(jcr->RestoreBootstrap);
804 if (jcr->last_fname) {
805 free_pool_memory(jcr->last_fname);
811 * Get response from Storage daemon to a command we
812 * sent. Check that the response is OK.
814 * Returns: 0 on failure
817 int response(JCR *jcr, BSOCK *sd, char *resp, char *cmd)
824 if ((n = bnet_recv(sd)) > 0) {
826 if (strcmp(sd->msg, resp) == 0) {
830 if (is_bnet_error(sd)) {
831 Jmsg2(jcr, M_FATAL, 0, _("Comm error with SD. bad response to %s. ERR=%s\n"),
832 cmd, bnet_strerror(sd));
834 Jmsg3(jcr, M_FATAL, 0, _("Bad response to %s command. Wanted %s, got %s\n"),
840 static int send_bootstrap_file(JCR *jcr)
844 BSOCK *sd = jcr->store_bsock;
845 char *bootstrap = "bootstrap\n";
847 Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap);
848 if (!jcr->RestoreBootstrap) {
851 bs = fopen(jcr->RestoreBootstrap, "r");
853 Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
854 jcr->RestoreBootstrap, strerror(errno));
855 jcr->JobStatus = JS_ErrorTerminated;
858 strcpy(sd->msg, bootstrap);
859 sd->msglen = strlen(sd->msg);
861 while (fgets(buf, sizeof(buf), bs)) {
862 sd->msglen = Mmsg(&sd->msg, "%s", buf);
865 bnet_sig(sd, BNET_EOD);
867 if (!response(jcr, sd, OKSDbootstrap, "Bootstrap")) {
868 jcr->JobStatus = JS_ErrorTerminated;